Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: high resolution timestamp variable #6

Open
PAStheLoD opened this issue Sep 11, 2011 · 6 comments
Open

Feature request: high resolution timestamp variable #6

PAStheLoD opened this issue Sep 11, 2011 · 6 comments

Comments

@PAStheLoD
Copy link

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

@agentzh
Copy link
Member

agentzh commented Sep 12, 2011

Patches welcome! :)

@TrurlMcByte
Copy link

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

@TrurlMcByte
Copy link

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 )

@agentzh
Copy link
Member

agentzh commented Dec 14, 2013

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

@TrurlMcByte
Copy link

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 )

@waldman
Copy link

waldman commented Jan 17, 2020

I just had to say... @TrurlMcByte can't believe I just found you around here! \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants