time trace is back
This commit is contained in:
@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
@@ -143,6 +144,8 @@ class TimeStats {
|
||||
* Timatrace Functions
|
||||
*/
|
||||
namespace TT {
|
||||
class Res;
|
||||
using TraceMap = std::map<std::string, TT::Res>;
|
||||
/**
|
||||
* Data Structure for a TimeTrace Result
|
||||
*/
|
||||
@@ -202,11 +205,11 @@ class Res {
|
||||
/** Trace ID */
|
||||
std::string id;
|
||||
/** Start time */
|
||||
u64 start;
|
||||
u64 start = 0;
|
||||
/** End Time */
|
||||
u64 end;
|
||||
u64 end = 0;
|
||||
/** Last Diff */
|
||||
u64 diff;
|
||||
u64 diff = 0;
|
||||
/** Protocol */
|
||||
TimeStats protocol;
|
||||
};
|
||||
@@ -220,6 +223,9 @@ PD_API void Beg(const std::string& id);
|
||||
* @param id Name of the Trace
|
||||
*/
|
||||
PD_API void End(const std::string& id);
|
||||
PD_API TraceMap& GetTraceMap();
|
||||
PD_API TT::Res& GetTraceRef(const std::string& id);
|
||||
PD_API bool TraceExist(const std::string& id);
|
||||
/**
|
||||
* Collect Start end end of the trace by tracking
|
||||
* when the Scope object goes out of scope
|
||||
|
||||
@@ -22,15 +22,30 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
namespace PD::TT {
|
||||
static TraceMap pTraces;
|
||||
|
||||
PD_API TraceMap& GetTraceMap() { return pTraces; }
|
||||
|
||||
PD_API TT::Res& GetTraceRef(const std::string& id) {
|
||||
if (!pTraces.count(id)) {
|
||||
pTraces[id] = TT::Res();
|
||||
pTraces[id].SetID(id);
|
||||
}
|
||||
return pTraces[id];
|
||||
}
|
||||
|
||||
PD_API bool TraceExist(const std::string& id) { return pTraces.count(id); }
|
||||
|
||||
PD_API void Beg(const std::string& id) {
|
||||
/*auto trace = os.GetTraceRef(id);
|
||||
trace->SetStart(os.GetNanoTime());*/
|
||||
auto& trace = GetTraceRef(id);
|
||||
trace.SetStart(PD::Os::GetTimeNano());
|
||||
}
|
||||
|
||||
PD_API void End(const std::string& id) {
|
||||
/*auto trace = os.GetTraceRef(id);
|
||||
trace->SetEnd(os.GetNanoTime());*/
|
||||
auto& trace = GetTraceRef(id);
|
||||
trace.SetEnd(PD::Os::GetTimeNano());
|
||||
}
|
||||
} // namespace PD::TT
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_API std::unique_ptr<OsDriver> Os::driver;
|
||||
PD_API std::unique_ptr<OsDriver> Os::driver = std::make_unique<OsDriver>();
|
||||
|
||||
PD_API u64 OsDriver::GetTime() const {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
|
||||
Reference in New Issue
Block a user