Skip to content

Commit 997e29f

Browse files
committed
update doc for dump_hdrh
Change-Id: Id0903709edb56d7fe78638071b4a0220b81916ad
1 parent c524bab commit 997e29f

File tree

5 files changed

+113
-34
lines changed

5 files changed

+113
-34
lines changed

README.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,45 @@ Just run tox without any argument (the first run will take more time as tox will
191191
lint: commands succeeded
192192
congratulations :)
193193
194+
Utility to dump an encoded histogram string (dump_hdrh)
195+
-------------------------------------------------------
196+
197+
You can dump any encoded histogram using the dump_hdrh tool (installed along with the package).
198+
199+
.. code::
200+
201+
$ dump_hdrh
202+
203+
Usage: dump_hdrh [<string encoded hdr histogram>]*
204+
205+
You can pass one or more histogram strings to the tools:
206+
207+
.. code::
208+
209+
$ dump_hdrh 'HISTFAAAACl4nJNpmSzMwMDAxQABzFCaEUzOmNZg/wEi0NzIyPSYlWmpGBMAh4gG4A=='
210+
211+
Dumping histogram: HISTFAAAACl4nJNpmSzMwMDAxQABzFCaEUzOmNZg/wEi0NzIyPSYlWmpGBMAh4gG4A==
212+
213+
Value Percentile TotalCount 1/(1-Percentile)
214+
215+
139647.000 0.000000000000 1 1.00
216+
139647.000 0.100000000000 1 1.11
217+
139647.000 0.190000000000 1 1.23
218+
139647.000 0.271000000000 1 1.37
219+
187135.000 0.343900000000 2 1.52
220+
187135.000 0.409510000000 2 1.69
221+
187135.000 0.468559000000 2 1.88
222+
187135.000 0.521703100000 2 2.09
223+
187135.000 0.569532790000 2 2.32
224+
187135.000 0.612579511000 2 2.58
225+
187135.000 0.651321559900 2 2.87
226+
477695.000 0.686189403910 3 3.19
227+
477695.000 1.000000000000 3
228+
#[Mean = 268074.667, StdDeviation = 149397.390]
229+
#[Max = 477695.000, TotalCount = 3.000]
230+
#[Buckets = 14, SubBuckets = 2048]
231+
232+
194233
Aggregation of Distributed Histograms
195234
-------------------------------------
196235

hdrh/dump.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
'''
3+
Utility to dump any hdrh histogram from encoded string
4+
5+
Written by Alec Hothan
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
'''
19+
import sys
20+
21+
from hdrh.histogram import HdrHistogram
22+
23+
24+
def main():
25+
args = sys.argv[1:]
26+
if args:
27+
encoded_histograms = args
28+
for hdrh in encoded_histograms:
29+
print('\nDumping histogram: ' + hdrh + '\n')
30+
HdrHistogram.dump(hdrh)
31+
else:
32+
print('\nUsage: %s [<string encoded hdr histogram>]*\n' % (sys.argv[0]))
33+
34+
35+
if __name__ == '__main__':
36+
main()

hdrh/histogram.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,26 @@ def output_percentile_distribution(self,
607607
self.significant_figures).encode() % (max, total))
608608
out_file.write(b'#[Buckets = %12d, SubBuckets = %12d]\n' % (
609609
self.bucket_count, self.sub_bucket_count))
610+
611+
@staticmethod
612+
def dump(encoded_histogram, output=None,
613+
output_value_unit_scaling_ratio=1):
614+
"""Dump a string encoded histogram to the provider output
615+
616+
param output: a writable buffer output,
617+
if None output will be written to stdout
618+
param output_value_unit_scaling_ratio: scaling ratio, the amount
619+
by which values will be divided for display, defaults to 1
620+
"""
621+
histogram = HdrHistogram.decode(encoded_histogram)
622+
623+
if output is None:
624+
# sys.stdout.buffer will raise AttributeError in python 2.7
625+
try:
626+
# python 3 requires .buffer to write bytes
627+
output = sys.stdout.buffer
628+
except AttributeError:
629+
# in python 2.7, bytes can be writtent to sys.stdout
630+
output = sys.stdout
631+
histogram.output_percentile_distribution(output,
632+
output_value_unit_scaling_ratio)

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ classifier =
2121
[files]
2222
packages =
2323
hdrh
24+
25+
[entry_points]
26+
console_scripts =
27+
dump_hdrh = hdrh.dump:main
28+
29+
[wheel]
30+
universal = 1

test/test_hdrh_dump.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
'''
23
Test code for the python version of HdrHistogram.
34
@@ -25,40 +26,13 @@
2526
from hdrh.histogram import HdrHistogram
2627

2728

28-
ENCODE_SAMPLES_HDRHISTOGRAM_C = [
29-
# standard Hdr test histogram
30-
'HISTFAAAACF4nJNpmSzMwMDAzAABMJoRTM6Y1mD/ASLwN5oJAFuQBYU=',
31-
'HISTFAAAACh4nJNpmSzMwMDAyQABzFCaEUzOmNZg/wEisL2Kaasc00ImJgCC8Qbe'
32-
]
33-
34-
def dump_histogram(encoded_histogram):
35-
print('\nDumping histogram: ' + encoded_histogram)
36-
histogram = HdrHistogram.decode(encoded_histogram)
37-
38-
histogram.output_percentile_distribution(open(os.devnull, 'wb'), 1)
39-
# sys.stdout.buffer will raise AttributeError in python 2.7
40-
try:
41-
# python 3 requires .buffer to write bytes
42-
output = sys.stdout.buffer
43-
except AttributeError:
44-
# in python 2.7, bytes can be writtent to sys.stdout
45-
output = sys.stdout
46-
histogram.output_percentile_distribution(output, 1)
47-
4829
def test_dump_histogram():
30+
ENCODE_SAMPLES_HDRHISTOGRAM_C = [
31+
# standard Hdr test histogram
32+
'HISTFAAAACF4nJNpmSzMwMDAzAABMJoRTM6Y1mD/ASLwN5oJAFuQBYU=',
33+
'HISTFAAAACh4nJNpmSzMwMDAyQABzFCaEUzOmNZg/wEisL2Kaasc00ImJgCC8Qbe'
34+
]
4935
for hdrh in ENCODE_SAMPLES_HDRHISTOGRAM_C:
50-
dump_histogram(hdrh)
51-
52-
def main():
53-
args = sys.argv[1:]
54-
if args:
55-
encoded_histograms = args
56-
else:
57-
encoded_histograms = ENCODE_SAMPLES_HDRHISTOGRAM_C
58-
59-
for hdrh in encoded_histograms:
60-
dump_histogram(hdrh)
61-
36+
HdrHistogram.dump(hdrh, output=open(os.devnull, 'wb'))
37+
HdrHistogram.dump(hdrh)
6238

63-
if __name__ == '__main__':
64-
main()

0 commit comments

Comments
 (0)