Version: 9.16.0
chrono.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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
34typedef struct acnt
35{
36 char* _ctrNames;
39 double _ctrCumul;
41
43{
44public:
46 counters(int nb);
47 ~counters();
48 void stats();
49protected:
51};
52
54{
55public:
56 salome_chrono(int i);
58 void stop();
59protected:
60 bool _run;
61 int _ctr;
62 clock_t _start, _end;
63};
64
65#ifndef START_TIMING
66static long tcount=0;
67static long cumul;
68#ifdef WIN32
69static time_t tv;
70#else
71static 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_
#define YACSBASES_EXPORT
struct acnt cntStruct
static long cumul
Definition: chrono.hxx:67
static timeval tv
Definition: chrono.hxx:71
static long tcount
Definition: chrono.hxx:66
static cntStruct * _ctrs
Definition: chrono.hxx:45
int _nbChrono
Definition: chrono.hxx:50
clock_t _end
Definition: chrono.hxx:62
Definition: chrono.hxx:35
int _ctrLines
Definition: chrono.hxx:37
double _ctrCumul
Definition: chrono.hxx:39
int _ctrOccur
Definition: chrono.hxx:38
char * _ctrNames
Definition: chrono.hxx:36