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

Move back timer comments to header #2572

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions nano/lib/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,20 @@ desc (description_a)
{
}

/** Do not output if measured time is below the time units threshold in \p minimum_a */
template <typename UNIT, typename CLOCK>
nano::timer<UNIT, CLOCK> & nano::timer<UNIT, CLOCK>::set_minimum (UNIT minimum_a)
{
minimum = minimum_a;
return *this;
}

/**
* Create a child timer without starting it.
* Since the timing API needs to have low overhead, this function
* does not check if a timer with the same name already exists.
*/
template <typename UNIT, typename CLOCK>
nano::timer<UNIT, CLOCK> & nano::timer<UNIT, CLOCK>::child (std::string const & description_a)
{
children.emplace_back (description_a, this);
return children.back ();
}

/** Create and start a child timer */
template <typename UNIT, typename CLOCK>
nano::timer<UNIT, CLOCK> & nano::timer<UNIT, CLOCK>::start_child (std::string const & description_a)
{
Expand All @@ -95,7 +88,6 @@ nano::timer<UNIT, CLOCK> & nano::timer<UNIT, CLOCK>::start_child (std::string co
return child_timer;
}

/** Start the timer. This will assert if the timer is already started. */
template <typename UNIT, typename CLOCK>
void nano::timer<UNIT, CLOCK>::start ()
{
Expand All @@ -104,7 +96,6 @@ void nano::timer<UNIT, CLOCK>::start ()
begin = CLOCK::now ();
}

/** Restarts the timer */
template <typename UNIT, typename CLOCK>
void nano::timer<UNIT, CLOCK>::restart ()
{
Expand All @@ -114,22 +105,13 @@ void nano::timer<UNIT, CLOCK>::restart ()
measurements = 0;
}

/**
* Stops the timer and increases the measurement count. A timer can be started and paused
* multiple times (e.g. in a loop).
* @return duration
*/
template <typename UNIT, typename CLOCK>
UNIT nano::timer<UNIT, CLOCK>::pause ()
{
++measurements;
return stop ();
}

/**
* Stop timer
* @return duration
*/
template <typename UNIT, typename CLOCK>
UNIT nano::timer<UNIT, CLOCK>::stop ()
{
Expand All @@ -141,48 +123,40 @@ UNIT nano::timer<UNIT, CLOCK>::stop ()
return ticks;
}

/**
* Return current units.
*/
template <typename UNIT, typename CLOCK>
UNIT nano::timer<UNIT, CLOCK>::value () const
{
return ticks;
}

/** Returns the duration in UNIT since the timer was last started. */
template <typename UNIT, typename CLOCK>
UNIT nano::timer<UNIT, CLOCK>::since_start () const
{
auto end = CLOCK::now ();
return std::chrono::duration_cast<UNIT> (end - begin);
}

/** Returns true if the timer was last started longer than \p duration_a units ago*/
template <typename UNIT, typename CLOCK>
bool nano::timer<UNIT, CLOCK>::after_deadline (UNIT duration_a)
{
auto end = CLOCK::now ();
return std::chrono::duration_cast<UNIT> (end - begin) > duration_a;
}

/** Returns true if the timer was last started shorter than \p duration_a units ago*/
template <typename UNIT, typename CLOCK>
bool nano::timer<UNIT, CLOCK>::before_deadline (UNIT duration_a)
{
auto end = CLOCK::now ();
return std::chrono::duration_cast<UNIT> (end - begin) < duration_a;
}

/** Stop timer and write measurements to \p stream_a */
template <typename UNIT, typename CLOCK>
void nano::timer<UNIT, CLOCK>::stop (std::ostream & stream_a)
{
stop ();
print (stream_a);
}

/** Stop timer and write measurements to \p output_a */
template <typename UNIT, typename CLOCK>
void nano::timer<UNIT, CLOCK>::stop (std::string & output_a)
{
Expand All @@ -191,7 +165,6 @@ void nano::timer<UNIT, CLOCK>::stop (std::string & output_a)
output_a = stream.str ();
}

/** Print measurements to the \p stream_a */
template <typename UNIT, typename CLOCK>
void nano::timer<UNIT, CLOCK>::print (std::ostream & stream_a)
{
Expand Down Expand Up @@ -222,7 +195,6 @@ void nano::timer<UNIT, CLOCK>::print (std::ostream & stream_a)
}
}

/** Returns the SI unit string */
template <typename UNIT, typename CLOCK>
std::string nano::timer<UNIT, CLOCK>::unit () const
{
Expand Down
46 changes: 46 additions & 0 deletions nano/lib/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,66 @@ class timer
timer (nano::timer_state state_a, std::string const & description_a = "timer");
timer (std::string const & description_a);
timer (std::string const & description_a, timer * parent_a);

/** Do not output if measured time is below the time units threshold in \p minimum_a */
timer & set_minimum (UNIT minimum_a);

/**
* Create a child timer without starting it.
* Since the timing API needs to have low overhead, this function
* does not check if a timer with the same name already exists.
*/
timer & child (std::string const & description_a = "child timer");

/** Create and start a child timer */
timer & start_child (std::string const & description_a = "child timer");

/** Start the timer. This will assert if the timer is already started. */
void start ();

/**
* Restarts the timer by setting start time to current time and resetting tick count.
* This can be called in any timer state.
*/
void restart ();

/**
* Stops the timer and increases the measurement count. A timer can be started and paused
* multiple times (e.g. in a loop).
* @return duration
*/
UNIT pause ();

/**
* Stop timer. This will assert if the timer is not in a started state.
* @return duration
*/
UNIT stop ();

/**
* Return current tick count.
*/
UNIT value () const;

/** Returns the duration in UNIT since the timer was last started. */
UNIT since_start () const;

/** Returns true if the timer was last started longer than \p duration_a units ago*/
bool after_deadline (UNIT duration_a);

/** Returns true if the timer was last started shorter than \p duration_a units ago*/
bool before_deadline (UNIT duration_a);

/** Stop timer and write measurements to \p stream_a */
void stop (std::ostream & stream_a);

/** Stop timer and write measurements to \p output_a */
void stop (std::string & output_a);

/** Print measurements to the \p stream_a */
void print (std::ostream & stream_a);

/** Returns the SI unit string */
std::string unit () const;
nano::timer_state current_state () const;

Expand Down
2 changes: 1 addition & 1 deletion nano/node/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace nano
{
/** Policy to affects at which stage a buffer can be dropped */
/** Policy to affect at which stage a buffer can be dropped */
enum class buffer_drop_policy
{
/** Can be dropped by bandwidth limiter (default) */
Expand Down