Fixed multiple trace problems.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4357 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
37
src/trace.c
37
src/trace.c
@ -30,6 +30,7 @@ typedef struct _tf_trace_stack_t tf_trace_stack_t;
|
||||
typedef struct _tf_trace_stack_t
|
||||
{
|
||||
const char* names[256];
|
||||
const char* tags[256];
|
||||
int count;
|
||||
tf_trace_stack_t* next;
|
||||
} tf_trace_stack_t;
|
||||
@ -225,7 +226,7 @@ static tf_trace_thread_t* _tf_trace_get_thread(tf_trace_t* trace, pthread_t self
|
||||
return found;
|
||||
}
|
||||
|
||||
static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name)
|
||||
static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name, void* tag)
|
||||
{
|
||||
tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self);
|
||||
if (!thread->stack || thread->stack->count + 1 > (int)_countof(thread->stack->names))
|
||||
@ -240,11 +241,13 @@ static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name)
|
||||
{
|
||||
stack = stack->next;
|
||||
}
|
||||
stack->names[stack->count++] = name;
|
||||
stack->names[stack->count] = name;
|
||||
stack->tags[stack->count] = tag;
|
||||
stack->count++;
|
||||
|
||||
}
|
||||
|
||||
static const char* _tf_pop_stack(tf_trace_t* trace, pthread_t self)
|
||||
static const char* _tf_pop_stack(tf_trace_t* trace, pthread_t self, void* tag)
|
||||
{
|
||||
tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self);
|
||||
tf_trace_stack_t* stack = thread->stack;
|
||||
@ -253,7 +256,9 @@ static const char* _tf_pop_stack(tf_trace_t* trace, pthread_t self)
|
||||
stack = stack->next;
|
||||
}
|
||||
const char* name = NULL;
|
||||
if (stack && stack->count > 0)
|
||||
if (stack &&
|
||||
stack->count > 0 &&
|
||||
stack->tags[stack->count - 1] == tag)
|
||||
{
|
||||
name = stack->names[stack->count - 1];
|
||||
stack->count--;
|
||||
@ -261,15 +266,15 @@ static const char* _tf_pop_stack(tf_trace_t* trace, pthread_t self)
|
||||
return name;
|
||||
}
|
||||
|
||||
void tf_trace_begin(tf_trace_t* trace, const char* name)
|
||||
static void _tf_trace_begin_tagged(tf_trace_t* trace, const char* name, void* tag)
|
||||
{
|
||||
if (!trace)
|
||||
if (!trace || !name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_t self = pthread_self();
|
||||
_tf_push_stack(trace, self, name);
|
||||
_tf_push_stack(trace, self, name, tag);
|
||||
|
||||
char line[1024];
|
||||
int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)self, _trace_ts());
|
||||
@ -278,7 +283,12 @@ void tf_trace_begin(tf_trace_t* trace, const char* name)
|
||||
trace->callback(trace, line, p, trace->user_data);
|
||||
}
|
||||
|
||||
void tf_trace_end(tf_trace_t* trace)
|
||||
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)
|
||||
{
|
||||
if (!trace)
|
||||
{
|
||||
@ -286,7 +296,7 @@ void tf_trace_end(tf_trace_t* trace)
|
||||
}
|
||||
|
||||
pthread_t self = pthread_self();
|
||||
const char* name = _tf_pop_stack(trace, self);
|
||||
const char* name = _tf_pop_stack(trace, self, tag);
|
||||
if (!name)
|
||||
{
|
||||
return;
|
||||
@ -299,6 +309,11 @@ void tf_trace_end(tf_trace_t* trace)
|
||||
trace->callback(trace, line, p, trace->user_data);
|
||||
}
|
||||
|
||||
void tf_trace_end(tf_trace_t* trace)
|
||||
{
|
||||
_tf_trace_end_tagged(trace, NULL);
|
||||
}
|
||||
|
||||
char* tf_trace_export(tf_trace_t* trace)
|
||||
{
|
||||
if (!trace)
|
||||
@ -361,12 +376,12 @@ static int _tf_trace_sqlite_callback(unsigned int t, void* c, void* p, void* x)
|
||||
const char* statement = x;
|
||||
if (statement[0] != '-' || statement[1] != '-')
|
||||
{
|
||||
tf_trace_begin(trace, statement);
|
||||
_tf_trace_begin_tagged(trace, statement, p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SQLITE_TRACE_PROFILE:
|
||||
tf_trace_end(trace);
|
||||
_tf_trace_end_tagged(trace, p);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user