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

Supports to strip leading zero on print_log2_hist function #1226

Merged
merged 10 commits into from
Jun 29, 2017
Next Next commit
Add srtip_leading_zero to print_log2_hist function
  • Loading branch information
Taekho Nam committed Jun 20, 2017
commit fe2f15e2e5dadb8f1a802f35488352357b152c02
23 changes: 15 additions & 8 deletions src/python/bcc/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _stars(val, val_max, width):
return text


def _print_log2_hist(vals, val_type):
def _print_log2_hist(vals, val_type, strip_leading_zero=None):
global stars_max
log2_dist_max = 64
idx_max = -1
Expand All @@ -74,15 +74,23 @@ def _print_log2_hist(vals, val_type):
stars = int(stars_max / 2)

if idx_max > 0:
print(header % val_type);
print(header % val_type)

for i in range(1, idx_max + 1):
low = (1 << i) >> 1
high = (1 << i) - 1
if (low == high):
low -= 1
val = vals[i]
print(body % (low, high, val, stars,
_stars(val, val_max, stars)))

if strip_leading_zero:
if val:
print(body % (low, high, val, stars,
_stars(val, val_max, stars)))
strip_leading_zero = None
else:
print(body % (low, high, val, stars,
_stars(val, val_max, stars)))

def _print_linear_hist(vals, val_type):
global stars_max
Expand Down Expand Up @@ -281,7 +289,7 @@ def next(self, key):
return next_key

def print_log2_hist(self, val_type="value", section_header="Bucket ptr",
section_print_fn=None, bucket_fn=None):
section_print_fn=None, bucket_fn=None, strip_leading_zero=None):
"""print_log2_hist(val_type="value", section_header="Bucket ptr",
section_print_fn=None, bucket_fn=None)

Expand Down Expand Up @@ -312,12 +320,12 @@ def print_log2_hist(self, val_type="value", section_header="Bucket ptr",
section_print_fn(bucket)))
else:
print("\n%s = %r" % (section_header, bucket))
_print_log2_hist(vals, val_type)
_print_log2_hist(vals, val_type, strip_leading_zero)
else:
vals = [0] * log2_index_max
for k, v in self.items():
vals[k.value] = v.value
_print_log2_hist(vals, val_type)
_print_log2_hist(vals, val_type, strip_leading_zero)

def print_linear_hist(self, val_type="value", section_header="Bucket ptr",
section_print_fn=None, bucket_fn=None):
Expand Down Expand Up @@ -709,4 +717,3 @@ def __delitem__(self, key):

def clear(self):
pass