Version: 8.3.0
chrono.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef _CHRONO_HXX_
21 #define _CHRONO_HXX_
22 
23 #include "YACSBasesExport.hxx"
24 
25 #include <vector>
26 #include <string>
27 #include <iostream>
28 #include <ctime>
29 #ifdef WIN32
30 #else
31 #include <sys/time.h>
32 #endif
33 
34 typedef struct acnt
35 {
36  char* _ctrNames;
37  int _ctrLines;
38  int _ctrOccur;
39  double _ctrCumul;
40 } cntStruct;
41 
43 {
44 public:
45  static cntStruct *_ctrs;
46  counters(int nb);
47  ~counters();
48  void stats();
49 protected:
50  int _nbChrono;
51 };
52 
54 {
55 public:
56  salome_chrono(int i);
57  ~salome_chrono();
58  void stop();
59 protected:
60  bool _run;
61  int _ctr;
62  clock_t _start, _end;
63 };
64 
65 #ifndef START_TIMING
66 static long tcount=0;
67 static long cumul;
68 #ifdef WIN32
69 static time_t tv;
70 #else
71 static timeval tv;
72 #endif
73 #define START_TIMING gettimeofday(&tv,0);long tt0=tv.tv_usec+tv.tv_sec*1000000;
74 #define END_TIMING(NUMBER) \
75  tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
76  if(tcount==NUMBER){ std::cerr << __FILE__<<":"<<__LINE__<<" temps CPU(mus): "<<cumul<< std::endl; tcount=0 ;cumul=0; }
77 #endif
78 
79 #ifdef CHRONODEF
80 #define CHRONO(i) counters::_ctrs[i]._ctrNames = (char *)__FILE__; \
81  counters::_ctrs[i]._ctrLines = __LINE__; \
82  salome_chrono aChrono##i(i);
83 
84 #define CHRONOSTOP(i) aChrono##i.stop();
85 
86 #else // CHRONODEF
87 
88 #define CHRONO(i)
89 #define CHRONOSTOP(i)
90 
91 #endif // CHRONODEF
92 
93 #endif // _CHRONO_HXX_