Skip to content

Commit

Permalink
altrace: record callers' thread id and callstack.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 6, 2019
1 parent ba98e02 commit 618e9e7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
33 changes: 32 additions & 1 deletion altrace/altrace_playback.c
Expand Up @@ -10,6 +10,7 @@
#include "altrace_common.h"

static int dump_log = 1;
static int dump_callers = 0;
static int run_log = 0;

static int trace_scope = 0;
Expand Down Expand Up @@ -224,10 +225,36 @@ static ALboolean IO_BOOLEAN(void)
return (ALboolean) IO_UINT32();
}

static void IO_START_INFO(void)
{
const uint64 threadid = IO_UINT64();
const uint32 frames = IO_UINT32();
uint32 i;

if (dump_callers) {
for (i = 0; i < trace_scope; i++) { printf(" "); }
printf("Call from threadid=%llu, stack={\n", (unsigned long long) threadid);
}

for (i = 0; i < frames; i++) {
const char *str = IO_STRING();
if (dump_callers) {
for (i = 0; i < trace_scope; i++) { printf(" "); }
printf(" %s\n", str);
}
}

if (dump_callers) {
for (i = 0; i < trace_scope; i++) { printf(" "); }
printf("}\n");
}
}

#define IO_START(e) \
{ \
IO_START_INFO(); \
if (dump_log) { \
int i; for (i = 0; i < trace_scope; i++) { printf(" "); } \
int i; for (i = 0; i < trace_scope; i++) { printf(" "); } \
printf("%s", #e); \
} { \

Expand Down Expand Up @@ -2242,6 +2269,10 @@ int main(int argc, char **argv)
dump_log = 1;
} else if (strcmp(arg, "--no-dump") == 0) {
dump_log = 0;
} else if (strcmp(arg, "--dump-callers") == 0) {
dump_callers = 1;
} else if (strcmp(arg, "--no-dump-callers") == 0) {
dump_callers = 0;
} else if (strcmp(arg, "--run") == 0) {
run_log = 1;
} else if (strcmp(arg, "--no-run") == 0) {
Expand Down
22 changes: 21 additions & 1 deletion altrace/altrace_record.c
Expand Up @@ -6,6 +6,8 @@
* This file written by Ryan C. Gordon.
*/

#include <execinfo.h>

#define APPNAME "altrace_record"

#ifdef _MSC_VER
Expand Down Expand Up @@ -182,6 +184,23 @@ static void IO_BOOLEAN(ALboolean b)
IO_UINT32((uint32) b);
}

static void IO_START_INFO(void)
{
void* callstack[16];
const int frames = backtrace(callstack, sizeof (callstack) / sizeof (callstack[0]));
int i;
char** strs = backtrace_symbols(callstack, frames);

IO_UINT64((uint64) pthread_self());

IO_UINT32((uint32) frames);
for (i = 0; i < frames; i++) {
IO_STRING(strs[i]);
}

free(strs);
}

static void APILOCK(void)
{
const int rc = pthread_mutex_lock(apilock);
Expand Down Expand Up @@ -241,7 +260,8 @@ static void check_alc_error_events(ALCdevice *device)
{ \
APILOCK(); \
IO_UINT32(NOW()); \
IO_ENTRYENUM(ALEE_##e);
IO_ENTRYENUM(ALEE_##e); \
IO_START_INFO();

#define IO_END() \
check_al_error_events(); \
Expand Down

0 comments on commit 618e9e7

Please sign in to comment.