Skip to content

Commit

Permalink
altrace: Make thread ids human-readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 7, 2019
1 parent bc1e8ab commit 4159b2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 6 additions & 6 deletions altrace/altrace_common.h
Expand Up @@ -182,14 +182,14 @@ static void close_real_openal(void)
}
}

#define SIMPLE_MAP(maptype, ctype) \
#define SIMPLE_MAP(maptype, fromctype, toctype) \
typedef struct SimpleMap_##maptype { \
ctype from; \
ctype to; \
fromctype from; \
toctype to; \
} SimpleMap_##maptype; \
static SimpleMap_##maptype *simplemap_##maptype = NULL; \
static uint32 simplemap_##maptype##_map_size = 0; \
static void add_##maptype##_to_map(ctype from, ctype to) { \
static void add_##maptype##_to_map(fromctype from, toctype to) { \
void *ptr; uint32 i; \
for (i = 0; i < simplemap_##maptype##_map_size; i++) { \
if (simplemap_##maptype[i].from == from) { \
Expand All @@ -207,14 +207,14 @@ static void close_real_openal(void)
simplemap_##maptype[simplemap_##maptype##_map_size].to = to; \
simplemap_##maptype##_map_size++; \
} \
static ctype get_mapped_##maptype(ctype from) { \
static toctype get_mapped_##maptype(fromctype from) { \
uint32 i; \
for (i = 0; i < simplemap_##maptype##_map_size; i++) { \
if (simplemap_##maptype[i].from == from) { \
return simplemap_##maptype[i].to; \
} \
} \
return (ctype) 0; \
return (toctype) 0; \
} \
static void free_##maptype##_map(void) { \
free(simplemap_##maptype); \
Expand Down
18 changes: 14 additions & 4 deletions altrace/altrace_playback.c
Expand Up @@ -21,8 +21,8 @@ static void quit_altrace_playback(void);
// don't bother doing a full hash map for devices and contexts, since you'll
// usually never have more than one or two and they live basically the entire
// lifetime of your app.
SIMPLE_MAP(device, ALCdevice *)
SIMPLE_MAP(context, ALCcontext *)
SIMPLE_MAP(device, ALCdevice *, ALCdevice *)
SIMPLE_MAP(context, ALCcontext *, ALCcontext *)

static void free_hash_item_alname(ALuint from, ALuint to) { /* no-op */ }
static uint8 hash_alname(const ALuint name) {
Expand All @@ -47,6 +47,9 @@ static uint8 hash_stackframe(void *from) {
}
HASH_MAP(stackframe, void *, char *)

static uint32 next_mapped_threadid = 0;
SIMPLE_MAP(threadid, uint64, uint32);


#define MAX_IOBLOBS 32
static uint8 *ioblobs[MAX_IOBLOBS];
Expand Down Expand Up @@ -205,13 +208,19 @@ static ALboolean IO_BOOLEAN(void)

static void IO_ENTRYINFO(void)
{
const uint64 threadid = IO_UINT64();
const uint64 logthreadid = IO_UINT64();
const uint32 frames = IO_UINT32();
uint32 threadid = get_mapped_threadid(logthreadid);
uint32 i, framei;

if (!threadid) {
threadid = ++next_mapped_threadid;
add_threadid_to_map(logthreadid, threadid);
}

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

for (framei = 0; framei < frames; framei++) {
Expand Down Expand Up @@ -320,6 +329,7 @@ static void quit_altrace_playback(void)
free_source_map();
free_buffer_map();
free_stackframe_map();
free_threadid_map();

fflush(stderr);
}
Expand Down

0 comments on commit 4159b2b

Please sign in to comment.