-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_obj.c
267 lines (249 loc) · 7.95 KB
/
timer_obj.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "timer_obj.h"
#include "scenario_obj.h"
#include "ugm_defines.h"
#include "globals.h"
#include "ugm_macros.h"
/*****************************************************************************\
*******************************************************************************
** **
** MACROS **
** **
*******************************************************************************
\*****************************************************************************/
#define MAX_NUM_TIMERS 20
/*****************************************************************************\
*******************************************************************************
** **
** STATIC MEMORY FOR THIS OBJECT **
** **
*******************************************************************************
\*****************************************************************************/
typedef struct
{
char name[125];
clock_t start;
clock_t stop;
int num_calls;
float total_time;
float average_time;
BOOLEAN running;
}
ugm_timer_t;
static ugm_timer_t array[MAX_NUM_TIMERS];
static int actual_num_timers;
/*****************************************************************************\
*******************************************************************************
** **
** SCCS ID **
** **
*******************************************************************************
\*****************************************************************************/
char timer_obj_c_sccs_id[] = "@(#)timer_obj.c 1.81 12/4/00";
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_MemoryLog
** PURPOSE: log memory map to FILE* fp
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
timer_MemoryLog (FILE * fp)
{
LOG_MEM (fp, &array[0], sizeof (ugm_timer_t), MAX_NUM_TIMERS);
LOG_MEM (fp, &actual_num_timers, sizeof (int), 1);
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_Init
** PURPOSE: initialize timers
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
timer_Init ()
{
char func[] = "timer_Init";
int i;
actual_num_timers = 12;
if (actual_num_timers > MAX_NUM_TIMERS)
{
sprintf (msg_buf, "actual_num_timers > MAX_NUM_TIMERS");
LOG_ERROR (msg_buf);
EXIT (1);
}
strcpy (array[0].name, "spr_spread");
strcpy (array[1].name, "spr_phase1n3");
strcpy (array[2].name, "spr_phase4");
strcpy (array[3].name, "spr_phase5");
strcpy (array[4].name, "gdif_WriteGIF");
strcpy (array[5].name, "gdif_ReadGIF");
strcpy (array[6].name, "delta_deltatron");
strcpy (array[7].name, "delta_phase1");
strcpy (array[8].name, "delta_phase2");
strcpy (array[9].name, "grw_growth");
strcpy (array[10].name, "drv_driver");
strcpy (array[11].name, "main");
for (i = 0; i < actual_num_timers; i++)
{
array[i].num_calls = 0;
array[i].running = FALSE;
array[i].total_time = 0.0;
}
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_Start
** PURPOSE: start a timer
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
timer_Start (int val)
{
char func[] = "timer_Start";
if ((val < 0) || (val > actual_num_timers))
{
sprintf (msg_buf, "(val < 0) || (val > actual_num_timers)");
LOG_ERROR (msg_buf);
EXIT (1);
}
if (array[val].running)
{
sprintf (msg_buf, "array[%u].running", val);
LOG_ERROR (msg_buf);
EXIT (1);
}
array[val].start = clock ();
array[val].num_calls++;
array[val].running = TRUE;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_Read
** PURPOSE: read a timer
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
double
timer_Read (int val)
{
char func[] = "timer_Read";
if ((val < 0) || (val > actual_num_timers))
{
sprintf (msg_buf, "(val < 0) || (val > actual_num_timers)");
LOG_ERROR (msg_buf);
EXIT (1);
}
if (!array[val].running)
{
sprintf (msg_buf, "array[%u].running", val);
LOG_ERROR (msg_buf);
EXIT (1);
}
return (((double) (clock () - array[val].start)
* 1000) / CLOCKS_PER_SEC) + array[val].total_time;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_Stop
** PURPOSE: stop a timer
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
timer_Stop (int val)
{
char func[] = "timer_Stop";
if ((val < 0) || (val > actual_num_timers))
{
sprintf (msg_buf, "(val < 0) || (val > actual_num_timers)");
LOG_ERROR (msg_buf);
EXIT (1);
}
if (!array[val].running)
{
sprintf (msg_buf, "array[%u].running", val);
LOG_ERROR (msg_buf);
EXIT (1);
}
array[val].running = FALSE;
array[val].stop = clock ();
array[val].total_time += ((float) (array[val].stop - array[val].start)
* 1000) / CLOCKS_PER_SEC;
array[val].average_time = array[val].total_time / array[val].num_calls;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: timer_LogIt
** PURPOSE: log timer results to FILE * fp
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
timer_LogIt (FILE * fp)
{
char buf[15];
int i;
fprintf (fp, "\n\n****************************LOG OF TIMINGS ");
fprintf (fp, "***********************************\n");
fprintf (fp, " Routine #Calls Avg Time Total Time\n");
fprintf (fp, " (millisec) (millisec)\n");
for (i = 0; i < actual_num_timers; i++)
{
fprintf (fp, "%15s %5u %8.2f %10.2f = %s\n",
array[i].name,
array[i].num_calls,
array[i].average_time,
array[i].total_time,
timer_Format (buf, (unsigned int) (array[i].total_time / 1000)));
}
fprintf (fp, "Number of CPUS = %u\n", glb_npes);
}
char *
timer_Format (char *buf, unsigned int sec)
{
unsigned int days;
unsigned int hrs;
unsigned int min;
#define SEC_PER_DAY (60*60*24)
#define SEC_PER_HR (60*60)
#define SEC_PER_MIN 60
days = sec / SEC_PER_DAY;
sec -= MAX ((days * SEC_PER_DAY), 0);
hrs = sec / SEC_PER_HR;
sec -= MAX ((hrs * SEC_PER_HR), 0);
min = sec / SEC_PER_MIN;
sec -= MAX ((min * SEC_PER_MIN), 0);
sprintf (buf, "%04u:%02u:%02u:%02u", days, hrs, min, sec);
return buf;
}