]>
Commit | Line | Data |
---|---|---|
b765ad15 | 1 | // $Id$ |
2 | ||
3 | //************************************************************************** | |
4 | //* This file is property of and copyright by the ALICE HLT Project * | |
5 | //* ALICE Experiment at CERN, All rights reserved. * | |
6 | //* * | |
7 | //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
8 | //* for The ALICE HLT Project. * | |
9 | //* * | |
10 | //* Permission to use, copy, modify and distribute this software and its * | |
11 | //* documentation strictly for non-commercial purposes is hereby granted * | |
12 | //* without fee, provided that the above copyright notice appears in all * | |
13 | //* copies and that both the copyright notice and this permission notice * | |
14 | //* appear in the supporting documentation. The authors make no claims * | |
15 | //* about the suitability of this software for any purpose. It is * | |
16 | //* provided "as is" without express or implied warranty. * | |
17 | //************************************************************************** | |
18 | ||
19 | /** @file AliHLTCompStatCollector.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Collector component for the component statistics information. | |
23 | */ | |
24 | ||
25 | #include "AliHLTCompStatCollector.h" | |
c7b299f1 | 26 | #include "TFile.h" |
b765ad15 | 27 | #include "TStopwatch.h" |
28 | #include "TH1F.h" | |
29 | #include "TH2F.h" | |
30 | #include "TH2C.h" | |
31 | #include "TTree.h" | |
abb52c8f | 32 | #include "TFolder.h" |
33 | #include "TNamed.h" | |
b765ad15 | 34 | #include "TString.h" |
abb52c8f | 35 | #include <cassert> |
36 | ||
37 | #define HLTSTAT_FOLDER_NAME "HLTstat" | |
38 | #define HLTSTAT_FOLDER_DESC "ALICE HLT component statistics" | |
39 | #define HLTSTAT_ENTRY_PARENT_FOLDER_NAME "parents" | |
40 | #define HLTSTAT_ENTRY_PARENT_FOLDER_DESC "parent components" | |
41 | #define HLTSTAT_ENTRY_PROPS_FOLDER_NAME "props" | |
42 | #define HLTSTAT_ENTRY_PROPS_FOLDER_DESC "component properties" | |
43 | #define HLTSTAT_ENTRY_PROPS_IDOBJ_NAME "id" | |
44 | #define HLTSTAT_ENTRY_PROPS_IDOBJ_DESC "numerical id calculated from chain id" | |
b765ad15 | 45 | |
46 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
47 | ClassImp(AliHLTCompStatCollector) | |
48 | ||
49 | AliHLTCompStatCollector::AliHLTCompStatCollector() | |
50 | : | |
51 | AliHLTProcessor(), | |
52 | fpTimer(NULL), | |
abb52c8f | 53 | fpFolder(NULL), |
b765ad15 | 54 | fpStatTree(NULL), |
55 | fCycleTime(0), | |
56 | fNofSets(0), | |
57 | fArraySize(1000), | |
58 | fPosition(0), | |
59 | fpLevelArray(NULL), | |
60 | fpSpecArray(NULL), | |
61 | fpBlockNoArray(NULL), | |
62 | fpIdArray(NULL), | |
63 | fpTimeArray(NULL), | |
64 | fpCTimeArray(NULL), | |
65 | fpInputBlockCountArray(NULL), | |
66 | fpTotalInputSizeArray(NULL), | |
fce51f62 | 67 | fpNormalizedInputSizeArray(NULL), |
b765ad15 | 68 | fpOutputBlockCountArray(NULL), |
69 | fpTotalOutputSizeArray(NULL) | |
fce51f62 | 70 | , fpInputOutputRatioArray(NULL) |
71 | , fpNormalizedInputOutputRatioArray(NULL) | |
2e3fd14f | 72 | , fpComponentCycleTimeArray(NULL) |
73 | , fpEventTypeArray(NULL) | |
74 | , fpEventCountArray(NULL) | |
63410eb4 | 75 | , fSizeEstimator(1000) |
c7b299f1 | 76 | , fMode(kPublishObjects) |
77 | , fFileName() | |
78 | , fFile(NULL) | |
79 | , fLastTime(time(NULL)) | |
80 | , fPeriod(0) | |
81 | , fEventModulo(0) | |
b765ad15 | 82 | { |
83 | // see header file for class documentation | |
84 | // or | |
85 | // refer to README to build package | |
86 | // or | |
87 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
88 | } | |
89 | ||
90 | AliHLTCompStatCollector::~AliHLTCompStatCollector() | |
91 | { | |
92 | // see header file for class documentation | |
93 | ClearAll(); | |
94 | } | |
95 | ||
96 | void AliHLTCompStatCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
97 | { | |
98 | // see header file for class documentation | |
99 | list.push_back(kAliHLTDataTypeComponentStatistics); | |
100 | } | |
101 | ||
102 | AliHLTComponentDataType AliHLTCompStatCollector::GetOutputDataType() | |
103 | { | |
104 | // see header file for class documentation | |
105 | return kAliHLTMultipleDataType; | |
106 | } | |
107 | ||
108 | int AliHLTCompStatCollector::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
109 | { | |
110 | // see header file for class documentation | |
111 | tgtList.clear(); | |
112 | tgtList.push_back(kAliHLTDataTypeHistogram); | |
113 | tgtList.push_back(kAliHLTDataTypeTTree); | |
114 | return tgtList.size(); | |
115 | } | |
116 | ||
117 | void AliHLTCompStatCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
118 | { | |
119 | // see header file for class documentation | |
63410eb4 | 120 | constBase=fSizeEstimator; |
b765ad15 | 121 | inputMultiplier=100.0; |
122 | } | |
123 | ||
124 | int AliHLTCompStatCollector::DoInit( int argc, const char** argv ) | |
125 | { | |
126 | // see header file for class documentation | |
127 | int iResult=0; | |
128 | TString argument=""; | |
129 | int bMissingParam=0; | |
130 | for (int i=0; i<argc && iResult>=0; i++) { | |
131 | argument=argv[i]; | |
132 | if (argument.IsNull()) continue; | |
133 | ||
c7b299f1 | 134 | // -file |
135 | if (argument.CompareTo("-file")==0) { | |
b765ad15 | 136 | if ((bMissingParam=(++i>=argc))) break; |
c7b299f1 | 137 | fFileName=argv[i]; |
138 | fMode|=kSaveObjects; | |
139 | ||
140 | // -modulo | |
141 | } else if (argument.CompareTo("-modulo")==0) { | |
142 | if ((bMissingParam=(++i>=argc))) break; | |
143 | TString param=argv[i]; | |
b765ad15 | 144 | if (param.IsDigit()) { |
c7b299f1 | 145 | fEventModulo=param.Atoi(); |
b765ad15 | 146 | } else { |
c7b299f1 | 147 | HLTError("expecting number as parameter for option %s", argument.Data()); |
b765ad15 | 148 | iResult=-EINVAL; |
149 | } | |
150 | ||
c7b299f1 | 151 | // -period |
152 | } else if (argument.CompareTo("-period")==0) { | |
153 | if ((bMissingParam=(++i>=argc))) break; | |
154 | TString param=argv[i]; | |
155 | if (param.IsDigit()) { | |
156 | fPeriod=param.Atoi(); | |
157 | } else { | |
158 | HLTError("expecting number as parameter for option %s", argument.Data()); | |
159 | iResult=-EINVAL; | |
160 | } | |
161 | ||
162 | // -publish | |
163 | } else if (argument.CompareTo("-publish")==0) { | |
164 | if ((bMissingParam=(++i>=argc))) break; | |
165 | TString param=argv[i]; | |
166 | if (param.IsDigit()) { | |
167 | if (param.Atoi()==1) fMode|=kPublishObjects; | |
168 | else if (param.Atoi()==0) fMode&=~kPublishObjects; | |
169 | else { | |
170 | HLTError("expecting 0 or 1 as parameter for option %s", argument.Data()); | |
171 | iResult=-EINVAL; | |
172 | } | |
173 | } else { | |
174 | HLTError("expecting number as parameter for option %s", argument.Data()); | |
175 | iResult=-EINVAL; | |
176 | } | |
fce51f62 | 177 | |
178 | // -arraysize | |
179 | } else if (argument.CompareTo("-arraysize")==0) { | |
180 | if ((bMissingParam=(++i>=argc))) break; | |
181 | TString param=argv[i]; | |
182 | if (param.IsDigit()) { | |
183 | fArraySize=param.Atoi(); | |
184 | } else { | |
185 | HLTError("expecting number as parameter for option %s", argument.Data()); | |
186 | iResult=-EINVAL; | |
187 | } | |
188 | ||
b765ad15 | 189 | } else { |
c7b299f1 | 190 | HLTError("unknown argument %s", argument.Data()); |
b765ad15 | 191 | iResult=-EINVAL; |
192 | } | |
193 | } | |
194 | if (bMissingParam) { | |
195 | HLTError("missing parameter for argument %s", argument.Data()); | |
196 | iResult=-EINVAL; | |
197 | } | |
198 | ||
199 | if (iResult>=0) { | |
200 | fpLevelArray=new UInt_t[fArraySize]; | |
201 | fpSpecArray=new UInt_t[fArraySize]; | |
202 | fpBlockNoArray=new UInt_t[fArraySize]; | |
203 | fpIdArray=new UInt_t[fArraySize]; | |
204 | fpTimeArray=new UInt_t[fArraySize]; | |
205 | fpCTimeArray=new UInt_t[fArraySize]; | |
206 | fpInputBlockCountArray=new UInt_t[fArraySize]; | |
207 | fpTotalInputSizeArray=new UInt_t[fArraySize]; | |
fce51f62 | 208 | fpNormalizedInputSizeArray=new UInt_t[fArraySize]; |
b765ad15 | 209 | fpOutputBlockCountArray=new UInt_t[fArraySize]; |
210 | fpTotalOutputSizeArray=new UInt_t[fArraySize]; | |
fce51f62 | 211 | fpInputOutputRatioArray=new UInt_t[fArraySize]; |
212 | fpNormalizedInputOutputRatioArray=new UInt_t[fArraySize]; | |
2e3fd14f | 213 | fpComponentCycleTimeArray=new UInt_t[fArraySize]; |
214 | fpEventTypeArray=new UInt_t[fArraySize]; | |
215 | fpEventCountArray=new UInt_t[fArraySize]; | |
b765ad15 | 216 | |
217 | fpStatTree=new TTree("CompStat", "HLT component statistics"); | |
218 | if (fpStatTree) { | |
219 | fpStatTree->SetDirectory(0); | |
220 | fpStatTree->Branch("cycleTime", &fCycleTime, "cycleTime/F"); | |
221 | fpStatTree->Branch("nofSets", &fNofSets, "nofSets/I"); | |
222 | fpStatTree->Branch("Level", fpLevelArray, "Level[nofSets]/i"); | |
223 | fpStatTree->Branch("Specification", fpSpecArray, "Specification[nofSets]/i"); | |
224 | fpStatTree->Branch("BlockNo", fpBlockNoArray, "BlockNo[nofSets]/i"); | |
225 | fpStatTree->Branch("Id", fpIdArray, "Id[nofSets]/i"); | |
226 | fpStatTree->Branch("Time", fpTimeArray, "Time[nofSets]/i"); | |
227 | fpStatTree->Branch("CTime", fpCTimeArray, "CTime[nofSets]/i"); | |
228 | fpStatTree->Branch("InputBlockCount", fpInputBlockCountArray, "InputBlockCount[nofSets]/i"); | |
229 | fpStatTree->Branch("TotalInputSize", fpTotalInputSizeArray, "TotalInputSize[nofSets]/i"); | |
fce51f62 | 230 | fpStatTree->Branch("NormalizedInputSize", fpNormalizedInputSizeArray, "NormalizedInputSize[nofSets]/i"); |
b765ad15 | 231 | fpStatTree->Branch("OutputBlockCount", fpOutputBlockCountArray, "OutputBlockCount[nofSets]/i"); |
232 | fpStatTree->Branch("TotalOutputSize", fpTotalOutputSizeArray, "TotalOutputSize[nofSets]/i"); | |
fce51f62 | 233 | fpStatTree->Branch("InputOutputRatio", fpInputOutputRatioArray, "InputOutputRatio[nofSets]/i"); |
234 | fpStatTree->Branch("NormalizedInputOutputRatio", fpNormalizedInputOutputRatioArray, "NormalizedInputOutputRatio[nofSets]/i"); | |
2e3fd14f | 235 | fpStatTree->Branch("ComponentCycleTime",fpComponentCycleTimeArray, "ComponentCycleTime[nofSets]/i"); |
236 | fpStatTree->Branch("EventType",fpEventTypeArray, "EventType[nofSets]/i"); | |
237 | fpStatTree->Branch("EventCount",fpEventCountArray, "EventCount[nofSets]/i"); | |
b765ad15 | 238 | } |
239 | } | |
c7b299f1 | 240 | |
241 | if (!fFileName.empty()) { | |
242 | fFile=new TFile(fFileName.c_str(), "RECREATE"); | |
243 | } | |
b765ad15 | 244 | return iResult; |
245 | } | |
246 | ||
247 | int AliHLTCompStatCollector::DoDeinit( ) | |
248 | { | |
249 | // see header file for class documentation | |
250 | ClearAll(); | |
251 | ||
c7b299f1 | 252 | if (fFile) { |
253 | fFile->Close(); | |
254 | delete fFile; | |
255 | fFile=NULL; | |
256 | } | |
b765ad15 | 257 | return 0; |
258 | } | |
259 | ||
260 | int AliHLTCompStatCollector::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) | |
261 | { | |
262 | // see header file for class documentation | |
263 | int iResult=0; | |
264 | ||
abb52c8f | 265 | AliHLTUInt32_t eventType=gkAliEventTypeUnknown; |
266 | IsDataEvent(&eventType); | |
267 | ||
b765ad15 | 268 | ResetFillingVariables(); |
269 | if (fpTimer) { | |
270 | fCycleTime=fpTimer->RealTime()*1000000; | |
271 | } | |
272 | ||
abb52c8f | 273 | bool bEmbeddedTree=false; |
274 | bool bFolderCreated=false; | |
9d5f00ad | 275 | if ((bFolderCreated=(fpFolder==NULL))) { |
abb52c8f | 276 | fpFolder=new TFolder(HLTSTAT_FOLDER_NAME, HLTSTAT_FOLDER_DESC); |
277 | if (bEmbeddedTree) fpFolder->Add(fpStatTree); | |
278 | } | |
279 | if (!fpFolder) return -ENOMEM; | |
280 | vector<TFolder*> newFolders; | |
281 | ||
282 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeComponentTable); | |
283 | pBlock && iResult>=0; | |
284 | pBlock=GetNextInputBlock()) { | |
285 | string chainId, compId, compArgs; | |
286 | vector<AliHLTUInt32_t> parents; | |
287 | iResult=ExtractComponentTableEntry((const AliHLTUInt8_t*)pBlock->fPtr, pBlock->fSize, | |
288 | chainId, compId, compArgs, | |
289 | parents); | |
290 | if (iResult>0) { | |
291 | HLTDebug("%s(%s) 0x%08x", chainId.c_str(), compId.c_str(), pBlock->fSpecification); | |
292 | TObject* pObj=NULL; | |
293 | TFolder* pEntry=NULL; | |
294 | if ((pObj=fpFolder->FindObjectAny(chainId.c_str()))!=NULL && | |
295 | (pEntry=dynamic_cast<TFolder*>(pObj))!=NULL ) { | |
296 | ||
297 | } else if (pObj) { | |
298 | HLTError("entry %s exists in folder, but is not a sub-folder", chainId.c_str()); | |
299 | } else if (chainId.size()>0) { | |
300 | pEntry=new TFolder(chainId.c_str(), chainId.c_str()); | |
301 | if (pEntry) { | |
302 | pEntry->SetOwner(); | |
303 | TFolder* pProps=pEntry->AddFolder(HLTSTAT_ENTRY_PROPS_FOLDER_NAME, HLTSTAT_ENTRY_PROPS_FOLDER_DESC); | |
304 | if (pProps) { | |
305 | pProps->Add(new TObjString(compId.c_str())); | |
306 | if (!compArgs.empty()) | |
307 | pProps->Add(new TObjString(compArgs.c_str())); | |
308 | TNamed* pCRC=new TNamed(HLTSTAT_ENTRY_PROPS_IDOBJ_NAME, HLTSTAT_ENTRY_PROPS_IDOBJ_DESC); | |
309 | if (pCRC) { | |
310 | pCRC->SetUniqueID(pBlock->fSpecification); | |
311 | pProps->Add(pCRC); | |
312 | } | |
313 | } | |
314 | TFolder* pParents=pEntry->AddFolder(HLTSTAT_ENTRY_PARENT_FOLDER_NAME, HLTSTAT_ENTRY_PARENT_FOLDER_DESC); | |
315 | if (pParents) { | |
316 | for (vector<AliHLTUInt32_t>::iterator parent=parents.begin(); | |
317 | parent!=parents.end(); parent++) { | |
318 | TString name; name.Form("0x%08x", *parent); | |
319 | pParents->Add(new TObjString(name)); | |
320 | } | |
321 | } | |
322 | if (parents.size()==0) { | |
323 | newFolders.push_back(pEntry); | |
324 | } else { | |
325 | vector<TFolder*>::iterator iter=newFolders.begin(); | |
326 | vector<AliHLTUInt32_t>::iterator parent=parents.begin(); | |
327 | while (iter!=newFolders.end() && parent!=parents.end()) { | |
328 | TObject* idobj=(*iter)->FindObjectAny(HLTSTAT_ENTRY_PROPS_IDOBJ_NAME); | |
329 | AliHLTUInt32_t crcid=0; | |
330 | if (idobj) crcid=idobj->GetUniqueID(); | |
331 | HLTDebug("check: %s 0x%08x", (*iter)->GetName(), crcid); | |
332 | if (idobj && crcid==*parent) break; | |
333 | if ((++parent!=parents.end())) continue; | |
334 | parent=parents.begin(); | |
335 | iter++; | |
336 | } | |
337 | newFolders.insert(iter,pEntry); | |
338 | } | |
339 | } | |
340 | } else { | |
341 | HLTError("missing chain id for table entry 0x%08x (%p %d), skipping ...", pBlock->fSpecification, pBlock->fPtr, pBlock->fSize); | |
342 | } | |
343 | } else if (iResult!=0) { | |
344 | HLTError("extraction of table entry 0x%08x (%p %d) failed with %d", pBlock->fSpecification, pBlock->fPtr, pBlock->fSize, iResult); | |
345 | } | |
346 | iResult=0; | |
347 | } | |
348 | ||
349 | if (newFolders.size()>0) { | |
350 | vector<TFolder*> revert; | |
351 | vector<TFolder*>::iterator iter=newFolders.begin(); | |
352 | while (iter!=newFolders.end()) { | |
353 | revert.insert(revert.begin(), *iter); | |
354 | HLTDebug("%s", (*iter)->GetName()); | |
355 | iter++; | |
356 | } | |
357 | newFolders.empty(); | |
358 | newFolders.assign(revert.begin(), revert.end()); | |
359 | ||
360 | vector<TFolder*>::iterator publisher=newFolders.begin(); | |
361 | while (publisher!=newFolders.end()) { | |
362 | bool bRemove=false; | |
363 | HLTDebug("checking %s for parents", (*publisher)->GetName()); | |
364 | TFolder* propsFolder=dynamic_cast<TFolder*>((*publisher)->FindObject(HLTSTAT_ENTRY_PROPS_FOLDER_NAME)); | |
365 | assert(propsFolder); | |
366 | TObject* idobj=NULL; | |
367 | if (propsFolder) idobj=propsFolder->FindObject(HLTSTAT_ENTRY_PROPS_IDOBJ_NAME); | |
368 | assert(idobj); | |
369 | AliHLTUInt32_t crcid=idobj->GetUniqueID(); | |
370 | TString idstr; idstr.Form("0x%08x", crcid); | |
371 | if (idobj) { | |
372 | for (vector<TFolder*>::iterator consumer=publisher+1; | |
373 | consumer!=newFolders.end(); consumer++) { | |
374 | HLTDebug(" checking %s", (*consumer)->GetName()); | |
375 | TFolder* parentFolder=dynamic_cast<TFolder*>((*consumer)->FindObject(HLTSTAT_ENTRY_PARENT_FOLDER_NAME)); | |
376 | assert(parentFolder); | |
377 | if (parentFolder) { | |
378 | TIter entries(parentFolder->GetListOfFolders()); | |
379 | while (TObject* entry=entries.Next()) | |
460c4045 | 380 | if (entry) { |
381 | Bool_t foo; foo=kTRUE;// only to avoid warning in non-debug compile | |
382 | HLTDebug(" searching %s in %s: %s", idstr.Data(), (*consumer)->GetName(), entry->GetName()); | |
383 | } | |
abb52c8f | 384 | TObject* parent=parentFolder->FindObjectAny(idstr); |
385 | if (parent) { | |
386 | parentFolder->Add(*publisher); | |
387 | parentFolder->Remove(parent); | |
388 | bRemove=true; | |
389 | } | |
390 | } | |
391 | } | |
392 | } | |
393 | if (bRemove) publisher=newFolders.erase(publisher); | |
394 | else publisher++; | |
395 | } | |
396 | ||
397 | for (publisher=newFolders.begin(); | |
398 | publisher!=newFolders.end(); publisher++) { | |
399 | RemoveRecurrence(*publisher); | |
400 | fpFolder->Add(*publisher); | |
401 | } | |
402 | } | |
403 | ||
b765ad15 | 404 | int blockNo=0; |
405 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeComponentStatistics); | |
406 | pBlock && iResult>=0; | |
407 | pBlock=GetNextInputBlock(), blockNo++) { | |
408 | unsigned int current=fPosition; | |
2e3fd14f | 409 | iResult=FillVariablesSorted(pBlock->fPtr, pBlock->fSize, eventType); |
b765ad15 | 410 | for (; current<fPosition; current++) { |
411 | fpSpecArray[current]=pBlock->fSpecification; | |
412 | fpBlockNoArray[current]=blockNo; | |
413 | } | |
587c9cf9 | 414 | // indicate availability of component statistic block |
415 | iResult=1; | |
b765ad15 | 416 | } |
417 | ||
4e5a2a53 | 418 | int totalOutputSize=0; |
2e3fd14f | 419 | if (iResult>0 && eventType) { |
b765ad15 | 420 | fNofSets=fPosition; |
421 | fpStatTree->Fill(); | |
b765ad15 | 422 | |
587c9cf9 | 423 | // init the timer for the next cycle |
424 | if (!fpTimer) fpTimer=new TStopwatch; | |
425 | if (fpTimer) { | |
426 | fpTimer->Reset(); | |
427 | fpTimer->Start(); | |
428 | } | |
b765ad15 | 429 | } |
430 | ||
c7b299f1 | 431 | if (eventType==gkAliEventTypeEndOfRun || |
432 | (iResult>=0 && CheckPeriod())) { | |
433 | ||
434 | // publish objects to component output | |
435 | if ((fMode&kPublishObjects)!=0) { | |
436 | if (!bEmbeddedTree) { | |
437 | iResult=PushBack(fpStatTree, kAliHLTDataTypeTTree|kAliHLTDataOriginOut); | |
438 | totalOutputSize+=GetLastObjectSize(); | |
439 | } | |
440 | iResult=PushBack(fpFolder, kAliHLTDataTypeTObject|kAliHLTDataOriginOut); | |
441 | totalOutputSize+=GetLastObjectSize(); | |
442 | } | |
443 | ||
444 | // save objects to file | |
445 | if ((fMode&kSaveObjects)!=0 && fFile!=NULL) { | |
446 | HLTDebug("saving objects to file %s", fFileName.c_str()); | |
447 | fFile->cd(); | |
448 | if (!bEmbeddedTree) { | |
449 | fpStatTree->Write("", TObject::kOverwrite); | |
450 | } | |
451 | fpFolder->Write("", TObject::kOverwrite); | |
452 | } | |
4e5a2a53 | 453 | } |
c7b299f1 | 454 | |
4e5a2a53 | 455 | if (iResult==-ENOSPC) { |
456 | fSizeEstimator+=totalOutputSize; | |
abb52c8f | 457 | } |
458 | ||
459 | if (iResult>0) iResult=0; | |
b765ad15 | 460 | return iResult; |
461 | } | |
462 | ||
463 | void AliHLTCompStatCollector::ResetFillingVariables() | |
464 | { | |
465 | // see header file for class documentation | |
466 | fCycleTime=0; | |
467 | fNofSets=0; | |
468 | fPosition=0; | |
469 | memset(fpLevelArray, 0, sizeof(UInt_t)*fArraySize); | |
470 | memset(fpSpecArray, 0, sizeof(UInt_t)*fArraySize); | |
471 | memset(fpBlockNoArray, 0, sizeof(UInt_t)*fArraySize); | |
472 | memset(fpIdArray, 0, sizeof(UInt_t)*fArraySize); | |
473 | memset(fpTimeArray, 0, sizeof(UInt_t)*fArraySize); | |
474 | memset(fpCTimeArray, 0, sizeof(UInt_t)*fArraySize); | |
475 | memset(fpInputBlockCountArray, 0, sizeof(UInt_t)*fArraySize); | |
476 | memset(fpTotalInputSizeArray, 0, sizeof(UInt_t)*fArraySize); | |
fce51f62 | 477 | memset(fpNormalizedInputSizeArray, 0, sizeof(UInt_t)*fArraySize); |
b765ad15 | 478 | memset(fpOutputBlockCountArray, 0, sizeof(UInt_t)*fArraySize); |
479 | memset(fpTotalOutputSizeArray, 0, sizeof(UInt_t)*fArraySize); | |
fce51f62 | 480 | memset(fpInputOutputRatioArray, 0, sizeof(UInt_t)*fArraySize); |
481 | memset(fpNormalizedInputOutputRatioArray, 0, sizeof(UInt_t)*fArraySize); | |
2e3fd14f | 482 | memset(fpComponentCycleTimeArray, 0, sizeof(UInt_t)*fArraySize); |
483 | memset(fpEventTypeArray, 0, sizeof(UInt_t)*fArraySize); | |
484 | memset(fpEventCountArray, 0, sizeof(UInt_t)*fArraySize); | |
b765ad15 | 485 | } |
486 | ||
2e3fd14f | 487 | int AliHLTCompStatCollector::FillVariablesSorted(void* ptr, int size, AliHLTUInt32_t eventType) |
b765ad15 | 488 | { |
489 | // see header file for class documentation | |
490 | int iResult=0; | |
491 | if (size%sizeof(AliHLTComponentStatistics)) { | |
2e3fd14f | 492 | // older or invalid structure |
b765ad15 | 493 | HLTError("data block is not aligned to the size of the AliHLTComponentStatistics struct"); |
494 | return -EINVAL; | |
495 | } | |
2e3fd14f | 496 | |
b765ad15 | 497 | AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(ptr); |
498 | UInt_t nofStats=size/sizeof(AliHLTComponentStatistics); | |
499 | vector<int> indexList; | |
500 | UInt_t i=0; | |
501 | for (i=0; i<nofStats; i++) { | |
502 | vector<int>::iterator element=indexList.begin(); | |
503 | for (; element!=indexList.end(); element++) { | |
504 | if (pStat[i].fLevel>pStat[*element].fLevel) { | |
505 | break; | |
506 | } | |
507 | } | |
508 | indexList.insert(element, i); | |
509 | } | |
510 | ||
511 | i=fPosition; | |
512 | for (vector<int>::iterator element=indexList.begin(); | |
513 | element!=indexList.end(); | |
514 | element++, i++) { | |
515 | if (i<fArraySize) { | |
516 | fpLevelArray[i]=pStat[*element].fLevel; | |
517 | fpIdArray[i]=pStat[*element].fId; | |
518 | fpTimeArray[i]=pStat[*element].fTime; | |
519 | fpCTimeArray[i]=pStat[*element].fCTime; | |
520 | fpInputBlockCountArray[i]=pStat[*element].fInputBlockCount; | |
521 | fpTotalInputSizeArray[i]=pStat[*element].fTotalInputSize; | |
fce51f62 | 522 | fpNormalizedInputSizeArray[i]=pStat[*element].fTotalInputSize; |
523 | if (pStat[*element].fInputBlockCount>0) | |
524 | fpNormalizedInputSizeArray[i]/=pStat[*element].fInputBlockCount; | |
b765ad15 | 525 | fpOutputBlockCountArray[i]=pStat[*element].fOutputBlockCount; |
526 | fpTotalOutputSizeArray[i]=pStat[*element].fTotalOutputSize; | |
fce51f62 | 527 | if (pStat[*element].fTotalOutputSize>0) |
528 | fpInputOutputRatioArray[i]=pStat[*element].fTotalInputSize/pStat[*element].fTotalOutputSize; | |
529 | if (pStat[*element].fInputBlockCount>0) | |
530 | fpNormalizedInputOutputRatioArray[i]=fpInputOutputRatioArray[i]*pStat[*element].fOutputBlockCount/pStat[*element].fInputBlockCount; | |
2e3fd14f | 531 | fpComponentCycleTimeArray[i]=pStat[*element].fComponentCycleTime; |
532 | fpEventTypeArray[i]=eventType; | |
533 | fpEventCountArray[i]=GetEventCount(); | |
c7b299f1 | 534 | } else { |
535 | // TODO: dynamically grow arrays with placement new | |
b765ad15 | 536 | } |
537 | } | |
538 | ||
539 | if (i>=fArraySize) { | |
540 | HLTWarning("too little space in branch variables to fill %d statistics blocks, available %d at position %d", i, fArraySize, fPosition); | |
541 | fPosition=fArraySize; | |
542 | } else { | |
543 | fPosition=i; | |
544 | } | |
545 | ||
546 | return iResult; | |
547 | } | |
548 | ||
549 | void AliHLTCompStatCollector::ClearAll() | |
550 | { | |
abb52c8f | 551 | // see header file for class documentation |
b765ad15 | 552 | if (fpTimer) delete fpTimer; fpTimer=NULL; |
abb52c8f | 553 | if (fpFolder) delete fpFolder; fpFolder=NULL; |
b765ad15 | 554 | if (fpStatTree) delete fpStatTree; fpStatTree=NULL; |
555 | if (fpLevelArray) delete fpLevelArray; fpLevelArray=NULL; | |
556 | if (fpSpecArray) delete fpSpecArray; fpSpecArray=NULL; | |
557 | if (fpBlockNoArray) delete fpBlockNoArray; fpBlockNoArray=NULL; | |
558 | if (fpIdArray) delete fpIdArray; fpIdArray=NULL; | |
559 | if (fpTimeArray) delete fpTimeArray; fpTimeArray=NULL; | |
560 | if (fpCTimeArray) delete fpCTimeArray; fpCTimeArray=NULL; | |
561 | if (fpInputBlockCountArray) delete fpInputBlockCountArray; fpInputBlockCountArray=NULL; | |
562 | if (fpTotalInputSizeArray) delete fpTotalInputSizeArray; fpTotalInputSizeArray=NULL; | |
fce51f62 | 563 | if (fpNormalizedInputSizeArray) delete fpNormalizedInputSizeArray; fpNormalizedInputSizeArray=NULL; |
b765ad15 | 564 | if (fpOutputBlockCountArray) delete fpOutputBlockCountArray; fpOutputBlockCountArray=NULL; |
565 | if (fpTotalOutputSizeArray) delete fpTotalOutputSizeArray; fpTotalOutputSizeArray=NULL; | |
fce51f62 | 566 | if (fpInputOutputRatioArray) delete fpInputOutputRatioArray; fpInputOutputRatioArray=NULL; |
567 | if (fpNormalizedInputOutputRatioArray) delete fpNormalizedInputOutputRatioArray; fpNormalizedInputOutputRatioArray=NULL; | |
2e3fd14f | 568 | if (fpComponentCycleTimeArray) delete fpComponentCycleTimeArray; fpComponentCycleTimeArray=NULL; |
569 | if (fpEventTypeArray) delete fpEventTypeArray; fpEventTypeArray=NULL; | |
570 | if (fpEventCountArray) delete fpEventCountArray; fpEventCountArray=NULL; | |
b765ad15 | 571 | } |
abb52c8f | 572 | |
573 | int AliHLTCompStatCollector::RemoveRecurrence(TFolder* pRoot) const | |
574 | { | |
575 | // see header file for class documentation | |
576 | int iResult=0; | |
577 | if (!pRoot) return -EINVAL; | |
578 | TFolder* parentFolder=dynamic_cast<TFolder*>(pRoot->FindObject(HLTSTAT_ENTRY_PARENT_FOLDER_NAME)); | |
579 | assert(parentFolder); | |
580 | vector<TFolder*> listRemove; | |
581 | if (parentFolder) { | |
582 | TIter entries(parentFolder->GetListOfFolders()); | |
583 | TFolder* entry=NULL; | |
584 | TObject* obj=NULL; | |
585 | while ((obj=entries.Next())!=NULL && (entry=dynamic_cast<TFolder*>(obj))!=NULL) { | |
586 | TString name=entry->GetName(); | |
587 | HLTDebug("checking %s for recurrence", name.Data()); | |
588 | TIter tokens(parentFolder->GetListOfFolders()); | |
589 | TFolder* token=NULL; | |
590 | while ((obj=tokens.Next())!=NULL && (token=dynamic_cast<TFolder*>(obj))!=NULL) { | |
591 | if (name.CompareTo(token->GetName())==0) continue; | |
592 | if ((obj=token->FindObjectAny(name))!=NULL) { | |
593 | listRemove.push_back(entry); | |
594 | HLTDebug("found recurrence in %s", token->GetName()); | |
595 | break; | |
596 | } else { | |
597 | HLTDebug("no recurrence found in %s", token->GetName()); | |
598 | } | |
599 | } | |
600 | RemoveRecurrence(entry); | |
601 | } | |
602 | for (vector<TFolder*>::iterator removeElement=listRemove.begin(); | |
603 | removeElement!=listRemove.end(); removeElement++) { | |
604 | parentFolder->Remove(*removeElement); | |
605 | } | |
606 | } | |
607 | ||
608 | return iResult; | |
609 | } | |
c7b299f1 | 610 | |
611 | bool AliHLTCompStatCollector::CheckPeriod(bool bUpdate) | |
612 | { | |
613 | // see header file for class documentation | |
614 | bool result=true; | |
615 | if (fEventModulo>0) { | |
616 | if ((result=((GetEventCount()+1)%fEventModulo)==0)) { | |
617 | return true; | |
618 | } | |
619 | } | |
620 | if (fPeriod>0) { | |
621 | if ((result=((difftime(time(NULL), fLastTime)>(double)fPeriod))) && | |
622 | bUpdate) { | |
623 | fLastTime=time(NULL); | |
624 | } | |
625 | } | |
626 | return result; | |
627 | } |