Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Feature request: high resolution timestamp variable #6

Open
PAStheLoD opened this Issue Sep 11, 2011 · 5 comments

Comments

Projects
None yet
3 participants

Hello,

I'd like to put a timestamp into my upstream request URIs (or include it as a request header with the HeardsMore module), so it'd be great if you could implement a few other special variables:

  • tsc_time using a crude but fast solution[0] of reading the TSC register and dividing it with the MHZ from /proc/cpuinfo ~ 50 cycles
  • gettimeofday: ngx_gettimeofday is just a macro for gettimeofday( tp, NULL) ~ 10K cycles
  • clock_gettime(CLOCK_MONOTONIC , ...) or with other CLOCK_* ~ 10K cycles

Thanks!

[0] http://stackoverflow.com/questions/88/is-gettimeofday-guaranteed-to-be-of-microsecond-resolution/367#367

Owner

agentzh commented Sep 12, 2011

Patches welcome! :)

clock_gettime required rt lib, not sure if it's good idea

I have set_hires_time (wrong name, it's not related to time, it's CPU cycles)
for example

location /hires.html {
    default_type plain/html;
    set_hires_time $hires1;
    set_hires_time $hires2;
    let $hires ( $hires2 - $hires1 );
    echo $hires1;
    echo $hires2;
    echo $hires;
    break;
}

return something like
20796514112602790 20796514112618124 15334
Of course all variables in location was set in one time, but 15334 cycles is difference between this "one time" )

PS. nginx 1.4.4, used nginx-let-module, echo-nginx-module, my fork of set-misc-nginx-module
CPU Model: 6.42.7 "Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz"
(yep, this code may be CPU type depended )

Owner

agentzh commented Dec 14, 2013

@TrurlMcByte seems like it's only useful for timing an ngx_rewrite command :)

with echo_location working too )

        location = /hires1.html {
            default_type plain/html;
            echo_reset_timer;
            echo_location /hires1;
            echo_location /hires2;
            echo "took $echo_timer_elapsed sec for total.";
        }

        location = /hires1 {
            echo_sleep 1.0;
            set_hires_time $hires1;
            echo $hires1;
        }

        location = /hires2 {
            set_hires_time $hires2;
            echo $hires2;
        }

20803416887362244
20803420302652656
took 1.001 sec for total.

3415290412 cycles difference for 1.001 seconds is not bad precision )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment