]> OCCT Git - occt.git/commitdiff
0032000: Foundation Classes - collect OSD_Timer time in message report
authornds <nds@opencascade.com>
Wed, 16 Dec 2020 09:29:06 +0000 (12:29 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Dec 2020 16:48:02 +0000 (19:48 +0300)
Added Message_MetricType_WallClock metric type handled by Message_AttributeMeter.
Added public OSD_Timer::GetWallClockTime() method.

src/Message/Message.cxx
src/Message/Message_AttributeMeter.cxx
src/Message/Message_MetricType.hxx
src/OSD/OSD_Timer.cxx
src/OSD/OSD_Timer.hxx

index 9dc3a7107e7a952aebae9fb391bcb20bfb510859..0a4de987519e43143f133ef0f486b5331528d2ad 100644 (file)
@@ -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"
   };
 }
index d37cc8b7c3acc87c99daddb2304afa4edc8f4e17..0fe5042dc25402354d2d2d0e7a33973dcbb30952 100644 (file)
@@ -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) ||
index 89a1ac479946ab3a234c5e36d9d3d6efea667ac6..a35e87e5e580f6991c4d086b9110cfc2e131a088 100644 (file)
@@ -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
index c3129a89bee92b944c3b4fa8e91517b2ab3c2f3c..5a0a176bf426f93083e426cda7551432c63decb8 100644 (file)
 
 #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
 }
 
 //=======================================================================
index 2b483283bfaca170f009b18c49b2800a4b07a145..5ea0bab6d49131ff62e9158cdc7d30db75628044 100644 (file)
 //! // 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