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

Add support for scoped timings. #4533

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Nov 14, 2024

I think there are a few related ways to do this. I considered llvm::make_scope_exit, but the return type is difficult to work with. I particularly was thinking I could encapsulate the duration logic this way.

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Nice, I like the scoped model.

Left a minor API suggestion, but its not blocking either way.


private:
std::optional<Timings>* timings;
llvm::StringRef label;
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about using a std::string here and moving it into the Add call (with the old API)?

Mostly it'd make it safe to use this with a string built with any formatting, and it shouldn't change how many strings we end up needing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would allocate the string regardless of whether timings were on. Is that desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't get me wrong, there could be a similar: label(*timings ? std::string(label) : std::string())

It'd just been my leaning to keep the size smaller for the common case where timings weren't collected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note, might want a slightly different structure if this is used with formatting, since we'd probably want to avoid creation of the formatted string when not storing timings.

@jonmeow jonmeow added this pull request to the merge queue Nov 15, 2024
Merged via the queue into carbon-language:trunk with commit 1d8c7ff Nov 15, 2024
10 checks passed
@jonmeow jonmeow deleted the timing branch November 15, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants