Skip to content

Minor profiler refactor to avoid string construction#197

Closed
zwxxx wants to merge 4 commits intomicrosoft:masterfrom
zwxxx:refator_profiler
Closed

Minor profiler refactor to avoid string construction#197
zwxxx wants to merge 4 commits intomicrosoft:masterfrom
zwxxx:refator_profiler

Conversation

@zwxxx
Copy link
Contributor

@zwxxx zwxxx commented Dec 17, 2018

std string concatenation allocates. Check if profiler enabled then call EndTimeAndRecordEvent to avoid string construction and allocation.
@pranavsharma
@tracysh

@zwxxx zwxxx requested a review from a team as a code owner December 17, 2018 21:50
void Profiler::EndTimeAndRecordEvent(EventCategory category,
const std::string& event_name,
TimePoint& start_time,
const std::initializer_list<std::pair<std::string, std::string>>& event_args,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this take away the ability to record multiple key-val pairs in a profile? Isn't invoking this function conditionally (that is only when profiling is enabled) enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see why one EndTimeAndRecordEvent should take multiple events. At least existing code has no such cases. But if you insist, I can add it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it, yeah recording just one event is fine. However we should've a name for the thing that you're recording. So in this case I don't know if the string that you're recording is an op_name or something else. Would be good to add event_name and event_value parameters to the function.

Copy link
Contributor Author

@zwxxx zwxxx Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok it makes sense. added std::pair<std::string, std::string> back.

@pranavsharma
Copy link
Contributor

/AzurePipelines run all

const std::string& event_name,
TimePoint& start_time,
const std::string& op_name,
const std::pair<std::string, std::string>& op_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change. This pair can contain stuff besides op_name too, right? what's a good name for this parameter? tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are probably meant to act as props/annotations/tags for the actual event being recorded. The event being recorded is already being captured in the event_name param. So may be we can use props.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to tags.

@pranavsharma
Copy link
Contributor

Looks like some of the tests failed. Can you rebase?

Copy link
Member

@yufenglee yufenglee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't notice this PR. I made a similar PR that was merged.

@yufenglee
Copy link
Member

I would like to close this PR as it has been inactive for a while and similar change was merged.

@yufenglee yufenglee closed this May 2, 2019
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

Successfully merging this pull request may close these issues.

3 participants