Mercurial > geeqie
comparison src/main.c @ 412:eb5ae19a62f6
Display elapsed time since previous get_exec_time() call (debug only).
author | zas_ |
---|---|
date | Fri, 18 Apr 2008 21:53:33 +0000 |
parents | 2649a28d31b6 |
children | 5ddcf93278c7 |
comparison
equal
deleted
inserted
replaced
411:f744baaa71a5 | 412:eb5ae19a62f6 |
---|---|
115 gdouble get_zoom_increment(void) | 115 gdouble get_zoom_increment(void) |
116 { | 116 { |
117 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); | 117 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); |
118 } | 118 } |
119 | 119 |
120 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y) | |
121 { | |
122 if (x->tv_usec < y->tv_usec) | |
123 { | |
124 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; | |
125 y->tv_usec -= 1000000 * nsec; | |
126 y->tv_sec += nsec; | |
127 } | |
128 | |
129 if (x->tv_usec - y->tv_usec > 1000000) | |
130 { | |
131 gint nsec = (x->tv_usec - y->tv_usec) / 1000000; | |
132 y->tv_usec += 1000000 * nsec; | |
133 y->tv_sec -= nsec; | |
134 } | |
135 | |
136 result->tv_sec = x->tv_sec - y->tv_sec; | |
137 result->tv_usec = x->tv_usec - y->tv_usec; | |
138 | |
139 return x->tv_sec < y->tv_sec; | |
140 } | |
141 | |
120 const gchar *get_exec_time() | 142 const gchar *get_exec_time() |
121 { | 143 { |
122 static gchar timestr[20]; | 144 static gchar timestr[30]; |
123 static struct timeval start_tv = {0, 0}; | 145 static struct timeval start_tv = {0, 0}; |
124 | 146 static struct timeval previous = {0, 0}; |
147 static gint started = 0; | |
148 | |
125 struct timeval tv = {0, 0}; | 149 struct timeval tv = {0, 0}; |
126 | 150 static struct timeval delta = {0, 0}; |
151 | |
127 gettimeofday(&tv, NULL); | 152 gettimeofday(&tv, NULL); |
128 | 153 |
129 if (start_tv.tv_sec == 0) start_tv = tv; | 154 if (start_tv.tv_sec == 0) start_tv = tv; |
130 | 155 |
131 tv.tv_sec -= start_tv.tv_sec; | 156 tv.tv_sec -= start_tv.tv_sec; |
134 else | 159 else |
135 { | 160 { |
136 tv.tv_usec += 1000000 - start_tv.tv_usec; | 161 tv.tv_usec += 1000000 - start_tv.tv_usec; |
137 tv.tv_sec -= 1; | 162 tv.tv_sec -= 1; |
138 } | 163 } |
139 | 164 |
140 g_snprintf(timestr, sizeof(timestr), "%5d.%06d", (int)tv.tv_sec, (int)tv.tv_usec); | 165 if (started) timeval_delta(&delta, &tv, &previous); |
166 | |
167 previous = tv; | |
168 started = 1; | |
169 | |
170 g_snprintf(timestr, sizeof(timestr), "%5d.%06d (+%05d.%06d)", (int)tv.tv_sec, (int)tv.tv_usec, (int)delta.tv_sec, (int)delta.tv_usec); | |
141 | 171 |
142 return timestr; | 172 return timestr; |
143 } | 173 } |
144 | 174 |
145 /* | 175 /* |