mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
0032000: Foundation Classes - collect OSD_Timer time in message report
Added Message_MetricType_WallClock metric type handled by Message_AttributeMeter. Added public OSD_Timer::GetWallClockTime() method.
This commit is contained in:
parent
53f46612d9
commit
9283bba22f
@ -25,9 +25,9 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
static Standard_CString Message_Table_PrintMetricTypeEnum[10] =
|
||||
static Standard_CString Message_Table_PrintMetricTypeEnum[11] =
|
||||
{
|
||||
"NONE", "UserTimeCPU", "SystemTimeInfo", "MemPrivate", "MemVirtual",
|
||||
"NONE", "UserTimeCPU", "SystemTimeInfo", "WallClock", "MemPrivate", "MemVirtual",
|
||||
"MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage"
|
||||
};
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <Message.hxx>
|
||||
#include <Message_Report.hxx>
|
||||
#include <OSD_Chronometer.hxx>
|
||||
#include <OSD_Timer.hxx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
#include <Standard_Dump.hxx>
|
||||
@ -128,6 +129,16 @@ void Message_AttributeMeter::SetAlertMetrics (const Handle(Message_AlertExtended
|
||||
const NCollection_IndexedMap<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
|
||||
|
||||
// time metrics
|
||||
if (anActiveMetrics.Contains (Message_MetricType_WallClock))
|
||||
{
|
||||
OSD_Timer aTimer;
|
||||
aTimer.Start();
|
||||
Standard_Real aTime = OSD_Timer::GetWallClockTime();
|
||||
if (theStartValue)
|
||||
aMeterAttribute->SetStartValue (Message_MetricType_WallClock, aTime);
|
||||
else
|
||||
aMeterAttribute->SetStopValue (Message_MetricType_WallClock, aTime);
|
||||
}
|
||||
if (anActiveMetrics.Contains (Message_MetricType_ProcessCPUUserTime) ||
|
||||
anActiveMetrics.Contains (Message_MetricType_ProcessCPUSystemTime) ||
|
||||
anActiveMetrics.Contains (Message_MetricType_ThreadCPUUserTime) ||
|
||||
|
@ -22,6 +22,7 @@ enum Message_MetricType
|
||||
Message_MetricType_ThreadCPUSystemTime, //!< OSD_Chronometer::GetThreadCPU system time
|
||||
Message_MetricType_ProcessCPUUserTime, //!< OSD_Chronometer::GetProcessCPU user time
|
||||
Message_MetricType_ProcessCPUSystemTime, //!< OSD_Chronometer::GetProcessCPU system time
|
||||
Message_MetricType_WallClock, //!< OSD_Timer elapsed time
|
||||
Message_MetricType_MemPrivate, //!< OSD_MemInfo::MemPrivate
|
||||
Message_MetricType_MemVirtual, //!< OSD_MemInfo::MemVirtual
|
||||
Message_MetricType_MemWorkingSet, //!< OSD_MemInfo::MemWorkingSet
|
||||
|
@ -16,50 +16,11 @@
|
||||
|
||||
#include <OSD_Timer.hxx>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
//=======================================================================
|
||||
//function : GetWallClockTime
|
||||
//purpose : Get current time in seconds with system-defined precision
|
||||
//=======================================================================
|
||||
|
||||
static inline Standard_Real GetWallClockTime ()
|
||||
{
|
||||
struct timeval tv;
|
||||
// use time of first call as base for computing total time,
|
||||
// to avoid loss of precision due to big values of tv_sec (counted since 1970)
|
||||
static time_t startSec = (gettimeofday (&tv, NULL) ? 0 : tv.tv_sec);
|
||||
return gettimeofday (&tv, NULL) ? 0. : (tv.tv_sec - startSec) + 0.000001 * tv.tv_usec;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
//=======================================================================
|
||||
//function : GetWallClockTime
|
||||
//purpose : Get current time in seconds with system-defined precision
|
||||
//=======================================================================
|
||||
|
||||
static inline Standard_Real GetWallClockTime ()
|
||||
{
|
||||
// compute clock frequence on first call
|
||||
static LARGE_INTEGER freq;
|
||||
static BOOL isOk = QueryPerformanceFrequency (&freq);
|
||||
|
||||
LARGE_INTEGER time;
|
||||
return isOk && QueryPerformanceCounter (&time) ?
|
||||
(Standard_Real)time.QuadPart / (Standard_Real)freq.QuadPart :
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
0.001 * GetTickCount64();
|
||||
#else
|
||||
0.001 * GetTickCount();
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -78,6 +39,49 @@ namespace
|
||||
theMinutes = (aSec - theHours * 3600) / 60;
|
||||
theSeconds = theTimeSec - theHours * 3600 - theMinutes * 60;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
//! Define a structure for initializing global constant of pair values.
|
||||
struct PerfCounterFreq
|
||||
{
|
||||
LARGE_INTEGER Freq;
|
||||
Standard_Boolean IsOk;
|
||||
|
||||
PerfCounterFreq()
|
||||
{
|
||||
IsOk = QueryPerformanceFrequency (&Freq) != FALSE;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetWallClockTime
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Real OSD_Timer::GetWallClockTime()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// compute clock frequence on first call
|
||||
static const PerfCounterFreq aFreq;
|
||||
|
||||
LARGE_INTEGER aTime;
|
||||
return aFreq.IsOk && QueryPerformanceCounter (&aTime)
|
||||
? (Standard_Real )aTime.QuadPart / (Standard_Real )aFreq.Freq.QuadPart
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
: 0.001 * GetTickCount64();
|
||||
#else
|
||||
: 0.001 * GetTickCount();
|
||||
#endif
|
||||
#else
|
||||
struct timeval aTime;
|
||||
// use time of first call as base for computing total time,
|
||||
// to avoid loss of precision due to big values of tv_sec (counted since 1970)
|
||||
static const time_t aStartSec = (gettimeofday (&aTime, NULL) == 0 ? aTime.tv_sec : 0);
|
||||
return gettimeofday (&aTime, NULL) == 0
|
||||
? (aTime.tv_sec - aStartSec) + 0.000001 * aTime.tv_usec
|
||||
: 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
@ -40,6 +40,14 @@
|
||||
//! // t1 and t2.
|
||||
class OSD_Timer : public OSD_Chronometer
|
||||
{
|
||||
public:
|
||||
|
||||
//! Returns current time in seconds with system-defined precision.
|
||||
//! The could be a system uptime or a time from some date.
|
||||
//! Returned value is intended for precise elapsed time measurements as a delta between timestamps.
|
||||
//! On Windows implemented via QueryPerformanceCounter(), on other systems via gettimeofday().
|
||||
Standard_EXPORT static Standard_Real GetWallClockTime();
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
Loading…
x
Reference in New Issue
Block a user