Commit 85208ec1 authored by Brenden Blanco's avatar Brenden Blanco

Merge pull request #167 from brendangregg/master

improve examples using new features
parents 0c7ab873 39e13733
...@@ -44,9 +44,6 @@ dist_max = 64 ...@@ -44,9 +44,6 @@ dist_max = 64
# header # header
print("Tracing... Hit Ctrl-C to end.") print("Tracing... Hit Ctrl-C to end.")
last = {}
for i in range(1, dist_max + 1):
last[i] = 0
# functions # functions
stars_max = 38 stars_max = 38
...@@ -67,7 +64,7 @@ def print_log2_hist(dist, val_type): ...@@ -67,7 +64,7 @@ def print_log2_hist(dist, val_type):
val_max = 0 val_max = 0
for i in range(1, dist_max + 1): for i in range(1, dist_max + 1):
try: try:
val = dist[c_int(i)].value - last[i] val = dist[c_int(i)].value
if (val > 0): if (val > 0):
idx_max = i idx_max = i
if (val > val_max): if (val > val_max):
...@@ -82,10 +79,9 @@ def print_log2_hist(dist, val_type): ...@@ -82,10 +79,9 @@ def print_log2_hist(dist, val_type):
if (low == high): if (low == high):
low -= 1 low -= 1
try: try:
val = dist[c_int(i)].value - last[i] val = dist[c_int(i)].value
print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val, print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val,
stars_max, stars(val, val_max, stars_max))) stars_max, stars(val, val_max, stars_max)))
last[i] = dist[c_int(i)].value
except: except:
break break
...@@ -104,5 +100,6 @@ while (1): ...@@ -104,5 +100,6 @@ while (1):
print print
print_log2_hist(b["dist"], "kbytes") print_log2_hist(b["dist"], "kbytes")
b["dist"].clear()
if do_exit: if do_exit:
exit() exit()
...@@ -33,16 +33,10 @@ except: ...@@ -33,16 +33,10 @@ except:
# format output # format output
while 1: while 1:
try: (task, pid, cpu, flags, ts, msg) = b.trace_readline_fields()
line = trace.readline().rstrip() (bytes_s, bflags_s, us_s) = msg.split()
except KeyboardInterrupt:
pass; exit() if int(bflags_s, 16) & REQ_WRITE:
prolog, time_s, colon, bytes_s, flags_s, us_s = \
line.rsplit(" ", 5)
time_s = time_s[:-1] # strip trailing ":"
flags = int(flags_s, 16)
if flags & REQ_WRITE:
type_s = "W" type_s = "W"
elif bytes_s == "0": # see blk_fill_rwbs() for logic elif bytes_s == "0": # see blk_fill_rwbs() for logic
type_s = "M" type_s = "M"
...@@ -50,4 +44,4 @@ while 1: ...@@ -50,4 +44,4 @@ while 1:
type_s = "R" type_s = "R"
ms = float(int(us_s, 10)) / 1000 ms = float(int(us_s, 10)) / 1000
print("%-18s %-2s %-7s %8.2f" % (time_s, type_s, bytes_s, ms)) print("%-18.9f %-2s %-7s %8.2f" % (ts, type_s, bytes_s, ms))
...@@ -45,9 +45,6 @@ dist_max = 64 ...@@ -45,9 +45,6 @@ dist_max = 64
# header # header
print("Tracing... Hit Ctrl-C to end.") print("Tracing... Hit Ctrl-C to end.")
last = {}
for i in range(1, dist_max + 1):
last[i] = 0
# functions # functions
stars_max = 38 stars_max = 38
...@@ -68,7 +65,7 @@ def print_log2_hist(dist, val_type): ...@@ -68,7 +65,7 @@ def print_log2_hist(dist, val_type):
val_max = 0 val_max = 0
for i in range(1, dist_max + 1): for i in range(1, dist_max + 1):
try: try:
val = dist[c_int(i)].value - last[i] val = dist[c_int(i)].value
if (val > 0): if (val > 0):
idx_max = i idx_max = i
if (val > val_max): if (val > val_max):
...@@ -83,10 +80,9 @@ def print_log2_hist(dist, val_type): ...@@ -83,10 +80,9 @@ def print_log2_hist(dist, val_type):
if (low == high): if (low == high):
low -= 1 low -= 1
try: try:
val = dist[c_int(i)].value - last[i] val = dist[c_int(i)].value
print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val, print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val,
stars_max, stars(val, val_max, stars_max))) stars_max, stars(val, val_max, stars_max)))
last[i] = dist[c_int(i)].value
except: except:
break break
...@@ -105,5 +101,6 @@ while (1): ...@@ -105,5 +101,6 @@ while (1):
print print
print_log2_hist(b["dist"], "usecs") print_log2_hist(b["dist"], "usecs")
b["dist"].clear()
if do_exit: if do_exit:
exit() exit()
...@@ -28,7 +28,6 @@ S_COUNT = c_int(1) ...@@ -28,7 +28,6 @@ S_COUNT = c_int(1)
print("Tracing... Ctrl-C to end.") print("Tracing... Ctrl-C to end.")
# output # output
last = 0
while (1): while (1):
try: try:
sleep(1) sleep(1)
...@@ -36,5 +35,5 @@ while (1): ...@@ -36,5 +35,5 @@ while (1):
exit() exit()
print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"), print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
(b["stats"][S_COUNT].value))) b["stats"][S_COUNT].value))
b["stats"].clear() b["stats"].clear()
...@@ -54,11 +54,9 @@ stat_types = { ...@@ -54,11 +54,9 @@ stat_types = {
# header # header
print("%-8s " % "TIME", end="") print("%-8s " % "TIME", end="")
last = {}
for stype in stat_types.keys(): for stype in stat_types.keys():
print(" %8s" % (stype + "/s"), end="") print(" %8s" % (stype + "/s"), end="")
idx = stat_types[stype] idx = stat_types[stype]
last[idx] = 0
print("") print("")
# output # output
...@@ -78,9 +76,9 @@ while (1): ...@@ -78,9 +76,9 @@ while (1):
for stype in stat_types.keys(): for stype in stat_types.keys():
idx = stat_types[stype] idx = stat_types[stype]
try: try:
delta = b["stats"][c_int(idx)].value - last[idx] val = b["stats"][c_int(idx)].value / interval
print(" %8d" % (delta / interval), end="") print(" %8d" % val, end="")
last[idx] = b["stats"][c_int(idx)].value
except: except:
print(" %8d" % 0, end="") print(" %8d" % 0, end="")
b["stats"].clear()
print("") print("")
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