Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/general/profiler.cpp
3206 views
1
/**************************************************************************/
2
/* File: profiler.cpp */
3
/* Author: Joachim Schoeberl */
4
/* Date: 19. Apr. 2002 */
5
/**************************************************************************/
6
7
8
#include <myadt.hpp>
9
#define PROF_ACTIVE 0
10
11
namespace netgen
12
{
13
//using namespace netgen;
14
15
long int NgProfiler::tottimes[SIZE];
16
long int NgProfiler::starttimes[SIZE];
17
long int NgProfiler::counts[SIZE];
18
string NgProfiler::names[SIZE];
19
int NgProfiler::usedcounter[SIZE];
20
21
22
NgProfiler :: NgProfiler()
23
{
24
for (int i = 0; i < SIZE; i++)
25
{
26
tottimes[i] = 0;
27
usedcounter[i] = 0;
28
}
29
30
total_timer = CreateTimer ("total CPU time");
31
StartTimer (total_timer);
32
}
33
34
NgProfiler :: ~NgProfiler()
35
{
36
StopTimer (total_timer);
37
38
//ofstream prof;
39
//prof.open("ng.prof");
40
41
// ofstream-constructor may be called after STL-stuff is destructed,
42
// which leads to an "order of destruction"-problem,
43
// thus we use the C-variant:
44
45
#if PROF_ACTIVE
46
char filename[100];
47
#ifdef PARALLEL
48
sprintf (filename, "netgen.prof.%d", id);
49
#else
50
sprintf (filename, "netgen.prof");
51
#endif
52
FILE *prof = fopen(filename,"w");
53
Print (prof);
54
fclose(prof);
55
#endif
56
}
57
58
59
// void NgProfiler :: Print (ostream & prof)
60
// {
61
// for (int i = 0; i < SIZE; i++)
62
// if (counts[i] != 0 || usedcounter[i] != 0)
63
// {
64
// prof.setf (ios::fixed, ios::floatfield);
65
// prof.setf (ios::showpoint);
66
67
// prof // << "job " << setw(3) << i
68
// << "calls " << setw(8) << counts[i]
69
// << ", time " << setprecision(2) << setw(6) << double(tottimes[i]) / CLOCKS_PER_SEC << " sec";
70
71
// if (usedcounter[i])
72
// prof << " " << names[i];
73
// else
74
// prof << " " << i;
75
76
// prof << endl;
77
// }
78
// }
79
80
81
void NgProfiler :: Print (FILE * prof)
82
{
83
#if PROF_ACTIVE
84
for (int i = 0; i < SIZE; i++)
85
if (counts[i] != 0 || usedcounter[i] != 0)
86
{
87
fprintf(prof,"calls %8i, time %6.2f sec",counts[i],double(tottimes[i]) / CLOCKS_PER_SEC);
88
if(usedcounter[i])
89
fprintf(prof," %s",names[i].c_str());
90
else
91
fprintf(prof," %i",i);
92
fprintf(prof,"\n");
93
}
94
#endif
95
}
96
97
int NgProfiler :: CreateTimer (const string & name)
98
{
99
for (int i = SIZE-1; i > 0; i--)
100
if(names[i] == name)
101
return i;
102
103
for (int i = SIZE-1; i > 0; i--)
104
if (!usedcounter[i])
105
{
106
usedcounter[i] = 1;
107
names[i] = name;
108
return i;
109
}
110
return -1;
111
}
112
113
114
NgProfiler prof;
115
}
116
117