if (offset < 0)
goto fail;
- /* Reduce our allocation now that we know where the end of the key section is. */
- pKeys->fileData = (char *)realloc(pKeys->fileData, offset);
- pKeys->fileLen = offset;
/* Leave fp pointing to the beginning of the data section. */
fseek(fp, offset, SEEK_SET);
/* Create cache if it doesn't already exist */
if (pKeys->methodCache == NULL) {
- pKeys->methodCache = (int*) malloc(sizeof(int) * METHOD_CACHE_SIZE);
+ pKeys->methodCache = (int*) calloc(METHOD_CACHE_SIZE, sizeof(int));
}
// ids are multiples of 4, so shift
}
TraceData data1;
+ memset(&data1, 0, sizeof(data1));
DataKeys* dataKeys = parseDataKeys(&data1, gOptions.traceFileName,
&sumThreadTime, filters);
if (dataKeys == NULL) {
} else if (strcmp(argv[i], "-Xcheckdexsum") == 0) {
gDvm.verifyDexChecksum = true;
+ } else if (strcmp(argv[i], "-Xprofile:wallclock") == 0) {
+ gDvm.profilerWallClock = true;
+
} else {
if (!ignoreUnrecognized) {
dvmFprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
static inline u8 getClock()
{
#if defined(HAVE_POSIX_CLOCKS)
- struct timespec tm;
+ if (!gDvm.profilerWallClock) {
+ struct timespec tm;
- clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);
- //assert(tm.tv_nsec >= 0 && tm.tv_nsec < 1*1000*1000*1000);
- if (!(tm.tv_nsec >= 0 && tm.tv_nsec < 1*1000*1000*1000)) {
- LOGE("bad nsec: %ld\n", tm.tv_nsec);
- dvmAbort();
- }
-
- return tm.tv_sec * 1000000LL + tm.tv_nsec / 1000;
-#else
- struct timeval tv;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);
+ if (!(tm.tv_nsec >= 0 && tm.tv_nsec < 1*1000*1000*1000)) {
+ LOGE("bad nsec: %ld\n", tm.tv_nsec);
+ dvmAbort();
+ }
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000000LL + tv.tv_usec;
+ return tm.tv_sec * 1000000LL + tm.tv_nsec / 1000;
+ } else
#endif
+ {
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000000LL + tv.tv_usec;
+ }
}
/*
fprintf(state->traceFile, "data-file-overflow=%s\n",
state->overflow ? "true" : "false");
#if defined(HAVE_POSIX_CLOCKS)
- fprintf(state->traceFile, "clock=thread-cpu\n");
-#else
- fprintf(state->traceFile, "clock=global\n");
+ if (!gDvm.profilerWallClock) {
+ fprintf(state->traceFile, "clock=thread-cpu\n");
+ } else
#endif
+ {
+ fprintf(state->traceFile, "clock=wall\n");
+ }
fprintf(state->traceFile, "elapsed-time-usec=%llu\n", elapsed);
fprintf(state->traceFile, "num-method-calls=%d\n",
(finalCurOffset - TRACE_HEADER_LEN) / TRACE_REC_SIZE);