ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/mdProfile.cpp
Revision: 884
Committed: Thu Dec 18 21:47:51 2003 UTC (20 years, 6 months ago) by mmeineke
File size: 2896 byte(s)
Log Message:
added some profile functionality

File Contents

# Content
1 #include <sys/time.h>
2
3 #include "mdProfile.hpp"
4
5 namespace mdProfileSpace {
6
7 class ProfileString{
8 char myName[MAX_PROFILE_NAMELENGTH];
9 };
10
11 ProfileString theNames[N_PROFILES];
12
13 struct timeval startTime[N_PROFILES];
14 struct timeval endTime[N_PROFILES];
15
16 double accumTime[N_PROFILES];
17
18 #ifdef IS_MPI
19 double globalTime[N_PROFILES];
20 #endif //is_mpi
21
22 }
23
24
25 using namespace mdProfileSpace;
26
27
28 void initProfile( void ){
29
30 int i;
31
32 for( i=0;i<N_PROFILES;i++ ){
33
34 accumTime[i] = 0.0;
35
36 #ifdef IS_MPI
37 globalTime[i] = 0.0;
38 #endif //is_mpi
39 }
40
41 strncpy( theNames[pro1].myName, "unamed1", MAX_PROFILE_NAMELENGTH );
42 strncpy( theNames[pro2].myName, "unamed2", MAX_PROFILE_NAMELENGTH );
43 strncpy( theNames[pro3].myName, "unamed3", MAX_PROFILE_NAMELENGTH );
44 strncpy( theNames[pro4].myName, "unamed4", MAX_PROFILE_NAMELENGTH );
45 strncpy( theNames[pro5].myName, "unamed5", MAX_PROFILE_NAMELENGTH );
46 strncpy( theNames[pro6].myName, "unamed6", MAX_PROFILE_NAMELENGTH );
47 strncpy( theNames[pro7].myName, "unamed7", MAX_PROFILE_NAMELENGTH );
48 strncpy( theNames[pro8].myName, "unamed8", MAX_PROFILE_NAMELENGTH );
49 }
50
51
52 void startProfile( proNames theProfile ){
53 struct timezone tz;
54
55 gettimeofday( &startTime[theProfile], &tz );
56 }
57
58 void endProfile( proNames theProfile ){
59 struct timezone tz;
60 double startVal, endVal;
61
62 gettimeofday( &endTime[theProfile], &tz );
63
64 startVal = (double)startTime[theProfile].tv_sec
65 + (double)startTime[theProfile].tv_usec / 1000.0;
66
67 endVal = (double)endTime[theProfile].tv_sec
68 + (double)endTime[theProfile].tv_usec / 1000.0;
69
70 accumTime[theProfile] += endVal - startVal;
71 }
72
73
74 void writeProfiles( void ){
75
76 int i;
77 double totTime;
78 double percentTime[N_PROFILES];
79 int days, hours, minutes, secs, usecs;
80 double donkey;
81
82 #ifndef IS_MPI // single processor version
83
84 totTime = 0.0;
85 for(i=0;i<N_PROFILES;i++)
86 totTime += accumTime[i];
87
88 for(i=0;i<N_PROFILES;i++)
89 percentTime[i] = accumTime[i] / totalTime;
90
91 fprintf(stdout,
92 " Time Spent Percent Time Name\n"
93 "-------------- ---------------- -----------------------------------------\n"
94 );
95
96 for(i=0;i<N_PROFILES;i++){
97 fprintf(stdout,
98 " %12G %14G %40s\n",
99 accumTime[i],
100 percentTime[i],
101 theNames[i].myName );
102 }
103
104 days = (int)floor( totalTime / 86400 );
105 donkey = totalTime - 86400 * days;
106
107 hours = (int)floor( donkey / 3600 );
108 donkey -= hours * 3600;
109
110 minutes = (int)floor( donkey / 60 );
111 donkey -= minutes * 60;
112
113 secs = (int)donkey;
114 usecs = (int)( (donkey - secs) * 1000 );
115
116 fprintf( stdout,
117 "----------------------------------------------------------------------------\n"
118 " Total Time = %03d:%02d:%02d:%02d.%03d ( %G sec )\n",
119 days,
120 hours,
121 minutes,
122 secs,
123 usecs,
124 totalTime );
125
126 #else // the parrallel version
127
128 #endif // is_mpi
129
130
131 }