Skip to content

Commit

Permalink
improve code by utilizing .clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Aug 26, 2015
1 parent 0c7ab87 commit ef2452d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
9 changes: 3 additions & 6 deletions examples/bitehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ def usage():

# header
print("Tracing... Hit Ctrl-C to end.")
last = {}
for i in range(1, dist_max + 1):
last[i] = 0

# functions
stars_max = 38
Expand All @@ -67,7 +64,7 @@ def print_log2_hist(dist, val_type):
val_max = 0
for i in range(1, dist_max + 1):
try:
val = dist[c_int(i)].value - last[i]
val = dist[c_int(i)].value
if (val > 0):
idx_max = i
if (val > val_max):
Expand All @@ -82,10 +79,9 @@ def print_log2_hist(dist, val_type):
if (low == high):
low -= 1
try:
val = dist[c_int(i)].value - last[i]
val = dist[c_int(i)].value
print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val,
stars_max, stars(val, val_max, stars_max)))
last[i] = dist[c_int(i)].value
except:
break

Expand All @@ -104,5 +100,6 @@ def print_log2_hist(dist, val_type):

print
print_log2_hist(b["dist"], "kbytes")
b["dist"].clear()
if do_exit:
exit()
9 changes: 3 additions & 6 deletions examples/vfsreadlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def usage():

# header
print("Tracing... Hit Ctrl-C to end.")
last = {}
for i in range(1, dist_max + 1):
last[i] = 0

# functions
stars_max = 38
Expand All @@ -68,7 +65,7 @@ def print_log2_hist(dist, val_type):
val_max = 0
for i in range(1, dist_max + 1):
try:
val = dist[c_int(i)].value - last[i]
val = dist[c_int(i)].value
if (val > 0):
idx_max = i
if (val > val_max):
Expand All @@ -83,10 +80,9 @@ def print_log2_hist(dist, val_type):
if (low == high):
low -= 1
try:
val = dist[c_int(i)].value - last[i]
val = dist[c_int(i)].value
print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val,
stars_max, stars(val, val_max, stars_max)))
last[i] = dist[c_int(i)].value
except:
break

Expand All @@ -105,5 +101,6 @@ def print_log2_hist(dist, val_type):

print
print_log2_hist(b["dist"], "usecs")
b["dist"].clear()
if do_exit:
exit()
3 changes: 1 addition & 2 deletions tools/pidpersec
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ S_COUNT = c_int(1)
print("Tracing... Ctrl-C to end.")

# output
last = 0
while (1):
try:
sleep(1)
except KeyboardInterrupt:
exit()

print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
(b["stats"][S_COUNT].value)))
b["stats"][S_COUNT].value))
b["stats"].clear()
8 changes: 3 additions & 5 deletions tools/vfsstat
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ stat_types = {

# header
print("%-8s " % "TIME", end="")
last = {}
for stype in stat_types.keys():
print(" %8s" % (stype + "/s"), end="")
idx = stat_types[stype]
last[idx] = 0
print("")

# output
Expand All @@ -78,9 +76,9 @@ while (1):
for stype in stat_types.keys():
idx = stat_types[stype]
try:
delta = b["stats"][c_int(idx)].value - last[idx]
print(" %8d" % (delta / interval), end="")
last[idx] = b["stats"][c_int(idx)].value
val = b["stats"][c_int(idx)].value / interval
print(" %8d" % val, end="")
except:
print(" %8d" % 0, end="")
b["stats"].clear()
print("")

0 comments on commit ef2452d

Please sign in to comment.