Log profiler: fill and display a few more data fields in the header.
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 8 Nov 2010 15:30:56 +0000 (16:30 +0100)
committerPaolo Molaro <lupus@oddwiz.org>
Mon, 8 Nov 2010 16:36:33 +0000 (17:36 +0100)
mono/profiler/decode.c
mono/profiler/proflog.c
mono/profiler/utils.c
mono/profiler/utils.h

index 77fed197782a6ec1dee7c1930eeb406d8bbc2eb8..25adbfd8b01e27211de409b4259a447b68524d6f 100644 (file)
@@ -406,6 +406,10 @@ typedef struct {
        unsigned char *buf;
        int size;
        int data_version;
+       int version_major;
+       int version_minor;
+       int timer_overhead;
+       uint64_t startup_time;
        ThreadContext *threads;
        ThreadContext *current;
 } ProfContext;
@@ -1092,9 +1096,16 @@ load_file (char *name)
        p = ctx->buf;
        if (read_int32 (p) != LOG_HEADER_ID || p [6] != LOG_DATA_VERSION)
                return NULL;
+       ctx->version_major = p [4];
+       ctx->version_minor = p [5];
        ctx->data_version = p [6];
-       if (read_int32 (p + 12)) /* flags must be 0 */
+       /* reading 64 bit files on 32 bit systems not supported yet */
+       if (p [7] > sizeof (void*))
                return NULL;
+       if (read_int32 (p + 20)) /* flags must be 0 */
+               return NULL;
+       ctx->startup_time = read_int64 (p + 8);
+       ctx->timer_overhead = read_int32 (p + 16);
        return ctx;
 }
 
@@ -1127,8 +1138,13 @@ compare_class (const void *a, const void *b)
 static void
 dump_header (ProfContext *ctx)
 {
+       time_t st = ctx->startup_time / 1000;
+       char *t = ctime (&st);
        fprintf (outfile, "\nMono log profiler data\n");
+       fprintf (outfile, "\tProfiler version: %d.%d\n", ctx->version_major, ctx->version_minor);
        fprintf (outfile, "\tData version: %d\n", ctx->data_version);
+       fprintf (outfile, "\tMean timer overhead: %d nanoseconds\n", ctx->timer_overhead);
+       fprintf (outfile, "\tProgram startup: %s\n", t);
 }
 
 static void
index 5c4ccdd012c1ec10a10c680876ada9f7a2a473bd..ac08dc221abbfd7029626b1c65ec6809e45d6a9a 100644 (file)
@@ -386,8 +386,8 @@ dump_header (MonoProfiler *profiler)
        *p++ = LOG_VERSION_MINOR;
        *p++ = LOG_DATA_VERSION;
        *p++ = sizeof (void*);
-       p = write_int64 (p, 0); /* startup time */
-       p = write_int32 (p, 0); /* timer overhead */
+       p = write_int64 (p, ((uint64_t)time (NULL)) * 1000); /* startup time */
+       p = write_int32 (p, get_timer_overhead ()); /* timer overhead */
        p = write_int32 (p, 0); /* flags */
        p = write_int32 (p, 0); /* pid */
        p = write_int32 (p, 0); /* opsystem */
index b6e83963e58108831d97cd1db9794c88b7e984fa..e36e82e7f67ee288278ab7088ed85fc86f41f817 100644 (file)
@@ -77,6 +77,7 @@ static CRITICAL_SECTION log_lock;
 static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
+static int timer_overhead = 0;
 static uint64_t time_inc = 0;
 typedef uint64_t (*TimeFunc)(void);
 
@@ -208,6 +209,8 @@ null_time (void)
 void
 utils_init (int fast_time)
 {
+       int i;
+       uint64_t time_start, time_end;
        TLS_INIT (tls_data);
 #ifdef HOST_WIN32
        InitializeCriticalSection (&log_lock);
@@ -233,6 +236,17 @@ utils_init (int fast_time)
        } else {
                time_func = clock_time;
        }
+       time_start = time_func ();
+       for (i = 0; i < 256; ++i)
+               time_func ();
+       time_end = time_func ();
+       timer_overhead = (time_end - time_start) / 256;
+}
+
+int
+get_timer_overhead (void)
+{
+       return timer_overhead;
 }
 
 uint64_t
index c7e1c33ba3c1947978dee5a308698fcac3b5a12b..fd104ad4fca763d81e3c02dbba91ff92184c5cd9 100644 (file)
@@ -5,6 +5,7 @@
 #include "mono/utils/mono-publib.h"
 
 void utils_init (int fast_time);
+int get_timer_overhead (void);
 uint64_t current_time (void);
 void* alloc_buffer (int size);
 void free_buffer (void *buf, int size);