Esempio n. 1
0
void FunctionAddressRegistry::dumpPerfMap() {
    std::string out_path = "perf_map";
    removeDirectoryIfExists(out_path);

    llvm_error_code code;
    code = llvm::sys::fs::create_directory(out_path, false);
    assert(!code);

    FILE* index_f = fopen((out_path + "/index.txt").c_str(), "w");

    char buf[80];
    snprintf(buf, 80, "/tmp/perf-%d.map", getpid());
    FILE* f = fopen(buf, "w");
    for (const auto& p : functions) {
        const FuncInfo& info = p.second;
        fprintf(f, "%lx %x %s\n", (uintptr_t)p.first, info.length, info.name.c_str());

        if (info.length > 0) {
            fprintf(index_f, "%lx %s\n", (uintptr_t)p.first, info.name.c_str());

            FILE* data_f = fopen((out_path + "/" + info.name).c_str(), "wb");

            int written = fwrite((void*)p.first, 1, info.length, data_f);
            assert(written == info.length);
            fclose(data_f);
        }
    }
    fclose(f);
}
Esempio n. 2
0
AST_Module* parse_string(const char* code) {
    int size = strlen(code);
    char buf[] = "pystontmp_XXXXXX";
    char* tmpdir = mkdtemp(buf);
    assert(tmpdir);
    std::string tmp = std::string(tmpdir) + "/in.py";
    if (VERBOSITY() >= 3) {
        printf("writing %d bytes to %s\n", size, tmp.c_str());
    }

    FILE* f = fopen(tmp.c_str(), "w");
    fwrite(code, 1, size, f);
    fputc('\n', f);
    fclose(f);

    AST_Module* m = parse_file(tmp.c_str());
    removeDirectoryIfExists(tmpdir);

    return m;
}