Commit a17d1e8e authored by KarimAllah Ahmed's avatar KarimAllah Ahmed

opensnoop: Refactor initial timestamp calculation

Signed-off-by: default avatarKarimAllah Ahmed <karim.allah.ahmed@gmail.com>
parent 0eb81fd8
...@@ -129,9 +129,7 @@ class Data(ct.Structure): ...@@ -129,9 +129,7 @@ class Data(ct.Structure):
("fname", ct.c_char * NAME_MAX) ("fname", ct.c_char * NAME_MAX)
] ]
start_ts = 0 initial_ts = 0
prev_ts = 0
delta = 0
# header # header
if args.timestamp: if args.timestamp:
...@@ -141,9 +139,7 @@ print("%-6s %-16s %4s %3s %s" % ("PID", "COMM", "FD", "ERR", "PATH")) ...@@ -141,9 +139,7 @@ print("%-6s %-16s %4s %3s %s" % ("PID", "COMM", "FD", "ERR", "PATH"))
# process event # process event
def print_event(cpu, data, size): def print_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(Data)).contents event = ct.cast(data, ct.POINTER(Data)).contents
global start_ts global initial_ts
global prev_ts
global delta
# split return value into FD and errno columns # split return value into FD and errno columns
if event.ret >= 0: if event.ret >= 0:
...@@ -153,26 +149,19 @@ def print_event(cpu, data, size): ...@@ -153,26 +149,19 @@ def print_event(cpu, data, size):
fd_s = -1 fd_s = -1
err = - event.ret err = - event.ret
if start_ts == 0: if not initial_ts:
prev_ts = start_ts initial_ts = event.ts
if start_ts == 1: if args.failed and (event.ret >= 0):
delta = float(delta) + (event.ts - prev_ts)
if (args.failed and (event.ret >= 0)):
start_ts = 1
prev_ts = event.ts
return return
if args.timestamp: if args.timestamp:
print("%-14.9f" % (delta / 1000000), end="") delta = event.ts - initial_ts
print("%-14.9f" % (float(delta) / 1000000), end="")
print("%-6d %-16s %4d %3d %s" % (event.pid, event.comm, print("%-6d %-16s %4d %3d %s" % (event.pid, event.comm,
fd_s, err, event.fname)) fd_s, err, event.fname))
prev_ts = event.ts
start_ts = 1
# loop with callback to print_event # loop with callback to print_event
b["events"].open_perf_buffer(print_event) b["events"].open_perf_buffer(print_event)
while 1: while 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment