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.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <pd/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
@@ -143,6 +144,8 @@ class TimeStats {
|
|||||||
* Timatrace Functions
|
* Timatrace Functions
|
||||||
*/
|
*/
|
||||||
namespace TT {
|
namespace TT {
|
||||||
|
class Res;
|
||||||
|
using TraceMap = std::map<std::string, TT::Res>;
|
||||||
/**
|
/**
|
||||||
* Data Structure for a TimeTrace Result
|
* Data Structure for a TimeTrace Result
|
||||||
*/
|
*/
|
||||||
@@ -202,11 +205,11 @@ class Res {
|
|||||||
/** Trace ID */
|
/** Trace ID */
|
||||||
std::string id;
|
std::string id;
|
||||||
/** Start time */
|
/** Start time */
|
||||||
u64 start;
|
u64 start = 0;
|
||||||
/** End Time */
|
/** End Time */
|
||||||
u64 end;
|
u64 end = 0;
|
||||||
/** Last Diff */
|
/** Last Diff */
|
||||||
u64 diff;
|
u64 diff = 0;
|
||||||
/** Protocol */
|
/** Protocol */
|
||||||
TimeStats protocol;
|
TimeStats protocol;
|
||||||
};
|
};
|
||||||
@@ -220,6 +223,9 @@ PD_API void Beg(const std::string& id);
|
|||||||
* @param id Name of the Trace
|
* @param id Name of the Trace
|
||||||
*/
|
*/
|
||||||
PD_API void End(const std::string& id);
|
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
|
* Collect Start end end of the trace by tracking
|
||||||
* when the Scope object goes out of scope
|
* when the Scope object goes out of scope
|
||||||
|
|||||||
@@ -22,15 +22,30 @@ SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/timetrace.hpp>
|
#include <pd/core/timetrace.hpp>
|
||||||
|
#include <pd/drivers/os.hpp>
|
||||||
|
|
||||||
namespace PD::TT {
|
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) {
|
PD_API void Beg(const std::string& id) {
|
||||||
/*auto trace = os.GetTraceRef(id);
|
auto& trace = GetTraceRef(id);
|
||||||
trace->SetStart(os.GetNanoTime());*/
|
trace.SetStart(PD::Os::GetTimeNano());
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void End(const std::string& id) {
|
PD_API void End(const std::string& id) {
|
||||||
/*auto trace = os.GetTraceRef(id);
|
auto& trace = GetTraceRef(id);
|
||||||
trace->SetEnd(os.GetNanoTime());*/
|
trace.SetEnd(PD::Os::GetTimeNano());
|
||||||
}
|
}
|
||||||
} // namespace PD::TT
|
} // namespace PD::TT
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <pd/drivers/os.hpp>
|
#include <pd/drivers/os.hpp>
|
||||||
|
|
||||||
namespace PD {
|
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 {
|
PD_API u64 OsDriver::GetTime() const {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
|||||||
Reference in New Issue
Block a user