wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
8.61k stars 592 forks source link

Reading file throw std::bad alloc #803

Closed Yellow-King21 closed 1 month ago

Yellow-King21 commented 1 month ago

Hello,

I have encountered a problem when saving a file from Trace and then attempting to view it afterward. The issue occurs in TracyUserData.cpp at line 45. Upon debugging, I discovered that the statement const auto sz = ftell(f); sets sz to 9223372036854775807. The file I tried to open is 287.8 MB, but I also tried with a file that is only 49.8 kB. I save the file from the profiler (GUI).

For your reference, I am using:

Best regards, Marek

wolfpld commented 1 month ago

The value returned by ftell is INT64_MAX, which is in the valid range. An error would be indicated by -1, which is not the case here. Can you provide more information about the file, such as the on-disk size, or the filesystem you are using? Note that the problem is not with the trace you have saved, but with an auxiliary data file that has its path constructed in OpenFile().

Yellow-King21 commented 1 month ago

Thank you for your response. I looked into it and found that Tracy opens a directory (so the value is valid but doesn't make sense) and opens <home_path>/.config/tracy/user/, but the correct path should be <home_path>/Documents/big_trace.tracy. I followed your suggestion, and the filesystem is /dev/mapper/vgubuntu-root ext4, and the on-disk size is 275M big_trace.tracy. Could you provide some more information how could I trace this bug and also how do I compile debug version with gdb symbols because I tried cmake -DLEGACY=ON -DCMAKE_C_FLAGS="-O0 -g3 -ggdb" -DCMAKE_CXX_FLAGS="-O0 -g3 -ggdb" .. but there is always optimized values. Thank you.

wolfpld commented 1 month ago

-DCMAKE_BUILD_TYPE=Debug

Yellow-King21 commented 1 month ago

I recompile it and in DEBUG version it stop working at assert TracyStorage.cpp:120 GetSavePath, I look at the pointer but is empty. At RELEASE version it give me <home_path>/.config/tracy/user/ as I mentioned early. I also found that PATH is correct when function at main.cpp:885.

wolfpld commented 1 month ago

207e065f should fix this for you.

Yellow-King21 commented 1 month ago

Yes, this fix the problem and trace file was loaded as expected.

Thank you

Yellow-King21 commented 1 month ago

I have a question: I tried to use Tracy with sudo, but there is no sampling data. Is this the same issue as described in issue #442?

Thank you for your answer

image