2021-01-02 13:10:00 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-02-20 21:41:37 -05:00
|
|
|
/**
|
|
|
|
** \defgroup trace Performance Tracing
|
|
|
|
** Generates trace output that is compatible with speedscope.app,
|
2024-02-28 19:12:41 -05:00
|
|
|
** chrome://tracing or ui.perfetto.dev for scrutinizing what each thread is
|
|
|
|
** doing for optimization purposes.
|
2024-02-20 21:41:37 -05:00
|
|
|
** @{
|
|
|
|
*/
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
#include <inttypes.h>
|
2022-01-02 13:17:58 -05:00
|
|
|
#include <stddef.h>
|
2021-01-02 13:10:00 -05:00
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** A trace instance.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
typedef struct _tf_trace_t tf_trace_t;
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** An SQLite database instance.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
typedef struct sqlite3 sqlite3;
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** Create a trace instance. Can be used to produce a Chrome trace event
|
|
|
|
** document for analyzing performance. Clean up with tf_trace_destroy().
|
|
|
|
** @return A trace instance.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
tf_trace_t* tf_trace_create();
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Destroy a trace instance that was created with tf_trace_create().
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_destroy(tf_trace_t* trace);
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** Set the name of the current process.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param name The name of the process.
|
|
|
|
*/
|
2023-02-01 18:20:16 -05:00
|
|
|
void tf_trace_set_process_name(tf_trace_t* trace, const char* name);
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** Record counter values.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param name The counter group name.
|
|
|
|
** @param argc The number of counters.
|
|
|
|
** @param arg_names The counter names.
|
|
|
|
** @param arg_values The counter values.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_counter(tf_trace_t* trace, const char* name, int argc, const char** arg_names, const int64_t* arg_values);
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Begin tracing a time interval. End with tf_trace_end().
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param name The interval name.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_begin(tf_trace_t* trace, const char* name);
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** End tracing the next time interval previously started with tf_trace_begin().
|
|
|
|
** @param trace The trace instance.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_end(tf_trace_t* trace);
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** Export all currently stored trace data to a string.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @return A string representation of the trace data.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
char* tf_trace_export(tf_trace_t* trace);
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** A callback to collect trace data.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param buffer The trace data.
|
|
|
|
** @param size The size of the trace data.
|
|
|
|
** @param user_data User data registered with the callback.
|
|
|
|
*/
|
2024-02-15 18:35:01 -05:00
|
|
|
typedef void(tf_trace_write_callback_t)(tf_trace_t* trace, const char* buffer, size_t size, void* user_data);
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Replace the trace recording behavior.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param callback A callback that will be called instead of collecting the trace data in a buffer.
|
|
|
|
** @param user_data User data to pass to the callback.
|
|
|
|
*/
|
2022-01-02 13:17:58 -05:00
|
|
|
void tf_trace_set_write_callback(tf_trace_t* trace, tf_trace_write_callback_t* callback, void* user_data);
|
2024-02-28 19:12:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Inject raw trace data.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param buffer The trace data.
|
|
|
|
** @param size The size of the trace data.
|
|
|
|
*/
|
2022-01-02 13:17:58 -05:00
|
|
|
void tf_trace_raw(tf_trace_t* trace, const char* buffer, size_t size);
|
|
|
|
|
2024-02-28 19:12:41 -05:00
|
|
|
/**
|
|
|
|
** Register for trace-worthy events from sqlite and record them going forward.
|
|
|
|
** @param trace The trace instance.
|
|
|
|
** @param sqlite The SQLite database.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_sqlite(tf_trace_t* trace, sqlite3* sqlite);
|
2024-02-20 21:41:37 -05:00
|
|
|
|
|
|
|
/** @} */
|