]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Report all AsyncJob objects (mgr:jobs) (#1468)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Wed, 6 Sep 2023 02:32:22 +0000 (02:32 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 8 Sep 2023 01:24:22 +0000 (01:24 +0000)
This new cache manager report is useful in triage and test automation.
It complements mgr:objects, mgr:events, and mgr:filedescriptors reports.

src/Makefile.am
src/base/AsyncJob.cc
src/base/AsyncJob.h
src/main.cc

index 0e98936913fa60dda713ffd96de605ddf6bc0778..26ba97859d4295cdf1df5a580f83a64b58a4a215 100644 (file)
@@ -1691,6 +1691,7 @@ nodist_tests_testACLMaxUserIP_SOURCES = \
        String.cc \
        tests/stub_access_log.cc \
        tests/stub_cache_cf.cc \
+       tests/stub_cache_manager.cc \
        tests/stub_cbdata.cc \
        tests/stub_client_side.cc \
        tests/stub_debug.cc \
index bcaf45b693b9894b2bf5f7e7cfdb85a376e9ca93..5c63bc6b26cc1d7547fe1a36b377dcdeeacb911b 100644 (file)
 #include "base/AsyncCall.h"
 #include "base/AsyncJob.h"
 #include "base/AsyncJobCalls.h"
+#include "base/PackableStream.h"
 #include "base/TextException.h"
 #include "cbdata.h"
+#include "mem/PoolingAllocator.h"
 #include "MemBuf.h"
+#include "mgr/Registration.h"
+#include "Store.h"
 
 #include <ostream>
+#include <unordered_set>
 
 InstanceIdDefinitions(AsyncJob, "job");
 
+/// a set of all AsyncJob objects in existence
+static auto &
+AllJobs()
+{
+    static const auto jobs = new std::unordered_set<AsyncJob *, std::hash<AsyncJob *>, std::equal_to<AsyncJob *>, PoolingAllocator<AsyncJob *> >();
+    return *jobs;
+}
+
 void
 AsyncJob::Start(const Pointer &job)
 {
@@ -32,6 +45,7 @@ AsyncJob::AsyncJob(const char *aTypeName) :
 {
     debugs(93,5, "AsyncJob constructed, this=" << this <<
            " type=" << typeName << " [" << id << ']');
+    AllJobs().insert(this);
 }
 
 AsyncJob::~AsyncJob()
@@ -39,6 +53,7 @@ AsyncJob::~AsyncJob()
     debugs(93,5, "AsyncJob destructed, this=" << this <<
            " type=" << typeName << " [" << id << ']');
     assert(!started_ || swanSang_);
+    AllJobs().erase(this);
 }
 
 void AsyncJob::start()
@@ -179,3 +194,26 @@ const char *AsyncJob::status() const
     return buf.content();
 }
 
+void
+AsyncJob::ReportAllJobs(StoreEntry *e)
+{
+    PackableStream os(*e);
+    // this loop uses YAML syntax, but AsyncJob::status() still needs to be adjusted to use YAML
+    const char *indent = "    ";
+    for (const auto job: AllJobs()) {
+        os << indent << job->id << ":\n";
+        os << indent << indent << "type: '" << job->typeName << "'\n";
+        os << indent << indent << "status:" << job->status() << '\n';
+        if (!job->started_)
+            os << indent << indent << "started: false\n";
+        if (job->stopReason)
+            os << indent << indent << "stopped: '" << job->stopReason << "'\n";
+    }
+}
+
+void
+AsyncJob::RegisterWithCacheManager()
+{
+    Mgr::RegisterAction("jobs", "All AsyncJob objects", &AsyncJob::ReportAllJobs, 0, 1);
+}
+
index 32f83482f437f21194fb823995f66b996632bb22..93faee9884161601349ca9e8b544914032ea0312 100644 (file)
@@ -44,6 +44,8 @@ public:
     /// successfully (i.e. without throwing).
     static void Start(const Pointer &job);
 
+    static void RegisterWithCacheManager();
+
 protected:
     // XXX: temporary method to replace "delete this" in jobs-in-transition.
     // Will be replaced with calls to mustStop() when transition is complete.
@@ -76,6 +78,9 @@ protected:
     // external destruction prohibited to ensure swanSong() is called
     ~AsyncJob() override;
 
+    /// writes a cache manager report about all jobs existing in this worker
+    static void ReportAllJobs(StoreEntry *);
+
     const char *stopReason; ///< reason for forcing done() to be true
     const char *typeName; ///< kid (leaf) class name, for debugging
     AsyncCall::Pointer inCall; ///< the asynchronous call being handled, if any
index 41cfb194d830713d007e82e6a1cea53329ff47e2..1a78e1c205f85e4939af64cdf4ca5e031a57ed96 100644 (file)
@@ -1203,6 +1203,8 @@ mainInitialize(void)
     FwdState::initModule();
     SBufStatsAction::RegisterWithCacheManager();
 
+    AsyncJob::RegisterWithCacheManager();
+
     /* These use separate calls so that the comm loops can eventually
      * coexist.
      */