I am not able to understand and analyze the profile generated using jeprof as it is not maping the symbols and showing the hex addesses I guess.
I am trying to generate the profile of following code:
#include <iostream>
#include <thread>
#include <jemalloc/jemalloc.h>
// #include <gperftools/profiler.h>
void task1()
{ for(int i=0; i<=100;i++){
// allocate some memory using jemalloc
void* data = malloc(sizeof(int) * 1000);
// std::cout << "Task 1: " <<i<< " Allocated memory at address " << data << "\n";
// do some work
// free the memory using jemalloc
free(data);
// std::cout << "Task 1: Freed memory at address " << data << "\n";
}}
void task2()
{
for(int i=0; i<=100;i++){
// allocate some memory using jemalloc
void* data = malloc(sizeof(int) * 1000);
// std::cout << "Task 2: " << i<< " Allocated memory at address " << data << "\n";
// free the memory using jemalloc
free(data);
// std::cout << "Task 2: Freed memory at address " << data << "\n";
}
}
int main()
{ setenv("opt.lg_prof_sample", "15", 1);
setenv("MALLOC_CONF", "opt.prof=true,opt.prof_prefix=profile,zero_realloc:true,narenas:8", 1);
setenv("opt.oversize_threshold", "1000", 1); // Set oversize_threshold to 4096 bytes
// initialize jemalloc
// ProfilerStart("heap_profiler.log");
// create two threads to perform tasks
std::thread t1(task1);
std::thread t2(task2);
// wait for threads to finish
t1.join();
t2.join();
// ProfilerStop();
return 0;
}
Execution steps: