From 7debaaca4854b3e46dfecb1175793c790914519d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 19 Aug 2023 19:06:44 +0200 Subject: [PATCH] Activity-Lang: adaptor to watch existing Activity's activation due to technical limitations this requires to wire the adaptor as replacement for the subject Activity, so that it can capture and log the activation, and then pass it on to its watched subject --- src/vault/gear/activity-lang.cpp | 2 +- src/vault/gear/activity.hpp | 7 ++--- src/vault/gear/job.h | 12 ++++++++ src/vault/gear/nop-job-functor.hpp | 8 +++++ tests/vault/gear/activity-detector-test.cpp | 34 ++++++++++++++++++++- tests/vault/gear/activity-detector.hpp | 25 ++++++++++++++- wiki/thinkPad.ichthyo.mm | 25 ++++++++------- 7 files changed, 95 insertions(+), 18 deletions(-) diff --git a/src/vault/gear/activity-lang.cpp b/src/vault/gear/activity-lang.cpp index 5e8d2e16b..19f2723c6 100644 --- a/src/vault/gear/activity-lang.cpp +++ b/src/vault/gear/activity-lang.cpp @@ -88,7 +88,7 @@ namespace gear { { switch (verb_) { case INVOKE: - return util::toString(data_.invocation.task) + return util::showPtr (data_.invocation.task) + ", " + util::toString(TimeValue{data_.invocation.time}); case WORKSTART: diff --git a/src/vault/gear/activity.hpp b/src/vault/gear/activity.hpp index 34a301128..9a53e7060 100644 --- a/src/vault/gear/activity.hpp +++ b/src/vault/gear/activity.hpp @@ -349,6 +349,9 @@ namespace gear { /// diagnostic representation operator std::string() const; + std::string showVerb() const; + std::string showData() const; + /********************************************************//** * Core Operation: _Activate_ and _perform_ this Activity. @@ -464,10 +467,6 @@ namespace gear { { return executionCtx.tick (now); } - - - std::string showVerb() const; - std::string showData() const; }; diff --git a/src/vault/gear/job.h b/src/vault/gear/job.h index 5ffa45c4c..308e31dd6 100644 --- a/src/vault/gear/job.h +++ b/src/vault/gear/job.h @@ -188,6 +188,7 @@ typedef lumiera_jobDescriptor* LumieraJobDescriptor; #ifdef __cplusplus /* ============== C++ Interface ================= */ +#include @@ -207,6 +208,17 @@ namespace gear { { public: virtual ~JobFunctor(); ///< this is an interface + + virtual std::string + diagnostic() const + { + return "JobFunctor"; + } + + operator std::string() const + { + return diagnostic(); + } }; /** * Interface of the closure for frame rendering jobs. diff --git a/src/vault/gear/nop-job-functor.hpp b/src/vault/gear/nop-job-functor.hpp index e17862409..d032c4768 100644 --- a/src/vault/gear/nop-job-functor.hpp +++ b/src/vault/gear/nop-job-functor.hpp @@ -40,6 +40,8 @@ #include "vault/gear/job.h" #include "lib/time/timevalue.hpp" +#include + namespace vault{ namespace gear { @@ -65,6 +67,12 @@ namespace gear { return META_JOB; } + std::string + diagnostic() const override + { + return "NopJobFunctor"; + } + InvocationInstanceID buildInstanceID (HashVal) const override { diff --git a/tests/vault/gear/activity-detector-test.cpp b/tests/vault/gear/activity-detector-test.cpp index 3832db478..04ff7d7f4 100644 --- a/tests/vault/gear/activity-detector-test.cpp +++ b/tests/vault/gear/activity-detector-test.cpp @@ -242,6 +242,7 @@ namespace test { ActivityDetector detector; auto someID = "trap-" + randStr(4); Activity& probe = detector.buildActivationProbe (someID); + CHECK (Activity::HOOK == probe.verb_); Time realTime = RealClock::now(); probe.activate (realTime, detector.executionCtx); @@ -252,12 +253,43 @@ namespace test { /** @test TODO diagnostic setup to detect Activity activation and propagation - * @todo WIP 8/23 🔁 define ⟶ implement + * @todo WIP 8/23 ✔ define 🔁 implement */ void watch_activationTap() { ActivityDetector detector; + + Time nomTime{99,11}; + Activity feed{size_t{12},size_t{34}}; + Activity feed2{size_t{56},size_t{78}}; + feed.next = &feed2; + string jobID = "job-" + randStr(4); + Activity invoke{detector.buildMockJobFunctor(jobID), nomTime, feed}; + + Time t1{0,1,1}; + CHECK (activity::PASS == invoke.activate (t1, detector.executionCtx)); + CHECK (detector.verifyInvocation (jobID).arg(nomTime, 12)); + + // decorate the INVOKE-Activity with an ActivationTap + Activity& tap = detector.buildActivationTap (invoke); + CHECK (tap.next == invoke.next); + + ++detector; + Time t2{0,2,2}; + // now activate through the Tap.... + tap.activate(t2, detector.executionCtx); + CHECK (detector.verifySeqIncrement(1) // ==> the ActivationTap "tap-INVOKE" reports and passes activation + .beforeInvocation("tap-INVOKE").seq(1).arg("JobFun-ActivityDetector."+jobID) + .beforeInvocation(jobID).seq(1).arg(nomTime,12)); + + // WARNING: can still activate the watched subject directly... + ++detector; + Time t3{0,3,3}; + invoke.activate (t3, detector.executionCtx); + CHECK (detector.verifyInvocation(jobID).seq(2)); // subject invoked + CHECK (detector.ensureNoInvocation("tap-INVOKE").seq(2) // but invocation not detected by ActivationTap + .beforeInvocation(jobID).seq(2)); } diff --git a/tests/vault/gear/activity-detector.hpp b/tests/vault/gear/activity-detector.hpp index c0cffbf50..434044de1 100644 --- a/tests/vault/gear/activity-detector.hpp +++ b/tests/vault/gear/activity-detector.hpp @@ -336,6 +336,11 @@ namespace test { mockOperation_(Time{TimeValue{param.nominalTime}}, param.invoKey.part.a); } + string diagnostic() const override + { + return "JobFun-"+string{mockOperation_}; + } + public: MockJobFunctor (MockOp mockedJobOperation) : mockOperation_{move (mockedJobOperation)} @@ -379,11 +384,17 @@ namespace test { } public: - explicit ActivityProbe (string id, EventLog& masterLog, uint const& invocationSeqNr) : Activity{*this, 0} , log_{id, masterLog, invocationSeqNr} { } + + ActivityProbe (Activity const& subject, string id, EventLog& masterLog, uint const& invocationSeqNr) + : Activity{*this, reinterpret_cast (&subject)} + , log_{id, masterLog, invocationSeqNr} + { + next = subject.next; + } operator string() const { @@ -464,12 +475,24 @@ namespace test { buildDiagnosticFun (id)); } + /** build a rigged HOOK-Activity to record each invocation */ Activity& buildActivationProbe (string id) { return mockActs_.emplace_back (id, eventLog_, invocationSeq_); } + /** build ActivationProbe to record each activation before passing it to the subject */ + Activity& + buildActivationTap (Activity const& subject, string id ="") + { + return mockActs_.emplace_back (subject + ,isnil(id)? "tap-"+subject.showVerb()+util::showAddr(subject) + : id + ,eventLog_ + ,invocationSeq_); + } + struct FakeExecutionCtx; using SIG_post = activity::Proc(Time, Activity&, FakeExecutionCtx&); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index fe0cf996f..d363af69d 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -82189,9 +82189,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - + @@ -82202,12 +82202,12 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - + @@ -82240,16 +82240,19 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - - - + + + + - + - + - + + + +