diff options
| author | Albert Cervin <albert@acervin.com> | 2024-05-06 22:42:39 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2024-05-06 22:42:39 +0200 |
| commit | ad0cd5c036f0080ee8d97db2e67b8d54186d1e33 (patch) | |
| tree | b85cc21acac6e1383dfa3b78494ce09c409b2f30 /src/dged/timers.c | |
| parent | c42412e1643c88c81cf5b38404cc010881437fe9 (diff) | |
| download | dged-ad0cd5c036f0080ee8d97db2e67b8d54186d1e33.tar.gz dged-ad0cd5c036f0080ee8d97db2e67b8d54186d1e33.tar.xz dged-ad0cd5c036f0080ee8d97db2e67b8d54186d1e33.zip | |
Fix slow buffer paste
Was caused by updating all buffer hooks on every char insert.
Particularily, the syntax update takes a little bit too long to
call on every char. Now the keyboard parsing routine compresses
all consecutive self-inserting chars into one "key press".
Also fix some small issues with timers and update them with a min
and max.
Diffstat (limited to 'src/dged/timers.c')
| -rw-r--r-- | src/dged/timers.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/dged/timers.c b/src/dged/timers.c index 37ac367..798c003 100644 --- a/src/dged/timers.c +++ b/src/dged/timers.c @@ -10,6 +10,8 @@ struct timer { char name[32]; + uint64_t max; + uint64_t min; uint64_t samples[NUM_FRAME_SAMPLES]; struct timespec started_at; }; @@ -50,7 +52,8 @@ struct timer *timer_start(const char *name) { namelen = namelen >= 32 ? 31 : namelen; memcpy(new_timer->name, name, namelen); new_timer->name[namelen] = '\0'; - + new_timer->max = 0; + new_timer->min = (uint64_t)-1; memset(new_timer->samples, 0, sizeof(uint64_t) * NUM_FRAME_SAMPLES); t = new_timer; @@ -60,14 +63,23 @@ struct timer *timer_start(const char *name) { return t; } -void timer_stop(struct timer *timer) { +uint64_t timer_stop(struct timer *timer) { struct timespec end; clock_gettime(CLOCK_MONOTONIC, &end); uint64_t elapsed = ((uint64_t)end.tv_sec * 1e9 + (uint64_t)end.tv_nsec) - ((uint64_t)timer->started_at.tv_sec * 1e9 + (uint64_t)timer->started_at.tv_nsec); + if (elapsed > timer->max) { + timer->max = elapsed; + } + + if (elapsed < timer->min) { + timer->min = elapsed; + } + timer->samples[g_timers.frame_index] += elapsed; + return elapsed; } struct timer *timer_get(const char *name) { @@ -82,9 +94,12 @@ float timer_average(const struct timer *timer) { } return (float)sum / NUM_FRAME_SAMPLES; - return 0.f; } +uint64_t timer_max(const struct timer *timer) { return timer->max; } + +uint64_t timer_min(const struct timer *timer) { return timer->min; } + const char *timer_name(const struct timer *timer) { return timer->name; } void timers_for_each(timer_callback callback, void *userdata) { |
