1 // Created on: 1999-11-23
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Message.hxx>
19 #include <Message_Messenger.hxx>
20 #include <Message_Report.hxx>
21 #include <TCollection_AsciiString.hxx>
27 static Standard_CString Message_Table_PrintMetricTypeEnum[13] =
29 "NONE", "ThreadCPUUserTime", "ThreadCPUSystemTime", "ProcessCPUUserTime", "ProcessCPUSystemTime",
30 "WallClock", "MemPrivate", "MemVirtual",
31 "MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage"
35 //=======================================================================
36 //function : DefaultMessenger
38 //=======================================================================
39 const Handle(Message_Messenger)& Message::DefaultMessenger ()
41 static Handle(Message_Messenger) aMessenger = new Message_Messenger;
45 //=======================================================================
48 //=======================================================================
50 TCollection_AsciiString Message::FillTime (const Standard_Integer hour,
51 const Standard_Integer minute,
52 const Standard_Real second)
56 Sprintf (t, "%02dh:%02dm:%.2fs", hour, minute, second);
58 Sprintf (t, "%02dm:%.2fs", minute, second);
60 Sprintf (t, "%.2fs", second);
61 return TCollection_AsciiString (t);
64 //=======================================================================
65 //function : DefaultReport
67 //=======================================================================
68 const Handle(Message_Report)& Message::DefaultReport(const Standard_Boolean theToCreate)
70 static Handle(Message_Report) MyReport;
71 if (MyReport.IsNull() && theToCreate)
73 MyReport = new Message_Report();
78 //=======================================================================
79 //function : MetricToString
81 //=======================================================================
82 Standard_CString Message::MetricToString (const Message_MetricType theType)
84 return Message_Table_PrintMetricTypeEnum[theType];
87 //=======================================================================
88 //function : MetricFromString
90 //=======================================================================
91 Standard_Boolean Message::MetricFromString (const Standard_CString theString,
92 Message_MetricType& theGravity)
94 TCollection_AsciiString aName (theString);
95 for (Standard_Integer aMetricIter = 0; aMetricIter <= Message_MetricType_MemHeapUsage; ++aMetricIter)
97 Standard_CString aMetricName = Message_Table_PrintMetricTypeEnum[aMetricIter];
98 if (aName == aMetricName)
100 theGravity = Message_MetricType (aMetricIter);
101 return Standard_True;
104 return Standard_False;
107 // =======================================================================
108 // function : ToOSDMetric
110 // =======================================================================
111 Standard_Boolean Message::ToOSDMetric (const Message_MetricType theMetric, OSD_MemInfo::Counter& theMemInfo)
115 case Message_MetricType_MemPrivate: theMemInfo = OSD_MemInfo::MemPrivate; break;
116 case Message_MetricType_MemVirtual: theMemInfo = OSD_MemInfo::MemVirtual; break;
117 case Message_MetricType_MemWorkingSet: theMemInfo = OSD_MemInfo::MemWorkingSet; break;
118 case Message_MetricType_MemWorkingSetPeak: theMemInfo = OSD_MemInfo::MemWorkingSetPeak; break;
119 case Message_MetricType_MemSwapUsage: theMemInfo = OSD_MemInfo::MemSwapUsage; break;
120 case Message_MetricType_MemSwapUsagePeak: theMemInfo = OSD_MemInfo::MemSwapUsagePeak; break;
121 case Message_MetricType_MemHeapUsage: theMemInfo = OSD_MemInfo::MemHeapUsage; break;
122 default: return Standard_False;
124 return Standard_True;
127 // =======================================================================
128 // function : ToMessageMetric
130 // =======================================================================
131 Standard_Boolean Message::ToMessageMetric (const OSD_MemInfo::Counter theMemInfo, Message_MetricType& theMetric)
135 case OSD_MemInfo::MemPrivate: theMetric = Message_MetricType_MemPrivate; break;
136 case OSD_MemInfo::MemVirtual: theMetric = Message_MetricType_MemVirtual; break;
137 case OSD_MemInfo::MemWorkingSet: theMetric = Message_MetricType_MemWorkingSet; break;
138 case OSD_MemInfo::MemWorkingSetPeak: theMetric = Message_MetricType_MemWorkingSetPeak; break;
139 case OSD_MemInfo::MemSwapUsage: theMetric = Message_MetricType_MemSwapUsage; break;
140 case OSD_MemInfo::MemSwapUsagePeak: theMetric = Message_MetricType_MemSwapUsagePeak; break;
141 case OSD_MemInfo::MemHeapUsage: theMetric = Message_MetricType_MemHeapUsage; break;
142 default: return Standard_False;
144 return Standard_True;