use timer functions in winmain and sharedspice instead ftime

This commit is contained in:
dwarning 2024-10-29 14:57:32 +01:00
parent 9ac0a6e63b
commit bb08b460d1
5 changed files with 48 additions and 45 deletions

View File

@ -82,6 +82,7 @@ PerfTimer timer;
void
init_time(void)
{
perf_timer_get_time(&timebegin);
perf_timer_start(&timer);
}

View File

@ -61,15 +61,13 @@ datestring(void)
/* return time interval in seconds and milliseconds */
#ifdef HAVE_FTIME
PerfTime timebegin;
struct timeb timebegin;
void timediff(struct timeb *now, struct timeb *begin, int *sec, int *msec)
void timediff(PerfTime *now, PerfTime *begin, int *sec, int *msec)
{
*msec = (int) now->millitm - (int) begin->millitm;
*sec = (int) now->time - (int) begin->time;
*msec = (int) now->milliseconds - (int) begin->milliseconds;
*sec = (int) now->seconds - (int) begin->seconds;
if (*msec < 0) {
*msec += 1000;
(*sec)--;
@ -78,8 +76,6 @@ void timediff(struct timeb *now, struct timeb *begin, int *sec, int *msec)
}
#endif
/*
* How many seconds have elapsed in running time.
* This is the routine called in IFseconds
@ -122,7 +118,7 @@ seconds(void)
ftime(&tb);
return tb.time + tb.millitm / 1000.0;
#else
error_no_timer_function_available;
#error "No timer function available."
#endif
}
@ -142,3 +138,11 @@ void perf_timer_elapsed_sec_ms(const PerfTimer *timer, int *seconds, int *millis
*seconds = (int)elapsed;
*milliseconds = (int)((elapsed - *seconds) * 1000.0);
}
void perf_timer_get_time(PerfTime *time)
{
double secs = seconds();
time->seconds = (int)secs;
time->milliseconds = (int)((secs - time->seconds) * 1000.0);
}

View File

@ -14,16 +14,18 @@ typedef struct {
double end;
} PerfTimer;
typedef struct {
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 *);
#ifdef HAVE_FTIME
extern PerfTime timebegin;
extern struct timeb timebegin;
void timediff(struct timeb *, struct timeb *, int *, int *);
#endif
void timediff(PerfTime *, PerfTime *, int *, int *);
#endif

View File

@ -155,10 +155,6 @@ static bool cont_condition;
#include "ngspice/stringskip.h"
#include "frontend/variable.h"
#ifdef HAVE_FTIME
#include <sys/timeb.h>
#endif
/* To interupt a spice run */
#include <signal.h>
typedef void (*sighandler)(int);
@ -1892,26 +1888,32 @@ void SetAnalyse(
static unsigned int ng_id1 = 0, ng_id2 = 0;
bool thread1;
#ifdef HAVE_FTIME
struct timeb timenow; /* actual time stamp */
#if defined (USE_OMP) \
|| defined (HAVE_QUERYPERFORMANCECOUNTER) \
|| defined (HAVE_CLOCK_GETTIME) \
|| defined (HAVE_GETTIMEOFDAY) \
|| defined (HAVE_TIMES) \
|| defined (HAVE_GETRUSAGE) \
|| defined (HAVE_FTIME)
PerfTime timenow; /* actual time stamp */
int diffsec, diffmillisec; /* differences actual minus prev. time stamp */
int result; /* return value from callback function */
char* s; /* outputs to callback function */
int OldPercent; /* Previous progress value */
char OldAn[128]; /* Previous analysis type */
char olds[128]; /* previous output */
static struct timeb timebefore; /* previous time stamp */
static PerfTime timebefore; /* previous time stamp */
/* thread 1 */
static int OldPercent1 = -2; /* Previous progress value */
static char OldAn1[128]; /* Previous analysis type */
static char olds1[128]; /* previous output */
static struct timeb timebefore1; /* previous time stamp */
static PerfTime timebefore1; /* previous time stamp */
/* thread2 */
static int OldPercent2 = -2; /* Previous progress value */
static char OldAn2[128]; /* Previous analysis type */
static char olds2[128]; /* previous output */
static struct timeb timebefore2; /* previous time stamp */
static PerfTime timebefore2; /* previous time stamp */
/*set the two thread ids */
unsigned int ng_idl = threadid_self();
@ -1929,20 +1931,16 @@ void SetAnalyse(
strcpy(OldAn, OldAn1);
strcpy(olds, olds1);
OldPercent = OldPercent1;
timebefore.dstflag = timebefore1.dstflag;
timebefore.millitm = timebefore1.millitm;
timebefore.time = timebefore1.time;
timebefore.timezone = timebefore1.timezone;
timebefore.milliseconds = timebefore1.milliseconds;
timebefore.seconds = timebefore1.seconds;
}
else if (ng_idl == ng_id2) {
thread1 = FALSE;
strcpy(OldAn, OldAn2);
strcpy(olds, olds2);
OldPercent = OldPercent2;
timebefore.dstflag = timebefore2.dstflag;
timebefore.millitm = timebefore2.millitm;
timebefore.time = timebefore2.time;
timebefore.timezone = timebefore2.timezone;
timebefore.milliseconds = timebefore2.milliseconds;
timebefore.seconds = timebefore2.seconds;
}
else
return;
@ -1956,7 +1954,7 @@ void SetAnalyse(
return;
/* get actual time */
ftime(&timenow);
perf_timer_get_time(&timenow);
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
s = TMALLOC(char, 128);
@ -2007,16 +2005,12 @@ void SetAnalyse(
sprintf( s, "%s: %3.1f%%", Analyse, (double)DecaPercent/10.);
}
if (thread1) {
timebefore1.dstflag = timenow.dstflag;
timebefore1.millitm = timenow.millitm;
timebefore1.time = timenow.time;
timebefore1.timezone = timenow.timezone;
timebefore1.milliseconds = timenow.milliseconds;
timebefore1.seconds = timenow.seconds;
}
else {
timebefore2.dstflag = timenow.dstflag;
timebefore2.millitm = timenow.millitm;
timebefore2.time = timenow.time;
timebefore2.timezone = timenow.timezone;
timebefore2.milliseconds = timenow.milliseconds;
timebefore2.seconds = timenow.seconds;
}
/* info when previous analysis period has finished */
if (strcmp(OldAn, Analyse)) {

View File

@ -220,7 +220,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */
static int OldPercent = -2; /* Previous progress value */
static char OldAn[128]; /* Previous analysis type */
char s[128], t[128]; /* outputs to analysis window and task bar */
PerfTimer timer; /* previous time stamp and actual time stamp */
static Perftime timebefore; /* previous time stamp */
Perftime timenow; /* actual time stamp */
int diffsec, diffmillisec; /* differences actual minus prev. time stamp */
WaitForIdle();
@ -231,8 +232,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */
return;
/* get actual time */
perf_timer_stop(&timer);
perf_timer_elapsed_sec_ms(&timer, &diffsec, &diffmillisec);
perf_timer_get_time(&timenow);
timediff(&timenow, &timebefore, &diffsec, &diffmillisec);
OldPercent = DecaPercent;
/* output only into hwAnalyse window and if time elapsed is larger than
@ -254,7 +255,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */
sprintf(s, " %s: %3.1f%%", Analyse, (double)DecaPercent/10.);
sprintf(t, "%s %3.1f%%", PACKAGE_STRING, (double)DecaPercent/10.);
}
timer.start = timer.end;
timebefore.milliseconds = timenow.milliseconds;
timebefore.seconds = timenow.seconds;
/* info when previous analysis period has finished */
if (strcmp(OldAn, Analyse)) {
if ((ft_nginfo || ft_ngdebug) && (strcmp(OldAn, "")))