Beispiel #1
0
/* Dumps free and used ranges, as text, to the named file.
 */
void dvmDumpHeapToFile(const char *fileName)
{
    HeapDumpContext ctx;
    FILE *fp;

    fp = fopen(fileName, "w+");
    if (fp == NULL) {
        LOGE("Can't open %s for writing: %s\n", fileName, strerror(errno));
        return;
    }
    LOGW("Dumping heap to %s...\n", fileName);

    fprintf(fp, "==== Dalvik heap dump ====\n");
    memset(&ctx, 0, sizeof(ctx));
    ctx.fp = fp;
    dvmHeapSourceWalk(heap_chunk_callback, (void *)&ctx);
    dump_context(&ctx);
    fprintf(fp, "==== end heap dump ====\n");

    LOGW("Dumped heap to %s.\n", fileName);

    fclose(fp);
}
Beispiel #2
0
static void walkHeap(bool merge, bool native)
{
    HeapChunkContext ctx;

    memset(&ctx, 0, sizeof(ctx));
    ctx.bufLen = HPSx_CHUNK_SIZE;
    ctx.buf = (u1 *)malloc(ctx.bufLen);
    if (ctx.buf == NULL) {
        return;
    }

    ctx.merge = merge;
    if (native) {
        ctx.type = CHUNK_TYPE("NHSG");
    } else {
        if (ctx.merge) {
            ctx.type = CHUNK_TYPE("HPSG");
        } else {
            ctx.type = CHUNK_TYPE("HPSO");
        }
    }

    ctx.p = ctx.buf;
    ctx.needHeader = true;
    if (native) {
#ifdef USE_DLMALLOC
        dlmalloc_inspect_all(heap_chunk_callback, (void*)&ctx);
#endif
    } else {
        dvmHeapSourceWalk(heap_chunk_callback, (void *)&ctx);
    }
    if (ctx.p > ctx.buf) {
        flush_hpsg_chunk(&ctx);
    }

    free(ctx.buf);
}