Spdk/scripts/histogram.py
paul luse 17538bdc67 add (c) and SPDX header to python files as needed
per Intel policy to include file commit date using git cmd
below.  The policy does not apply to non-Intel (C) notices.

git log --follow -C90% --format=%ad --date default <file> | tail -1

and then pull just the year from the result.

Intel copyrights were not added to files where Intel either had
no contribution ot the contribution lacked substance (ie license
header updates, formatting changes, etc)

Note that several files in this patch didn't end the license/(c)
block with a blank comment line so these were added as the vast
majority of files do have this last blank line.  Simply there for
consistency.

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I6cd3f18d1b469d5ef249d26ddb2923ca6b970bd4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15208
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-11-10 08:28:53 +00:00

49 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2019 Intel Corporation
# All rights reserved.
#
import sys
import json
import base64
import struct
buf = sys.stdin.readlines()
json = json.loads(" ".join(buf))
histogram = base64.b64decode(json["histogram"])
bucket_shift = json["bucket_shift"]
tsc_rate = json["tsc_rate"]
print("Latency histogram")
print("==============================================================================")
print(" Range in us Cumulative IO count")
so_far = 0
bucket = 0
total = 1
for i in range(0, 64 - bucket_shift):
for j in range(0, (1 << bucket_shift)):
index = (((i << bucket_shift) + j) * 8)
total += int.from_bytes(histogram[index:index + 8], 'little')
for i in range(0, 64 - bucket_shift):
for j in range(0, (1 << bucket_shift)):
index = (((i << bucket_shift) + j)*8)
count = int.from_bytes(histogram[index:index + 8], 'little')
so_far += count
last_bucket = bucket
if i > 0:
bucket = (1 << (i + bucket_shift - 1))
bucket += ((j+1) << (i - 1))
else:
bucket = j+1
start = last_bucket * 1000 * 1000 / tsc_rate
end = bucket * 1000 * 1000 / tsc_rate
so_far_pct = so_far * 100.0 / total
if count > 0:
print("%9.3f - %9.3f: %9.4f%% (%9u)" % (start, end, so_far_pct, count))