From 7fedc047b4f6441cdc0c47a3ce5caa6e7db9d241 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Tue, 5 Mar 2024 08:28:02 +0100
Subject: [PATCH] get_own_cpu_usage() will now work on Windows

---
 CHANGELOG.md                                  |  1 +
 docs/instrumentation/memory.rst               | 35 ++++++++++---------
 satella/instrumentation/cpu_time/collector.py |  2 +-
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c3a0f665..e4201c01 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,4 +3,5 @@
 * added DeferredValue
 * satella.coding.Context are considered experimental
 * added a way to register an object to be cleaned up via MemoryPressureManager
+* fixed get_own_cpu_usage() to work on Windows
 
diff --git a/docs/instrumentation/memory.rst b/docs/instrumentation/memory.rst
index 589ab711..167fb884 100644
--- a/docs/instrumentation/memory.rst
+++ b/docs/instrumentation/memory.rst
@@ -10,12 +10,28 @@ from Satella solves that problem.
 
 .. autofunction:: satella.instrumentation.memory.get_size
 
-.. warning:: Using these conditions will spawn a daemon thread to monitor the memory usage
-    in the background.
+install_force_gc_collect
+------------------------
+
+If you want, you can install a GC handler that will
+force a complete GC collection upon entering given severity level.
+
+.. autofunction:: satella.instrumentation.memory.install_force_gc_collect
+
+Dumping memory information
+--------------------------
+
+.. autofunction:: satella.instrumentation.memory.dump_memory_on
+
+.. autofunction:: satella.instrumentation.memory.install_dump_memory_on
+
 
 Defining severity levels
 ------------------------
 
+.. warning:: Using following routines will spawn a daemon thread to monitor the memory usage
+    in the background.
+
 To define a severity level, use the following classes:
 
 .. autoclass:: satella.instrumentation.memory.GlobalAbsoluteValue
@@ -57,18 +73,3 @@ that level 1 is still in effect. You can register your handlers here:
 Note that you can also register objects to have their methods called on entering a memory
 severity level, if these objects have a way to to for example drop some data onto disk and
 decrease memory usage via :meth:`~satella.instrumentation.memory.MemoryPressureManager.cleanup_on_entered`.
-
-install_force_gc_collect
-------------------------
-
-If you want, you can install a GC handler that will
-force a complete GC collection upon entering given severity level.
-
-.. autofunction:: satella.instrumentation.memory.install_force_gc_collect
-
-Dumping memory information
---------------------------
-
-.. autofunction:: satella.instrumentation.memory.dump_memory_on
-
-.. autofunction:: satella.instrumentation.memory.install_dump_memory_on
diff --git a/satella/instrumentation/cpu_time/collector.py b/satella/instrumentation/cpu_time/collector.py
index c041ab50..95d244c6 100644
--- a/satella/instrumentation/cpu_time/collector.py
+++ b/satella/instrumentation/cpu_time/collector.py
@@ -19,7 +19,7 @@ DEFAULT_WINDOW_SECONDS = '10s'
 
 pCPUtimes = collections.namedtuple('pcputimes',
                                    ['user', 'system', 'children_user', 'children_system',
-                                    'iowait'])
+                                    'iowait'], defaults=[0, 0, 0, 0, 0])
 
 
 class _CPUProfileBuilderThread(SingleStartThread):
-- 
GitLab