Why cant capture any data?
#include <string>
#include "easy/profiler.h"
#include "easy/arbitrary_value.h"
#include <iostream>
int main()
{
EASY_MAIN_THREAD;
EASY_PROFILER_ENABLE;
EASY_FUNCTION();
EASY_BLOCK("main");
auto sum = 0;
for(long i=0; i< 100'000'000; i++) {
EASY_BLOCK("loop");
sum +=i;
}
std::cout << "hello world" << std::endl;
EASY_END_BLOCK;
auto blk_cnt = profiler::dumpBlocksToFile("easy_profile2.prof");
std::cout << "Blocks count: " << blk_cnt << std::endl;
return 0;
}
cmake_minimum_required(VERSION 3.5)
project(demo)
find_package(easy_profiler REQUIRED)
add_executable(demo ./test.cpp)
target_compile_definitions(demo PUBLIC BUILD_WITH_EASY_PROFILER)
target_link_libraries(demo easy_profiler)
My test demo is shown above, but I always get a block of size 0, at the same time the easy_profiler_gui tips
Cannot read profiled blocks Reason: Wrong memory size == 0 for 0 blocks
Did I do something wrong?
btw: I'm using version 2.1.0
Try remove EASY_MAIN_THREAD, i never use it
May be try connect on runtime via gui, for this add
EASY_PROFILER_ENABLE;
profiler::startListen();
Hello @gfa99,
Thanks for reporting this issue.
You need to close all opened blocks using EASY_END_BLOCK.
In your case, you have opened two blocks with:
EASY_FUNCTION();
EASY_BLOCK("main");
Therefore, you should explicitly close them twice using EASY_END_BLOCK, or alternatively, move the logic inside a function so that the block gets closed automatically in the destructor.
I believe we should handle this within the dumpBlocksToFile function, but we need to carefully consider the synthetic case.