2023-02-17 19:51:22 -05:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <pthread.h>
|
|
|
|
#undef _GNU_SOURCE
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
#include "trace.h"
|
|
|
|
|
2022-06-04 13:04:51 -04:00
|
|
|
#include "mem.h"
|
2023-12-05 19:40:34 -05:00
|
|
|
#include "util.js.h"
|
2022-06-04 13:04:51 -04:00
|
|
|
|
2023-05-21 17:36:51 -04:00
|
|
|
#include "sqlite3.h"
|
|
|
|
#include "uv.h"
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
#include <assert.h>
|
2022-05-16 18:30:14 -04:00
|
|
|
#include <stdio.h>
|
2021-01-02 13:10:00 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-12-05 19:52:47 -05:00
|
|
|
#define tf_countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
|
2021-10-24 11:46:30 -04:00
|
|
|
|
2022-01-02 13:17:58 -05:00
|
|
|
enum
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
k_buffer_size = 4 * 1024 * 1024,
|
|
|
|
};
|
|
|
|
|
2021-10-24 11:46:30 -04:00
|
|
|
typedef struct _tf_trace_stack_t tf_trace_stack_t;
|
|
|
|
|
|
|
|
typedef struct _tf_trace_stack_t
|
|
|
|
{
|
|
|
|
const char* names[256];
|
2023-07-20 01:06:15 -04:00
|
|
|
const char* tags[256];
|
2021-10-24 11:46:30 -04:00
|
|
|
int count;
|
|
|
|
tf_trace_stack_t* next;
|
|
|
|
} tf_trace_stack_t;
|
|
|
|
|
2023-02-17 19:51:22 -05:00
|
|
|
typedef struct _tf_trace_thread_t
|
|
|
|
{
|
|
|
|
pthread_t id;
|
|
|
|
tf_trace_stack_t* stack;
|
|
|
|
char name[64];
|
|
|
|
} tf_trace_thread_t;
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
typedef struct _tf_trace_t
|
|
|
|
{
|
|
|
|
char buffer[k_buffer_size];
|
2023-02-01 18:20:16 -05:00
|
|
|
char process_name[256];
|
2021-01-02 13:10:00 -05:00
|
|
|
int write_offset;
|
2021-10-24 11:46:30 -04:00
|
|
|
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_t mutex;
|
2022-01-02 13:17:58 -05:00
|
|
|
tf_trace_write_callback_t* callback;
|
|
|
|
void* user_data;
|
|
|
|
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_rwlock_t threads_lock;
|
|
|
|
tf_trace_thread_t** threads;
|
|
|
|
int threads_count;
|
2021-01-02 13:10:00 -05:00
|
|
|
} tf_trace_t;
|
|
|
|
|
2022-01-02 13:17:58 -05:00
|
|
|
static void _trace_append(tf_trace_t* trace, const char* buffer, size_t size, void* user_data)
|
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_lock(&trace->mutex);
|
2022-01-02 13:17:58 -05:00
|
|
|
if (trace->write_offset + size + 2 >= k_buffer_size)
|
|
|
|
{
|
|
|
|
trace->buffer[trace->write_offset] = '\0';
|
|
|
|
trace->write_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trace->write_offset + size + 2 < k_buffer_size)
|
|
|
|
{
|
|
|
|
memcpy(trace->buffer + trace->write_offset, buffer, size);
|
|
|
|
trace->write_offset += size;
|
|
|
|
trace->buffer[trace->write_offset++] = '\n';
|
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_unlock(&trace->mutex);
|
2022-01-02 13:17:58 -05:00
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
tf_trace_t* tf_trace_create()
|
|
|
|
{
|
2022-06-04 13:04:51 -04:00
|
|
|
tf_trace_t* trace = tf_malloc(sizeof(tf_trace_t));
|
2021-01-02 13:10:00 -05:00
|
|
|
memset(trace, 0, sizeof(*trace));
|
2022-01-02 13:17:58 -05:00
|
|
|
trace->callback = _trace_append;
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_init(&trace->mutex);
|
|
|
|
uv_rwlock_init(&trace->threads_lock);
|
2021-01-02 13:10:00 -05:00
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tf_trace_destroy(tf_trace_t* trace)
|
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
for (int i = 0; i < trace->threads_count; i++)
|
2021-10-24 11:46:30 -04:00
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
tf_trace_thread_t* thread = trace->threads[i];
|
|
|
|
while (thread->stack)
|
|
|
|
{
|
|
|
|
tf_trace_stack_t* stack = thread->stack;
|
|
|
|
thread->stack = stack->next;
|
|
|
|
tf_free(stack);
|
|
|
|
}
|
|
|
|
tf_free(thread);
|
2021-10-24 11:46:30 -04:00
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
tf_free(trace->threads);
|
|
|
|
uv_rwlock_destroy(&trace->threads_lock);
|
|
|
|
uv_mutex_destroy(&trace->mutex);
|
2022-06-04 13:04:51 -04:00
|
|
|
tf_free(trace);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 18:20:16 -05:00
|
|
|
void tf_trace_set_process_name(tf_trace_t* trace, const char* name)
|
|
|
|
{
|
|
|
|
snprintf(trace->process_name, sizeof(trace->process_name), "%s", name);
|
|
|
|
}
|
|
|
|
|
2022-01-02 13:17:58 -05:00
|
|
|
void tf_trace_raw(tf_trace_t* trace, const char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
trace->callback(trace, buffer, size, trace->user_data);
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
static int64_t _trace_ts()
|
|
|
|
{
|
|
|
|
int64_t result = 0;
|
|
|
|
struct timespec ts;
|
2021-10-10 17:51:38 -04:00
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
result = (ts.tv_sec * 1e9 + ts.tv_nsec) / 1e3;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tf_trace_counter(tf_trace_t* trace, const char* name, int argc, const char** arg_names, const int64_t* arg_values)
|
|
|
|
{
|
2021-10-10 17:51:38 -04:00
|
|
|
if (!trace)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char line[1024];
|
|
|
|
int p = 0;
|
|
|
|
p += snprintf(line + p, sizeof(line) - p, "{\"ph\": \"C\", \"pid\": %d, \"ts\": %" PRId64 ", \"name\": \"%s\", \"args\": {", getpid(), _trace_ts(), name);
|
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
p += snprintf(line + p, sizeof(line) - p, "\"%s\": %" PRId64 "%s", arg_names[i], arg_values[i], i == argc - 1 ? "}}," : ", ");
|
|
|
|
}
|
2023-12-05 19:52:47 -05:00
|
|
|
p = tf_min(p, tf_countof(line));
|
2022-01-02 13:17:58 -05:00
|
|
|
trace->callback(trace, line, p, trace->user_data);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2023-01-31 22:15:22 -05:00
|
|
|
static int _tf_trace_escape_name(char* out, size_t out_size, const char* name)
|
|
|
|
{
|
|
|
|
int p = 0;
|
|
|
|
for (const char* c = name; *c && (size_t)p < out_size; c++)
|
|
|
|
{
|
|
|
|
switch (*c)
|
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
case '\\':
|
|
|
|
out[p++] = '\\';
|
|
|
|
if ((size_t)p + 1 < out_size)
|
|
|
|
{
|
|
|
|
out[p++] = *c;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
out[p++] = '\\';
|
|
|
|
if ((size_t)p + 1 < out_size)
|
|
|
|
{
|
|
|
|
out[p++] = 't';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
out[p++] = '\\';
|
|
|
|
if ((size_t)p + 1 < out_size)
|
|
|
|
{
|
|
|
|
out[p++] = 'n';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out[p++] = *c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2023-02-17 19:51:22 -05:00
|
|
|
static tf_trace_thread_t* _tf_trace_get_thread(tf_trace_t* trace, pthread_t self)
|
2021-01-02 13:10:00 -05:00
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
tf_trace_thread_t* found = NULL;
|
|
|
|
uv_rwlock_rdlock(&trace->threads_lock);
|
|
|
|
for (int i = 0; i < trace->threads_count; i++)
|
2021-10-10 17:51:38 -04:00
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
if (trace->threads[i]->id == self)
|
|
|
|
{
|
|
|
|
found = trace->threads[i];
|
|
|
|
break;
|
|
|
|
}
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_rwlock_rdunlock(&trace->threads_lock);
|
2021-01-02 13:10:00 -05:00
|
|
|
|
2023-02-17 19:51:22 -05:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
uv_rwlock_wrlock(&trace->threads_lock);
|
|
|
|
/* Maybe it was added while we changed from rd to rw. */
|
|
|
|
for (int i = 0; i < trace->threads_count; i++)
|
|
|
|
{
|
|
|
|
if (trace->threads[i]->id == self)
|
|
|
|
{
|
|
|
|
found = trace->threads[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
found = tf_malloc(sizeof(tf_trace_thread_t));
|
2024-02-15 18:35:01 -05:00
|
|
|
*found = (tf_trace_thread_t) {
|
2023-02-17 19:51:22 -05:00
|
|
|
.id = self,
|
|
|
|
};
|
2023-10-22 13:51:16 -04:00
|
|
|
#if defined(__linux__) && !defined(__ANDROID__)
|
2023-02-17 19:51:22 -05:00
|
|
|
pthread_getname_np(self, found->name, sizeof(found->name));
|
|
|
|
#endif
|
|
|
|
trace->threads = tf_resize_vec(trace->threads, sizeof(tf_trace_thread_t*) * (trace->threads_count + 1));
|
|
|
|
trace->threads[trace->threads_count++] = found;
|
|
|
|
}
|
|
|
|
uv_rwlock_wrunlock(&trace->threads_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2023-07-20 01:06:15 -04:00
|
|
|
static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name, void* tag)
|
2023-02-17 19:51:22 -05:00
|
|
|
{
|
|
|
|
tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self);
|
2023-12-05 19:52:47 -05:00
|
|
|
if (!thread->stack || thread->stack->count + 1 > tf_countof(thread->stack->names))
|
2021-10-24 11:46:30 -04:00
|
|
|
{
|
2022-06-04 13:04:51 -04:00
|
|
|
tf_trace_stack_t* stack = tf_malloc(sizeof(tf_trace_stack_t));
|
2021-10-24 11:46:30 -04:00
|
|
|
memset(stack, 0, sizeof(*stack));
|
2023-02-17 19:51:22 -05:00
|
|
|
stack->next = thread->stack;
|
|
|
|
thread->stack = stack;
|
2021-10-24 11:46:30 -04:00
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
tf_trace_stack_t* stack = thread->stack;
|
2023-12-05 19:52:47 -05:00
|
|
|
while (stack->count == 0 && stack->next && stack->next->count + 1 <= tf_countof(thread->stack->names))
|
2021-10-24 11:46:30 -04:00
|
|
|
{
|
|
|
|
stack = stack->next;
|
|
|
|
}
|
2023-07-20 01:06:15 -04:00
|
|
|
stack->names[stack->count] = name;
|
|
|
|
stack->tags[stack->count] = tag;
|
|
|
|
stack->count++;
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2023-07-20 01:06:15 -04:00
|
|
|
static const char* _tf_pop_stack(tf_trace_t* trace, pthread_t self, void* tag)
|
2021-01-02 13:10:00 -05:00
|
|
|
{
|
2023-02-17 19:51:22 -05:00
|
|
|
tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self);
|
|
|
|
tf_trace_stack_t* stack = thread->stack;
|
2021-10-24 11:46:30 -04:00
|
|
|
while (stack && stack->count == 0)
|
|
|
|
{
|
|
|
|
stack = stack->next;
|
|
|
|
}
|
2021-12-21 14:33:02 -05:00
|
|
|
const char* name = NULL;
|
2024-02-15 18:35:01 -05:00
|
|
|
if (stack && stack->count > 0 && stack->tags[stack->count - 1] == tag)
|
2021-12-21 14:33:02 -05:00
|
|
|
{
|
|
|
|
name = stack->names[stack->count - 1];
|
|
|
|
stack->count--;
|
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2023-07-20 01:06:15 -04:00
|
|
|
static void _tf_trace_begin_tagged(tf_trace_t* trace, const char* name, void* tag)
|
2023-02-17 19:51:22 -05:00
|
|
|
{
|
2023-07-20 01:06:15 -04:00
|
|
|
if (!trace || !name)
|
2023-02-17 19:51:22 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_t self = pthread_self();
|
2023-07-20 01:06:15 -04:00
|
|
|
_tf_push_stack(trace, self, name, tag);
|
2023-02-17 19:51:22 -05:00
|
|
|
|
|
|
|
char line[1024];
|
2024-01-01 20:09:05 -05:00
|
|
|
int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)self, _trace_ts());
|
2024-05-08 20:56:44 -04:00
|
|
|
p += _tf_trace_escape_name(line + p, sizeof(line) - p - 4, name);
|
2023-02-17 19:51:22 -05:00
|
|
|
p += snprintf(line + p, sizeof(line) - p, "\"},");
|
2023-12-05 19:52:47 -05:00
|
|
|
p = tf_min(p, tf_countof(line));
|
2023-02-17 19:51:22 -05:00
|
|
|
trace->callback(trace, line, p, trace->user_data);
|
|
|
|
}
|
|
|
|
|
2023-07-20 01:06:15 -04:00
|
|
|
void tf_trace_begin(tf_trace_t* trace, const char* name)
|
|
|
|
{
|
|
|
|
_tf_trace_begin_tagged(trace, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _tf_trace_end_tagged(tf_trace_t* trace, void* tag)
|
2023-02-17 19:51:22 -05:00
|
|
|
{
|
|
|
|
if (!trace)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_t self = pthread_self();
|
2023-07-20 01:06:15 -04:00
|
|
|
const char* name = _tf_pop_stack(trace, self, tag);
|
2022-01-02 13:17:58 -05:00
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-10-24 11:46:30 -04:00
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
char line[1024];
|
2024-02-17 14:22:02 -05:00
|
|
|
int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts());
|
2024-05-08 20:56:44 -04:00
|
|
|
p += _tf_trace_escape_name(line + p, sizeof(line) - p - 4, name);
|
2024-02-15 18:35:01 -05:00
|
|
|
p += snprintf(line + p, sizeof(line) - p, "\"},");
|
2023-12-05 19:52:47 -05:00
|
|
|
p = tf_min(p, tf_countof(line));
|
2022-01-02 13:17:58 -05:00
|
|
|
trace->callback(trace, line, p, trace->user_data);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2023-07-20 01:06:15 -04:00
|
|
|
void tf_trace_end(tf_trace_t* trace)
|
|
|
|
{
|
|
|
|
_tf_trace_end_tagged(trace, NULL);
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
char* tf_trace_export(tf_trace_t* trace)
|
|
|
|
{
|
2021-10-10 17:51:38 -04:00
|
|
|
if (!trace)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int k_extra_size = 1024;
|
2022-06-04 13:04:51 -04:00
|
|
|
char* buffer = tf_malloc(k_buffer_size + k_extra_size);
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_lock(&trace->mutex);
|
2021-01-02 13:10:00 -05:00
|
|
|
const char* newline = strchr(trace->buffer + trace->write_offset, '\n');
|
|
|
|
int begin = newline ? newline - trace->buffer : 0;
|
|
|
|
size_t size = 0;
|
|
|
|
size += snprintf(buffer, k_buffer_size, "{\"displayTimeUnit\": \"ns\",\n\"traceEvents\": [\n");
|
2023-02-01 18:20:16 -05:00
|
|
|
if (*trace->process_name)
|
|
|
|
{
|
2024-02-17 14:22:02 -05:00
|
|
|
size += snprintf(buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"name\":\"process_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(), trace->process_name);
|
2023-02-01 18:20:16 -05:00
|
|
|
}
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_rwlock_rdlock(&trace->threads_lock);
|
|
|
|
for (int i = 0; i < trace->threads_count; i++)
|
|
|
|
{
|
|
|
|
tf_trace_thread_t* thread = trace->threads[i];
|
2024-02-17 14:22:02 -05:00
|
|
|
size += snprintf(buffer + size, k_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"tid\":%" PRId64 ",\"name\":\"thread_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(),
|
|
|
|
(uint64_t)thread->id, thread->name);
|
2023-02-17 19:51:22 -05:00
|
|
|
}
|
|
|
|
uv_rwlock_rdunlock(&trace->threads_lock);
|
2021-10-10 17:51:38 -04:00
|
|
|
if (begin)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
size_t this_size = strlen(trace->buffer + begin);
|
|
|
|
memcpy(buffer + size, trace->buffer + begin, this_size);
|
|
|
|
size += this_size;
|
|
|
|
}
|
|
|
|
memcpy(buffer + size, trace->buffer, trace->write_offset);
|
|
|
|
size += trace->write_offset;
|
2023-02-17 19:51:22 -05:00
|
|
|
uv_mutex_unlock(&trace->mutex);
|
2021-10-10 17:51:38 -04:00
|
|
|
if (size > 2 && buffer[size - 1] == '\n' && buffer[size - 2] == ',')
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
buffer[size - 2] = '\n';
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
size += snprintf(buffer + size, k_buffer_size - size, "]}\n");
|
|
|
|
assert(size < (size_t)k_buffer_size + k_extra_size);
|
2023-02-17 19:51:22 -05:00
|
|
|
buffer[size] = '\0';
|
2021-01-02 13:10:00 -05:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _tf_trace_sqlite_callback(unsigned int t, void* c, void* p, void* x)
|
|
|
|
{
|
|
|
|
tf_trace_t* trace = c;
|
2021-10-10 17:51:38 -04:00
|
|
|
switch (t)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
case SQLITE_TRACE_STMT:
|
|
|
|
{
|
|
|
|
const char* statement = x;
|
2021-10-10 17:51:38 -04:00
|
|
|
if (statement[0] != '-' || statement[1] != '-')
|
|
|
|
{
|
2023-07-20 01:06:15 -04:00
|
|
|
_tf_trace_begin_tagged(trace, statement, p);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQLITE_TRACE_PROFILE:
|
2023-07-20 01:06:15 -04:00
|
|
|
_tf_trace_end_tagged(trace, p);
|
2021-01-02 13:10:00 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
trace->callback = callback;
|
|
|
|
trace->user_data = user_data;
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_trace_sqlite(tf_trace_t* trace, sqlite3* sqlite)
|
|
|
|
{
|
2021-10-10 17:51:38 -04:00
|
|
|
if (sqlite)
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
sqlite3_trace_v2(sqlite, SQLITE_TRACE_STMT | SQLITE_TRACE_PROFILE, _tf_trace_sqlite_callback, trace);
|
2021-10-10 17:51:38 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 13:10:00 -05:00
|
|
|
sqlite3_trace_v2(sqlite, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|