Skip to content

improve timestamp resolution #55

@brendangregg

Description

@brendangregg

The timestamp variable returns time with a ~10 ms granularity (based on xtime cache). For performance analysis it needs much better resolution.

This looks like it is due to dtrace_gethrtime() in driver/dtrace_linux.c, which looks like a work in progress.

As a workaround, I've been making the following change:

diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c
index ac13788..8bb2ed3 100644
--- a/driver/dtrace_linux.c
+++ b/driver/dtrace_linux.c
@@ -387,6 +387,9 @@ dtrace_gethrtime()
 {
        struct timespec ts;

+       getnstimeofday(&ts);
+       return (hrtime_t) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
+
        /*
        void (*ktime_get_ts)() = get_proc_addr("ktime_get_ts");
        if (ktime_get_ts == NULL) return 0;

WARNING: getnstimeofday() grabs seqlock. I don't know if this is safe to do in DTrace context - I'd assume it isn't until known otherwise. Generally, grabbing locks in DTrace context is unsafe (blocking while interrupts disabled), however, the characteristics of seqlock sound similar to the behavior of the Solaris dtrace_gethrtime(), so this might be ok.

As some example output with the above change, showing the resolution is satisfactory:

root@ubuntu:~/linux# dtrace -n 'syscall:::entry { self->ts = timestamp; }
    syscall:::return /self->ts/ { @["ns"] = quantize(timestamp - self->ts); self->ts = 0; }'
dtrace: description 'syscall:::entry ' matched 1318 probes
^C

  ns                                                
           value  ------------- Distribution ------------- count    
             256 |                                         0        
             512 |@                                        250      
            1024 |@@@@@@@@@@@@@@@@@@                       2982     
            2048 |@@                                       424      
            4096 |@                                        106      
            8192 |@@@@@@@@@@@@@@@@@                        2815     
           16384 |@                                        127      
           32768 |                                         3        
           65536 |                                         6        
          131072 |                                         17       
          262144 |                                         0        
          524288 |                                         0        
[...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions