All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace-cruncher: Add histogram tests
@ 2021-12-13 14:37 Yordan Karadzhov (VMware)
  0 siblings, 0 replies; only message in thread
From: Yordan Karadzhov (VMware) @ 2021-12-13 14:37 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

APIs for kernel tracing histograms have been added.
Here we add the corresponding test cases.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 .../tests/1_unit/test_01_ftracepy_unit.py     | 102 ++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
index 8a5881e..7b344e2 100644
--- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
+++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
@@ -480,5 +480,107 @@ class TracingOnTestCase(unittest.TestCase):
         self.assertTrue(err in str(context.exception))
 
 
+class HistTestCase(unittest.TestCase):
+    def test_hist_create(self):
+        inst = ft.create_instance(instance_name)
+        sys = 'kmem'
+        evt = 'kmalloc'
+        tgr_file = inst.dir() + '/events/' +  sys + '/' + evt + '/trigger'
+
+        f = open(tgr_file)
+
+        hist = ft.hist(system=sys, event=evt, key='call_site', type='sym')
+        hist.stop(inst)
+        h_buff = f.read()
+        self.assertTrue('hist:keys=call_site.sym' in h_buff)
+        hist.close(inst)
+
+        hist = ft.hist(system=sys, event=evt,
+                       axes={'call_site': 'sym',
+                             'bytes_alloc': 'n'})
+        hist.stop(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue('hist:keys=call_site.sym,bytes_alloc' in h_buff)
+        hist.close(inst)
+
+        hist = ft.hist(name='h2d', system=sys, event=evt,
+                       axes={'bytes_req': 'log',
+                             'bytes_alloc': 'h'})
+        hist.stop(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue('hist:name=h2d:keys=bytes_req.log2,bytes_alloc.hex' in h_buff)
+
+        hist.close(inst)
+        f.close()
+
+    def test_hist_setup(self):
+        inst = ft.create_instance(instance_name)
+        sys = 'kmem'
+        evt = 'kmalloc'
+        tgr_file = inst.dir() + '/events/' +  sys + '/' + evt + '/trigger'
+
+        f = open(tgr_file)
+
+        hist = ft.hist(system=sys, event=evt,
+                       axes={'call_site': 'sym',
+                             'bytes_alloc': 'n'})
+
+        hist.add_value(value='bytes_req')
+        hist.stop(inst)
+        h_buff = f.read()
+        self.assertTrue(':vals=hitcount,bytes_req' in h_buff)
+
+        hist.sort_keys(keys=['bytes_req', 'bytes_alloc'])
+        hist.stop(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue(':sort=bytes_req,bytes_alloc' in h_buff)
+
+        hist.sort_key_direction('bytes_req', 'desc')
+        hist.stop(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue(':sort=bytes_req.descending,bytes_alloc' in str(h_buff))
+
+        hist.close(inst)
+        f.close()
+
+    def test_hist_ctrl(self):
+        inst = ft.create_instance(instance_name)
+        sys = 'kmem'
+        evt = 'kmalloc'
+        tgr_file = inst.dir() + '/events/' +  sys + '/' + evt + '/trigger'
+
+        f = open(tgr_file)
+
+        hist = ft.hist(system=sys, event=evt,
+                       axes={'call_site': 'sym',
+                             'bytes_alloc': 'n'})
+
+        hist.start(inst)
+        h_buff = f.read()
+        self.assertTrue('[active]' in h_buff)
+
+        hist.stop(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue('[paused]' in h_buff)
+
+        hist.resume(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue('[active]' in h_buff)
+
+        h_buff = hist.read(inst)
+        self.assertTrue('Totals:' in h_buff)
+
+        hist.close(inst)
+        f.seek(0)
+        h_buff = f.read()
+        self.assertTrue('Available triggers:' in h_buff)
+        f.close()
+
 if __name__ == '__main__':
     unittest.main()
-- 
2.32.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-13 14:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 14:37 [PATCH] trace-cruncher: Add histogram tests Yordan Karadzhov (VMware)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.