From 39066900773e7857faf2d02e7ed51b71d219d97d Mon Sep 17 00:00:00 2001 From: godosa Date: Tue, 6 Oct 2026 23:39:36 +0200 Subject: godosa-engine: initial public history --- scripts/test_thread_cpu.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/test_thread_cpu.py (limited to 'scripts/test_thread_cpu.py') diff --git a/scripts/test_thread_cpu.py b/scripts/test_thread_cpu.py new file mode 100644 index 0000000..f60a2d0 --- /dev/null +++ b/scripts/test_thread_cpu.py @@ -0,0 +1,24 @@ +import sys +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import thread_cpu as tc + + +class ThreadCpuTests(unittest.TestCase): + def test_groups_by_name_and_counts_new_threads_from_zero(self): + before = {"1": ("main", 100), "2": ("worker", 10)} + after = {"1": ("main", 150), "2": ("worker", 20), "3": ("worker", 30)} + rows = tc.per_name(before, after, seconds=1.0, hz=100) + self.assertEqual(rows[0], ("main", 50.0, 1)) + self.assertEqual(rows[1], ("worker", 40.0, 2)) # 10 + 30 ticks + + def test_samples_this_process(self): + import os + threads = tc.sample(os.getpid()) + self.assertIn(str(os.getpid()), threads) + + +if __name__ == "__main__": + unittest.main() -- cgit