Skip to content
Snippets Groups Projects
Commit 3b898ac3 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

timer.cc: cleanup

parent a456a9b0
No related branches found
No related tags found
1 merge request!75M214003/develop
Pipeline #38074 passed
......@@ -5,20 +5,14 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "cdo_timer.h"
#include "timer.h"
int timer_read, timer_write;
FILE *rt_unit = nullptr;
static FILE *rt_unit = stderr;
enum
{
......@@ -27,17 +21,17 @@ enum
rt_stat_off
};
/* minimal internal time needed to do one measurement */
// minimal internal time needed to do one measurement
double tm_shift = 0.0;
static double tm_shift = 0.0;
/* average total overhead for one timer_start & timer_stop pair */
// average total overhead for one timer_start & timer_stop pair
double tm_overhead = 0.0;
static double tm_overhead = 0.0;
#define MAX_TIMER 128 /* max number of timers allowed */
constexpr int MAX_TIMER = 128; // max number of timers allowed
struct RT_TYPE
struct RealTimer
{
int reserved = 0;
int calls = 0;
......@@ -50,9 +44,9 @@ struct RT_TYPE
std::string text;
};
RT_TYPE rt[MAX_TIMER];
int timer_need_init = 1;
int top_timer = 0;
static RealTimer rt[MAX_TIMER];
static int timer_need_init = 1;
static int top_timer = 0;
static double
get_time_val(double mark0)
......@@ -62,7 +56,7 @@ get_time_val(double mark0)
return dt;
}
int ntests = 100; /* tests need about n microsecs on pwr4 */
constexpr int ntests = 100; // tests need about n microsecs
static double
m1(void)
......@@ -105,10 +99,7 @@ estimate_overhead(void)
static void
timer_init(void)
{
rt_unit = stderr;
estimate_overhead();
timer_need_init = 0;
}
......@@ -124,7 +115,7 @@ timer_new(const std::string &text)
fprintf(stderr, "timer_new: MAX_TIMER too small!\n");
}
int it = top_timer;
auto it = top_timer;
top_timer++;
rt[it].reserved = 1;
......@@ -147,10 +138,7 @@ timer_val(int it)
auto val = rt[it].tot;
if (rt[it].stat == rt_stat_on)
{
val += get_time_val(rt[it].mark1);
}
if (rt[it].stat == rt_stat_on) { val += get_time_val(rt[it].mark1); }
return val;
}
......@@ -169,9 +157,8 @@ timer_report(void)
for (int it = 0; it < top_timer; it++)
{
double total = timer_val(it);
double avg = rt[it].tot;
auto total = timer_val(it);
auto avg = rt[it].tot;
if (rt[it].calls > 0) avg /= rt[it].calls;
if (rt[it].stat != rt_stat_undef)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment