-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fixed Instrumentor generating same start time #185
Conversation
It needs to be written to the json file in a floating point format for
tracing to process it properly.
…On Tue, Dec 17, 2019 at 2:07 PM WhoseTheNerd ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Hazel/src/Hazel/Debug/Instrumentor.h
<#185 (comment)>:
>
#include <thread>
namespace Hazel {
struct ProfileResult
{
std::string Name;
- long long Start, End;
+ long double Start, End;
Would suggest uint64_t.
|
Similar note as I wrote in #175 (comment): Cherno has something in mind, he might fix it himself. If it still takes too long, we can always merge a PR to fix this issue. |
Copy, no worries. I only threw it out there because of this comment... |
EDIT: sorry for multiple editions/spams. I'm reviewing the code source. I think we can add some optimizations. I summarize all my ideas. I may give a PR if needed. Concerning the original code of Instrumentor.h:
|
@Penuvil @LovelySanta Here my modified version https://gist.github.com/Lecrapouille/1341f9392fb79831efe5ff7f42374c54 Edit: In version 2 I restored Hazel original names and code style (version 1 was when I checked with my personal project and I did not have time to set it back. Done now). In both version I'm based on Penuvil PR. While I did not test for fast functions. I hope this will help to reduce the profiler overhead inside measurements. For the debate of long double, microseconds vs nanoseconds I cannot help because I'm a noob concerning chrono lib. My changes (use meld editor to see diff) are:
With XXX something like |
Been pretty busy with holidays and sick kids, I will look over all of this as soon as I get a chance. |
"Replaced m_OutputStream.flush(); by std::endl (some text editor failed when lines are too long)" didn't you watch Jason Turners video about NOT using std::endl and instead calling std::flush on your own once work is done? https://www.youtube.com/watch?v=GMqQOEZYVJQ&list=PLs3KjaCtOwSZ2tbuV1hx8Xz-rFZTan2J1&index=7 |
@HerrDingenz I know that forcing a flush takes more time than letting filling the buffer until completely full which makes an automatic flush (~1024 to 4096 bytes). But you are right we can try to optimize this part. This document http://www.dil.univ-mrs.fr/~regis/prog/pdf/c-sys.4b.stdio-bufferisation.pdf describes it better than your video (sorry in french but it's the best I found yet). I summarized pages 9 and 11: There are 3 modes of buffering:
According to your video std::ofstream looks to be fully-buffered which is in accordance to my document. Anyway, the original code already called flushes, I just add an extra carriage return to avoid making some text editors crying when opening the file. I did nothing more! But yes, we may replace std::endl by '\n' but this not Windows compliant. Another solution would be to store in RAM ProfileResult (with a std::dqueue ?!) and when WriteFooter() is called, convert all ProfileResults as JSON format and write lines in the file. |
Update... As pointed out there are some other issues but this PR was intended to fix the duplicate start times. I'm personally not a big fan of trying to address too many issues in one PR. |
This looks fine as it is to solve the issue, should we open new issues that are mentioned here, and link to this PR? |
Looks like the memory leak and multiple BeginSession() issues, m_ProfileCount and ThreadID are cleaned up in PR #179. I could update this PR to include the minor change to m_Stoppped if you want and the suggested change to std::replace should probably be it's own issue. |
Make the two seperate PR's one for m_Stopped instead of m_CurrentSession and one for the std::replace. This will be easier to resolve merge conflicts |
I did not notice PR 179 when I made my suggestion. It looks fine. |
I will work on the conflicts and test again |
It should be good now, test it on your rig an let me know if you have any problems. |
Works for me! Found my mistake: I misplaced the |
Describe the issue (if no issue has been made)
Instrumentor clock resolution is too low and can create duplicate start times for closely executed functions.
PR impact (Make sure to add closing keywords)
List of related issues/PRs this will solve:
Proposed fix (Make sure you've read on how to contribute to Hazel)
Change start and stop times to nanoseconds, static cast to long double and divide by 1000 so Chrome tracing will accept the input. Chrome tracing will not accept nanoseconds directly but will accept floating point microsecond input.
Additional context
This will fail once nanoseconds since epoch becomes too large to fit in a double.
If higher resolution than nanoseconds is needed Chrome Tracing might not be the best solution because you would have to manually manipulate start times to avoid duplicates after that.