forked from SleipnirGroup/Sleipnir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand timing info in final diagnostics
- Loading branch information
Showing
13 changed files
with
684 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <string> | ||
#include <string_view> | ||
|
||
namespace sleipnir { | ||
|
||
/** | ||
* Records the number of profiler measurements (start/stop pairs) and the | ||
* average duration between each start and stop call. | ||
*/ | ||
class SetupProfiler { | ||
public: | ||
std::string name; | ||
|
||
/** | ||
* Constructs a SetupProfiler. | ||
* | ||
* @param name Name of measurement to show in diagnostics. | ||
*/ | ||
explicit SetupProfiler(std::string_view name) : name{name} {} | ||
|
||
/** | ||
* Tell the profiler to start measuring setup time. | ||
*/ | ||
void Start() { | ||
#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS | ||
m_setupStartTime = std::chrono::steady_clock::now(); | ||
#endif | ||
} | ||
|
||
/** | ||
* Tell the profiler to stop measuring setup time. | ||
*/ | ||
void Stop() { | ||
#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS | ||
m_setupStopTime = std::chrono::steady_clock::now(); | ||
m_setupDuration = m_setupStopTime - m_setupStartTime; | ||
#endif | ||
} | ||
|
||
/** | ||
* The setup duration in milliseconds as a double. | ||
*/ | ||
const std::chrono::duration<double>& Duration() const { | ||
return m_setupDuration; | ||
} | ||
|
||
private: | ||
std::chrono::steady_clock::time_point m_setupStartTime; | ||
std::chrono::steady_clock::time_point m_setupStopTime; | ||
std::chrono::duration<double> m_setupDuration{0.0}; | ||
}; | ||
|
||
} // namespace sleipnir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) Sleipnir contributors | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <string> | ||
#include <string_view> | ||
|
||
namespace sleipnir { | ||
|
||
/** | ||
* Records the number of profiler measurements (start/stop pairs) and the | ||
* average duration between each start and stop call. | ||
*/ | ||
class SolveProfiler { | ||
public: | ||
std::string name; | ||
|
||
/** | ||
* Constructs a SolveProfiler. | ||
*/ | ||
SolveProfiler() = default; | ||
|
||
/** | ||
* Constructs a SolveProfiler. | ||
* | ||
* @param name Name of measurement to show in diagnostics. | ||
*/ | ||
explicit SolveProfiler(std::string_view name) : name{name} {} | ||
|
||
/** | ||
* Tell the profiler to start measuring solve time. | ||
*/ | ||
void Start() { | ||
#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS | ||
m_currentSolveStartTime = std::chrono::steady_clock::now(); | ||
#endif | ||
} | ||
|
||
/** | ||
* Tell the profiler to stop measuring solve time, increment the number of | ||
* averages, and incorporate the latest measurement into the average. | ||
*/ | ||
void Stop() { | ||
#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS | ||
m_currentSolveStopTime = std::chrono::steady_clock::now(); | ||
m_currentSolveDuration = m_currentSolveStopTime - m_currentSolveStartTime; | ||
m_totalSolveDuration += m_currentSolveDuration; | ||
|
||
++m_numSolves; | ||
m_averageSolveDuration = | ||
(m_numSolves - 1.0) / m_numSolves * m_averageSolveDuration + | ||
1.0 / m_numSolves * m_currentSolveDuration; | ||
#endif | ||
} | ||
|
||
/** | ||
* The number of solves. | ||
*/ | ||
int NumSolves() const { return m_numSolves; } | ||
|
||
/** | ||
* The most recent solve duration in milliseconds as a double. | ||
*/ | ||
const std::chrono::duration<double>& CurrentDuration() const { | ||
return m_currentSolveDuration; | ||
} | ||
|
||
/** | ||
* The average solve duration in milliseconds as a double. | ||
*/ | ||
const std::chrono::duration<double>& AverageDuration() const { | ||
return m_averageSolveDuration; | ||
} | ||
|
||
/** | ||
* The sum of all solve durations in milliseconds as a double. | ||
*/ | ||
const std::chrono::duration<double>& TotalDuration() const { | ||
return m_totalSolveDuration; | ||
} | ||
|
||
private: | ||
std::chrono::steady_clock::time_point m_currentSolveStartTime; | ||
std::chrono::steady_clock::time_point m_currentSolveStopTime; | ||
std::chrono::duration<double> m_currentSolveDuration{0.0}; | ||
std::chrono::duration<double> m_totalSolveDuration{0.0}; | ||
|
||
int m_numSolves = 0; | ||
std::chrono::duration<double> m_averageSolveDuration{0.0}; | ||
}; | ||
|
||
} // namespace sleipnir |
Oops, something went wrong.