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 sectioned scoped timer #864

Merged
merged 6 commits into from Aug 15, 2016

Conversation

LGM-Doyle
Copy link
Contributor

This PR does three things:

  • makes the time threshold for display of ScopedTimer a parameter of the constructor
  • adds SectionedScopedTimer as a ScopedTimer with separately timed sub-sections.
  • uses SectionedScopedTimer in MapWnd::InitTurn() as an example.

SectionedScopedTimer is a ScopedTimer with an additional member functionEnterSection(<section name>), which creates/re-enters a separately timed sub section, with an arbitrary name.

When SectionedScopedTimer goes out of scope and is destroyed it prints a table of times. The table includes its total time and the time of any subsections that exceed the threshold parameter.

An example table looks like this:

         Title - Section  time: xxxx ms
         Title - Section2 time: xxxx ms
         Title            time: xxxx ms

SectionedScopedTimer was the profiling tool that I used while working on the split fleet timing PR #863. I stripped it out of that PR to submit here separately.

Change ScopedTimer from using deprecated boost::timer to using
boost::chrono.

The deprecated  boost::timer was a wall clock on Windows and a POSIX
clock on POSIX machines.

boost::chrono is interchangeable with the std::chrono supported in
C++11.

I chose not to upgrade to the newer boost::timer implementation.  The
new boost::timer uses a non-standard duration representation and implies
in the documentation that in future it will upgrade to chrono.
In order to produce output with ScopedTimer either
always_output or verbose-logging has to be true.

Change always_output to enable_output to better reflect its meaning.
A variable threshold is useful for profiling functions for which the 1 ms
default is inappropriate.
SectionedScopedTimer works like ScopedTimer and it has a member function
EnterSection(name) which starts a new sub section timer.

When SectionedScopedTimer is destroyer it prints a table of the elapsed
time of each section and the whole timer.

Only one subsection timer is active at a time.

Subsection can be re-entered.
std::string m_name;
bool m_always_output;

void FormatDuration(std::stringstream &ss, const boost::chrono::nanoseconds & duration) {
Copy link
Member

Choose a reason for hiding this comment

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

&ss -> & ss

@LGM-Doyle
Copy link
Contributor Author

I've made the changes.

@Vezzra Vezzra added the category:refactoring The Issue/PR describes or contains an improved implementation. label Aug 15, 2016
@Vezzra Vezzra added this to the Release v0.4.6 milestone Aug 15, 2016
@geoffthemedio geoffthemedio merged commit d9edad4 into freeorion:master Aug 15, 2016
@LGM-Doyle LGM-Doyle deleted the add_SectionedScopedTimer branch August 15, 2016 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:refactoring The Issue/PR describes or contains an improved implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants