diff options
author | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-06-15 12:29:32 +0200 |
---|---|---|
committer | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-07-16 17:12:34 +0200 |
commit | db7cd61f6297aab6343f7c6cd424d8987ca03a58 (patch) | |
tree | 85e06fa1cd4cf005facf4e63ecd0c98519effa2f /src/nvim/syntax.c | |
parent | f172b19f438b0bccdc1be0d82a6fe660c4bbd6e0 (diff) | |
download | rneovim-db7cd61f6297aab6343f7c6cd424d8987ca03a58.tar.gz rneovim-db7cd61f6297aab6343f7c6cd424d8987ca03a58.tar.bz2 rneovim-db7cd61f6297aab6343f7c6cd424d8987ca03a58.zip |
profiling: implement on top of os_hrtime()
Should be better than gettimeofday() since libuv uses higher resolution
clocks on most UNIX platforms. Libuv also tries to use monotonic clocks,
kernel bugs notwithstanding, which is another win over gettimeofday().
Necessary for Windows, which doesn't have gettimeofday(). In vanilla vim,
Windows uses QueryPerformanceCounter, which is the correct primitive for
this sort of things, but that was removed when slimming up the codebase.
Libuv uses QueryPerformanceCounter to implement uv_hrtime() on Windows so
the behaviour of vim profiling on Windows should now be the same.
The behaviour on Linux should be different (better) though, libuv uses more
accurate primitives than gettimeofday().
Other misc. changes:
- Added function attributes where relevant (const, pure, ...)
- Convert functions to receive scalars: Now that proftime_T is always a
(uint64_t) scalar (and not a struct), it's clearer to convert the
functions to receive it as such instead of a pointer to a scalar.
- Extract profiling funcs to profile.c: make everything clearer and reduces
the size of the "catch-all" ex_cmds2.c
- Add profile.{c,h} to clint and -Wconv:
- Don't use sprintf, use snprintf
- Don't use long, use int16_t/int32_t/...
Diffstat (limited to 'src/nvim/syntax.c')
-rw-r--r-- | src/nvim/syntax.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 96d45f41bf..51aeda7293 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2856,17 +2856,19 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T int r; proftime_T pt; - if (syn_time_on) - profile_start(&pt); + if (syn_time_on) { + pt = profile_start(); + } rmp->rmm_maxcol = syn_buf->b_p_smc; r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, NULL); if (syn_time_on) { - profile_end(&pt); - profile_add(&st->total, &pt); - if (profile_cmp(&pt, &st->slowest) < 0) + pt = profile_end(pt); + st->total = profile_add(st->total, pt); + if (profile_cmp(pt, st->slowest) < 0) { st->slowest = pt; + } ++st->count; if (r > 0) ++st->match; @@ -5630,8 +5632,8 @@ void ex_syntime(exarg_T *eap) static void syn_clear_time(syn_time_T *st) { - profile_zero(&st->total); - profile_zero(&st->slowest); + st->total = profile_zero(); + st->slowest = profile_zero(); st->count = 0; st->match = 0; } @@ -5673,7 +5675,7 @@ static int syn_compare_syntime(const void *v1, const void *v2) const time_entry_T *s1 = v1; const time_entry_T *s2 = v2; - return profile_cmp(&s1->total, &s2->total); + return profile_cmp(s1->total, s2->total); } /* @@ -5684,7 +5686,6 @@ static void syntime_report(void) synpat_T *spp; proftime_T tm; int len; - proftime_T total_total; int total_count = 0; garray_T ga; time_entry_T *p; @@ -5695,18 +5696,18 @@ static void syntime_report(void) } ga_init(&ga, sizeof(time_entry_T), 50); - profile_zero(&total_total); + proftime_T total_total = profile_zero(); for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) { spp = &(SYN_ITEMS(curwin->w_s)[idx]); if (spp->sp_time.count > 0) { p = GA_APPEND_VIA_PTR(time_entry_T, &ga); p->total = spp->sp_time.total; - profile_add(&total_total, &spp->sp_time.total); + total_total = profile_add(total_total, spp->sp_time.total); p->count = spp->sp_time.count; p->match = spp->sp_time.match; total_count += spp->sp_time.count; p->slowest = spp->sp_time.slowest; - profile_divide(&spp->sp_time.total, spp->sp_time.count, &tm); + tm = profile_divide(spp->sp_time.total, spp->sp_time.count); p->average = tm; p->id = spp->sp_syn.id; p->pattern = spp->sp_pattern; @@ -5724,7 +5725,7 @@ static void syntime_report(void) spp = &(SYN_ITEMS(curwin->w_s)[idx]); p = ((time_entry_T *)ga.ga_data) + idx; - MSG_PUTS(profile_msg(&p->total)); + MSG_PUTS(profile_msg(p->total)); MSG_PUTS(" "); /* make sure there is always a separating space */ msg_advance(13); msg_outnum(p->count); @@ -5733,10 +5734,10 @@ static void syntime_report(void) msg_outnum(p->match); MSG_PUTS(" "); msg_advance(26); - MSG_PUTS(profile_msg(&p->slowest)); + MSG_PUTS(profile_msg(p->slowest)); MSG_PUTS(" "); msg_advance(38); - MSG_PUTS(profile_msg(&p->average)); + MSG_PUTS(profile_msg(p->average)); MSG_PUTS(" "); msg_advance(50); msg_outtrans(HL_TABLE()[p->id - 1].sg_name); @@ -5755,7 +5756,7 @@ static void syntime_report(void) ga_clear(&ga); if (!got_int) { MSG_PUTS("\n"); - MSG_PUTS(profile_msg(&total_total)); + MSG_PUTS(profile_msg(total_total)); msg_advance(13); msg_outnum(total_count); MSG_PUTS("\n"); |