summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2009-02-23 03:45:01 +0100
committerNeal H. Walfield <neal@gnu.org>2009-02-23 03:45:01 +0100
commit50c25bb3200d344dffa683c31770d4f921faa890 (patch)
tree2899bde9b536784b708d427658309c1c969b13da
parent0c44705f8ba6f931edbee9e2b11e9057bbc9f2e0 (diff)
Add a command to the debugger. Fix bugs.
-rw-r--r--libc-parts/profile.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/libc-parts/profile.c b/libc-parts/profile.c
index 27c561e..501159b 100644
--- a/libc-parts/profile.c
+++ b/libc-parts/profile.c
@@ -20,6 +20,7 @@
#ifdef RM_INTERN
# include "../viengoos/zalloc.h"
+# include "../viengoos/timer.h"
#else
# include <stdlib.h>
#endif
@@ -60,11 +61,34 @@
# endif
#endif
+#ifndef NPROFILE
+# include "../viengoos/debug.h"
+
+static void
+profile_command (int argc, char *argv[])
+{
+ profile_stats_dump ();
+}
+
+static struct debug_command profile_debug =
+ {
+ .name = "profile",
+ .short_name = 0,
+ .help = "Display profile data.",
+ .function = profile_command
+ };
+
+#endif
+
static inline uint64_t
now (void)
{
#ifdef __gnu_hurd_viengoos__
+# ifdef RM_INTERN
+ return time_data.ns_since_boot / 1000;
+# else
return VG_TIME->ns_since_boot / 1000;
+# endif
#else
struct timeval t;
struct timezone tz;
@@ -88,13 +112,21 @@ struct call_site
};
/* The number of threads we support. */
-#define THREADS 4
+#ifdef RM_INTERN
+# define THREADS 1
+#else
+# define THREADS 4
+#endif
static int thread_count;
struct profile_block
{
#ifdef __gnu_hurd_viengoos__
-# define MYSELF() hurd_myself ()
+# ifdef RM_INTERN
+# define MYSELF() 0
+# else
+# define MYSELF() hurd_myself ()
+# endif
vg_thread_id_t tid;
#else
# define MYSELF() pthread_self ()
@@ -137,6 +169,11 @@ profile_block (void)
/* New thread. */
+#ifdef RM_INTERN
+ if (thread_count == 0)
+ debug_register (&profile_debug);
+#endif
+
i = __sync_fetch_and_add (&thread_count, 1);
if (i >= THREADS)
panic ("More threads than profile space available!");
@@ -258,6 +295,7 @@ profile_stats_dump (void)
order[j + 1] = t;
}
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
s_printf ("Thread: "VG_THREAD_ID_FMT"\n", pb->tid);
for (j = 0; j < count; j ++)
{
@@ -282,9 +320,10 @@ profile_stats_dump (void)
pb->call_sites[i].time / pb->call_sites[i].calls,
(int) ((10 * pb->call_sites[i].time)
/ pb->call_sites[i].calls) % 10,
- (int) ((100 * pb->call_sites[i].time) / (n - pb->epoch)),
(int) ((100 * pb->call_sites[i].time)
- / pb->profiled_time));
+ / MAX (n - pb->epoch, 1)),
+ (int) ((100 * pb->call_sites[i].time)
+ / MAX (pb->profiled_time, 1)));
}
s_printf ("profiled time: %"PRId64" ms (%d%%), calls: %"PRId64"\n",
@@ -372,4 +411,3 @@ profile_end (uintptr_t id)
else
site->nested_calls ++;
}
-