Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why cant capture any data? #218

Open
gfa99 opened this issue Jan 11, 2025 · 2 comments
Open

Why cant capture any data? #218

gfa99 opened this issue Jan 11, 2025 · 2 comments

Comments

@gfa99
Copy link

gfa99 commented Jan 11, 2025

#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

@bar2104y
Copy link

bar2104y commented Feb 3, 2025

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();

@yse
Copy link
Owner

yse commented Feb 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants