Skip to content

Commit d9a0bb9

Browse files
committed
some minor optimizes in SniperProfiling
1 parent f5f4173 commit d9a0bb9

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

Examples/CoreUsages/options/run-TimerUsage.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
22
"sniper": {
33
"LoadDlls": [ "libSniperProfilingLib.so", "libSniperCoreUsages.so" ],
4-
"LogLevel": 2
4+
"LogLevel": 3
55
},
66
"description": "an example to use profiling",
77
"identifier": "Task/task",
88
"properties": {
99
"EvtMax": 5,
10-
"LogLevel": 2
10+
"LogLevel": 3
1111
},
1212
"services": [
1313
{
1414
"description": "a service for providing some profiles",
15-
"identifier": "SniperProfiling/SniperProfiling"
15+
"identifier": "SniperProfiling/SniperProfiling",
16+
"properties": {
17+
"LogLevel": 2
18+
}
1619
},
1720
{
1821
"description": "a service instance that can be share by all algorithms",

Examples/CoreUsages/options/run-TimerUsage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
if __name__ == "__main__":
55

66
import Sniper
7-
Sniper.setLogLevel(2)
7+
Sniper.setLogLevel(3)
88
task = Sniper.Task("task")
99
task.setDescription("an example to use profiling")
1010
task.setEvtMax(5)
1111

1212
import SniperProfiling
1313
svc1 = task.createSvc("SniperProfiling")
1414
svc1.setDescription("a service for providing some profiles")
15+
svc1.setLogLevel(2)
1516

1617
import SniperCoreUsages
1718
svc2 = task.createSvc("DummySvc/SharedSvc")

SniperUtil/SniperProfiling/src/SniperProfiling.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool sp::EndAlgHandler::handle(Incident &incident)
130130
bool SniperProfiling::initialize()
131131
{
132132
Task* taskPtr = dynamic_cast<Task*>(m_par);
133-
const SniperJSON& taskJson = taskPtr->json();
133+
SniperJSON taskJson = taskPtr->json();
134134
const SniperJSON& algVec = taskJson["algorithms"];
135135

136136
//get event timer
@@ -139,7 +139,7 @@ bool SniperProfiling::initialize()
139139
//get names of algs and store them
140140
for (auto it = algVec.vec_begin(); it != algVec.vec_end(); it++)
141141
{
142-
const std::string& idtf = (*it)["identifier"].get<std::string>();
142+
std::string idtf = (*it)["identifier"].get<std::string>();
143143
const std::string&& algName = idtf.substr(idtf.find('/') + 1, idtf.size());
144144
m_algName.emplace_back(algName);
145145
m_algTimer[algName] = new SniperTimer(algName);
@@ -149,7 +149,7 @@ bool SniperProfiling::initialize()
149149
m_beginEvtHdl = new sp::BeginEvtHandler(m_par, m_evtTimer);
150150
m_beginEvtHdl->regist("BeginEvent");
151151

152-
// //create and regist the handler for EndEvent
152+
//create and regist the handler for EndEvent
153153
m_endEvtHdl = new sp::EndEvtHandler(m_par, m_evtTimer);
154154
m_endEvtHdl->regist("EndEvent");
155155

@@ -161,6 +161,10 @@ bool SniperProfiling::initialize()
161161
m_endAlgHdl = new sp::EndAlgHandler(m_par, m_algTimer);
162162
m_endAlgHdl->regist("EndAlg");
163163

164+
//use the same log level in EndEvent and EndAlg handlers
165+
m_endEvtHdl->setLogLevel(this->logLevel());
166+
m_endAlgHdl->setLogLevel(this->logLevel());
167+
164168
LogInfo << m_description << std::endl;
165169

166170
return true;
@@ -183,36 +187,36 @@ bool SniperProfiling::finalize()
183187
SniperLog::Logger::lock();
184188

185189
//print statical times
186-
*SniperLog::LogStream << "########################## SniperProfiling ##########################\n";
190+
*SniperLog::LogStream << "############################## SniperProfiling ##############################\n";
187191

188192
//print time of events
189193
*SniperLog::LogStream << std::setiosflags(std::ios::fixed|std::ios::showpoint)
190194
<< std::setprecision(5)
191-
<< std::setw(15) << std::left << "Name"
192-
<< std::setw(15) << "Num of calls"
195+
<< std::setw(25) << std::left << "Name"
196+
<< std::setw(12) << "Count"
193197
<< std::setw(15) << "Total(ms)"
194-
<< std::setw(15) << "Mean(ms)"
195-
<< std::setw(15) << "RMS(ms)"
198+
<< std::setw(13) << "Mean(ms)"
199+
<< std::setw(13) << "RMS(ms)"
196200
<< std::endl;
197201

198202
//print time of algs
199203
for (const auto& it : m_algName)
200204
{
201-
*SniperLog::LogStream << std::setw(15) << std::left << it
202-
<< std::setw(15) << (m_algTimer[it])->number_of_measurements()
205+
*SniperLog::LogStream << std::setw(25) << std::left << it
206+
<< std::setw(12) << (m_algTimer[it])->number_of_measurements()
203207
<< std::setw(15) << (m_algTimer[it])->number_of_measurements() * (m_algTimer[it])->mean()
204-
<< std::setw(15) << (m_algTimer[it])->mean()
205-
<< std::setw(15) << (m_algTimer[it])->rms()
208+
<< std::setw(13) << (m_algTimer[it])->mean()
209+
<< std::setw(13) << (m_algTimer[it])->rms()
206210
<< std::endl;
207211
}
208212

209-
*SniperLog::LogStream << std::setw(15) << std::left << "event"
210-
<< std::setw(15) << m_evtTimer->number_of_measurements()
213+
*SniperLog::LogStream << std::left << "Sum of " << std::setw(18) << getParent()->objName()
214+
<< std::setw(12) << m_evtTimer->number_of_measurements()
211215
<< std::setw(15) << m_evtTimer->number_of_measurements() * m_evtTimer->mean()
212-
<< std::setw(15) << m_evtTimer->mean()
213-
<< std::setw(15) << m_evtTimer->rms()
216+
<< std::setw(13) << m_evtTimer->mean()
217+
<< std::setw(13) << m_evtTimer->rms()
214218
<< std::endl << std::defaultfloat;
215-
*SniperLog::LogStream << "#####################################################################\n";
219+
*SniperLog::LogStream << "#############################################################################\n";
216220

217221
// release the lock for logs
218222
SniperLog::Logger::unlock();
@@ -223,4 +227,4 @@ bool SniperProfiling::finalize()
223227

224228
LogInfo << "finalized successfully" << std::endl;
225229
return true;
226-
}
230+
}

0 commit comments

Comments
 (0)