Keep it simple: use only one structure and get_time function

This commit is contained in:
dwarning 2024-11-06 14:32:26 +01:00 committed by Holger Vogt
parent 60554855d8
commit bf6ffd357d
5 changed files with 8 additions and 32 deletions

View File

@ -77,13 +77,10 @@ init_rlimits(void)
ft_ckspace();
}
PerfTimer timer;
void
init_time(void)
{
perf_timer_get_time(&timebegin);
perf_timer_start(&timer);
}
@ -158,6 +155,7 @@ printres(char *name)
static bool called = FALSE;
static long last_sec = 0, last_msec = 0;
struct variable *v, *vfree = NULL;
PerfTime timenow; /* actual time stamp */
char *cpu_elapsed;
if (!name || eq(name, "totalcputime") || eq(name, "cputime")) {
@ -168,8 +166,9 @@ printres(char *name)
|| defined (HAVE_GETTIMEOFDAY) || defined(HAVE_TIMES) \
|| defined (HAVE_GETRUSAGE) || defined(HAVE_FTIME)
perf_timer_stop(&timer);
perf_timer_elapsed_sec_ms(&timer, &total_sec, &total_msec);
perf_timer_get_time(&timenow);
total_sec = timenow.seconds;
total_msec = timenow.milliseconds;
#ifdef USE_OMP // this order have to be same as
cpu_elapsed = "elapsed"; // the order in seconds() misc_time.c

View File

@ -159,23 +159,6 @@ seconds(void)
#endif
}
void perf_timer_start(PerfTimer *timer)
{
timer->start = seconds();
}
void perf_timer_stop(PerfTimer *timer)
{
timer->end = seconds();
}
void perf_timer_elapsed_sec_ms(const PerfTimer *timer, int *seconds, int *milliseconds)
{
double elapsed = timer->end - timer->start;
*seconds = (int)elapsed;
*milliseconds = (int)((elapsed - *seconds) * 1000.0);
}
void perf_timer_get_time(PerfTime *time)
{
time->secs = seconds();

View File

@ -9,20 +9,12 @@
char * datestring(void);
double seconds(void);
typedef struct {
double start;
double end;
} PerfTimer;
typedef struct {
double secs;
int seconds;
int milliseconds;
} PerfTime;
void perf_timer_start(PerfTimer *);
void perf_timer_stop(PerfTimer *);
void perf_timer_elapsed_sec_ms(const PerfTimer *, int *, int *);
void perf_timer_get_time(PerfTime *);
extern PerfTime timebegin;

View File

@ -1971,7 +1971,8 @@ void SetAnalyse(
/* get current time */
perf_timer_get_time(&timenow);
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
diffsec = timenow.seconds;
diffmillisec = timenow.milliseconds;
s = TMALLOC(char, 128);

View File

@ -233,7 +233,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */
/* get actual time */
perf_timer_get_time(&timenow);
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
diffsec = timenow.seconds;
diffmillisec = timenow.milliseconds;
OldPercent = DecaPercent;
/* output only into hwAnalyse window and if time elapsed is larger than