1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: BSD-3-Clause 3 # Copyright (C) 2019 Intel Corporation 4 # All rights reserved. 5 # 6 7 import sys 8 import json 9 import base64 10 import struct 11 12 buf = sys.stdin.readlines() 13 json = json.loads(" ".join(buf)) 14 histogram = base64.b64decode(json["histogram"]) 15 bucket_shift = json["bucket_shift"] 16 tsc_rate = json["tsc_rate"] 17 18 print("Latency histogram") 19 print("==============================================================================") 20 print(" Range in us Cumulative IO count") 21 22 so_far = 0 23 bucket = 0 24 total = 1 25 26 for i in range(0, 64 - bucket_shift): 27 for j in range(0, (1 << bucket_shift)): 28 index = (((i << bucket_shift) + j) * 8) 29 total += int.from_bytes(histogram[index:index + 8], 'little') 30 31 for i in range(0, 64 - bucket_shift): 32 for j in range(0, (1 << bucket_shift)): 33 index = (((i << bucket_shift) + j)*8) 34 count = int.from_bytes(histogram[index:index + 8], 'little') 35 so_far += count 36 last_bucket = bucket 37 38 if i > 0: 39 bucket = (1 << (i + bucket_shift - 1)) 40 bucket += ((j+1) << (i - 1)) 41 else: 42 bucket = j+1 43 44 start = last_bucket * 1000 * 1000 / tsc_rate 45 end = bucket * 1000 * 1000 / tsc_rate 46 so_far_pct = so_far * 100.0 / total 47 if count > 0: 48 print("%9.3f - %9.3f: %9.4f%% (%9u)" % (start, end, so_far_pct, count)) 49