1#!/usr/bin/env python3 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6 7import sys 8import json 9import base64 10import struct 11 12buf = sys.stdin.readlines() 13json = json.loads(" ".join(buf)) 14histogram = base64.b64decode(json["histogram"]) 15bucket_shift = json["bucket_shift"] 16tsc_rate = json["tsc_rate"] 17 18print("Latency histogram") 19print("==============================================================================") 20print(" Range in us Cumulative IO count") 21 22so_far = 0 23bucket = 0 24total = 1 25 26for 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 31for 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