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;
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;
}
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
*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 */
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);
void
utils_init (int fast_time)
{
+ int i;
+ uint64_t time_start, time_end;
TLS_INIT (tls_data);
#ifdef HOST_WIN32
InitializeCriticalSection (&log_lock);
} 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
#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);