Skip to contentSkip to conversation

process: Add profile logging for main loop

PATCH New Richard Purdie 1 participant 1 message Feb 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 process: Add profile logging for main loop

When the idle/main loop was added, we didn't include profiling information for it. There is a performance issue in there, add logging for it.

---
 lib/bb/server/process.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
lib/bb/server/process.py +16 -0
index 6d77ce4786..1ca8e02ba0 100644
@@ -402,6 +402,22 @@ class ProcessServer():
                 serverlog("".join(msg))
 
     def idle_thread(self):
+        if self.cooker.configuration.profile:
+            try:
+                import cProfile as profile
+            except:
+                import profile
+            prof = profile.Profile()
+
+            ret = profile.Profile.runcall(prof, self.idle_thread_internal)
+
+            prof.dump_stats("profile-mainloop.log")
+            bb.utils.process_profilelog("profile-mainloop.log")
+            serverlog("Raw profiling information saved to profilemainloop.log and processed statistics to profilemainloop.log.processed")
+        else:
+            self.idle_thread_internal()
+
+    def idle_thread_internal(self):
         def remove_idle_func(function):
             with bb.utils.lock_timeout(self._idlefuncsLock):
                 del self._idlefuns[function]
Signature · 1 line
2.40.1