From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 5/5] trace-cruncher: Add kernel histogram example
Date: Tue, 7 Dec 2021 16:28:11 +0200 [thread overview]
Message-ID: <20211207142811.398929-6-y.karadz@gmail.com> (raw)
In-Reply-To: <20211207142811.398929-1-y.karadz@gmail.com>
This is a very basic possible example, demonstration the usage of
the new APIs for kernel histograms.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
examples/hist.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100755 examples/hist.py
diff --git a/examples/hist.py b/examples/hist.py
new file mode 100755
index 0000000..d668039
--- /dev/null
+++ b/examples/hist.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: CC-BY-4.0
+
+Copyright 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import sys
+import time
+
+import tracecruncher.ftracepy as ft
+
+inst_name = 'khist_example'
+
+cmds = ['start', 'stop', 'show', 'continue', 'clear', 'close']
+
+def get_hist():
+ hist = ft.hist(name='h1',
+ system='kmem',
+ event='kmalloc',
+ axes={'call_site': 'sym',
+ 'bytes_req': 'n'})
+
+ hist.add_value(value='bytes_alloc')
+ hist.sort_keys(keys=['bytes_req', 'bytes_alloc'])
+ hist.sort_key_direction(sort_key='bytes_req', direction='desc')
+
+ return hist
+
+if __name__ == "__main__":
+ if len(sys.argv) != 2:
+ sys.exit(1)
+
+ if not sys.argv[1].isdigit() and not sys.argv[1] in cmds:
+ sys.exit(1)
+
+ arg1 = sys.argv[1]
+ if arg1.isdigit() or arg1 == 'start':
+ inst = ft.create_instance(name=inst_name)
+ hist = get_hist()
+ hist.start(inst)
+
+ if arg1.isdigit():
+ time.sleep(int(arg1))
+ hist.stop(inst)
+ print(hist.read(inst))
+ hist.close(inst)
+ else:
+ ft.detach(inst)
+ else:
+ inst = ft.find_instance(name=inst_name)
+ hist = get_hist()
+
+ if arg1 == 'stop':
+ hist.stop(inst)
+ elif arg1 == 'show':
+ print(hist.read(inst))
+ elif arg1 == 'continue':
+ hist.resume(inst)
+ elif arg1 == 'clear':
+ hist.clear(inst)
+
+ if arg1 == 'close':
+ ft.attach(inst)
+ hist.close(inst)
--
2.32.0
prev parent reply other threads:[~2021-12-07 14:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-07 14:28 [PATCH 0/5] trace-cruncher: Kernel histograms Yordan Karadzhov (VMware)
2021-12-07 14:28 ` [PATCH 1/5] trace-cruncher: Define Python type for trace histograms Yordan Karadzhov (VMware)
2021-12-07 14:28 ` [PATCH 2/5] trace-cruncher: Define constructor " Yordan Karadzhov (VMware)
2021-12-07 14:28 ` [PATCH 3/5] trace-cruncher: Add APIs to setup a histogram Yordan Karadzhov (VMware)
2021-12-07 14:28 ` [PATCH 4/5] trace-cruncher: Add APIs for histogram control Yordan Karadzhov (VMware)
2021-12-07 14:28 ` Yordan Karadzhov (VMware) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211207142811.398929-6-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).