summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLuca Barbieri <[email protected]>2010-08-18 16:38:17 +0200
committerLuca Barbieri <[email protected]>2010-08-20 18:18:28 +0200
commit40eef4c20cc0b4500a0d8c8538872ed4b473d737 (patch)
tree8c01def1006d37e8877f310fb5814cd2ad7ac000 /src
parentb3e57fc8685af44dcf35a7f429b7410e63a9a571 (diff)
u_debug_symbol: add symbol name caching
Without this, any form of logging that dumps stack traces continuously will spend a lot of time resolving symbol names.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/util/u_debug_symbol.c40
-rw-r--r--src/gallium/auxiliary/util/u_debug_symbol.h4
2 files changed, 43 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c
index ebea517f90e..332952af88b 100644
--- a/src/gallium/auxiliary/util/u_debug_symbol.c
+++ b/src/gallium/auxiliary/util/u_debug_symbol.c
@@ -33,10 +33,12 @@
*/
#include "pipe/p_compiler.h"
+#include "os/os_thread.h"
#include "u_string.h"
#include "u_debug.h"
#include "u_debug_symbol.h"
+#include "u_hash_table.h"
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
@@ -186,3 +188,41 @@ debug_symbol_print(const void *addr)
debug_symbol_name(addr, buf, sizeof(buf));
debug_printf("\t%s\n", buf);
}
+
+struct util_hash_table* symbols_hash;
+pipe_mutex symbols_mutex;
+
+static unsigned hash_ptr(void* p)
+{
+ return (unsigned)(uintptr_t)p;
+}
+
+static int compare_ptr(void* a, void* b)
+{
+ if(a == b)
+ return 0;
+ else if(a < b)
+ return -1;
+ else
+ return 1;
+}
+
+const char*
+debug_symbol_name_cached(const void *addr)
+{
+ const char* name;
+ pipe_mutex_lock(symbols_mutex);
+ if(!symbols_hash)
+ symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
+ name = util_hash_table_get(symbols_hash, (void*)addr);
+ if(!name)
+ {
+ char buf[1024];
+ debug_symbol_name(addr, buf, sizeof(buf));
+ name = strdup(buf);
+
+ util_hash_table_set(symbols_hash, (void*)addr, (void*)name);
+ }
+ pipe_mutex_unlock(symbols_mutex);
+ return name;
+}
diff --git a/src/gallium/auxiliary/util/u_debug_symbol.h b/src/gallium/auxiliary/util/u_debug_symbol.h
index 5e283e5ba3f..b247706c2a0 100644
--- a/src/gallium/auxiliary/util/u_debug_symbol.h
+++ b/src/gallium/auxiliary/util/u_debug_symbol.h
@@ -45,10 +45,12 @@ extern "C" {
void
debug_symbol_name(const void *addr, char* buf, unsigned size);
+const char*
+debug_symbol_name_cached(const void *addr);
+
void
debug_symbol_print(const void *addr);
-
#ifdef __cplusplus
}
#endif