-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Access profiler from cpp #16580
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
Access profiler from cpp #16580
Conversation
torch/csrc/autograd/profiler.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs #include <fstream> to build on my devserver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
|
|
||
| RecordProfile::~RecordProfile() { | ||
| thread_event_lists event_lists = disableProfiler(); | ||
| std::vector<Event*> events; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of unnecessary. We could simply have this double loop inside processEvents and avoid allocating as many pointers as we have events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus you don't even reserve memory, meaning that we will keep reallocating the storage many many times
| } | ||
|
|
||
| void RecordProfile::init() { | ||
| enableProfiler(ProfilerState::CPU); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be nice to take this as a constructor argument too
| } | ||
|
|
||
| void RecordProfile::processEvents(const std::vector<Event*>& events) { | ||
| AT_CHECK(out_, "could not open file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: check in constructor (when the file is actually opened)?
| break; | ||
| } | ||
| } | ||
| AT_CHECK(start, "could not find start?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AT_ASSERT?
@jamesr66a