Scheduler-test: implement the simplest case for the instrumentation
...which is to account for the cumulative time spent in code
marked by bracketed measurement calls ("enter" ... "leave")
This commit is contained in:
parent
754b3a2ea6
commit
08847ae283
3 changed files with 119 additions and 42 deletions
|
|
@ -50,6 +50,7 @@
|
|||
|
||||
//#include "lib/meta/function.hpp"
|
||||
#include "lib/nocopy.hpp"
|
||||
#include "lib/iter-explorer.hpp"
|
||||
|
||||
//#include <utility>
|
||||
#include <cstdint>
|
||||
|
|
@ -57,6 +58,7 @@
|
|||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
|
@ -82,7 +84,7 @@ namespace lib {
|
|||
|
||||
struct Inc
|
||||
{
|
||||
Instance when{};
|
||||
Instance when;
|
||||
uint8_t thread :8;
|
||||
uint8_t caseID :8;
|
||||
bool isLeave :1;
|
||||
|
|
@ -110,17 +112,28 @@ namespace lib {
|
|||
return threadID;
|
||||
}
|
||||
|
||||
Sequence
|
||||
getMySequence()
|
||||
Sequence&
|
||||
getMySequence(uint8_t threadID)
|
||||
{
|
||||
uint8_t id{getMySlot()};
|
||||
if (id >= rec_.size())
|
||||
if (threadID >= rec_.size())
|
||||
{
|
||||
rec_.reserve (id);
|
||||
for (size_t i = rec_.size(); i < id; ++i)
|
||||
rec_.reserve (threadID+1);
|
||||
for (size_t i = rec_.size(); i < threadID+1u; ++i)
|
||||
rec_.emplace_back();
|
||||
}
|
||||
return rec_[id];
|
||||
return rec_[threadID];
|
||||
}
|
||||
|
||||
void
|
||||
addEntry(uint8_t caseID, bool isLeave)
|
||||
{
|
||||
uint8_t threadID{getMySlot()};
|
||||
Sequence& seq = getMySequence(threadID);
|
||||
Inc& incidence = seq.emplace_back();
|
||||
incidence.when = Clock::now();
|
||||
incidence.thread = threadID;
|
||||
incidence.caseID = caseID;
|
||||
incidence.isLeave = isLeave;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -151,28 +164,74 @@ namespace lib {
|
|||
|
||||
/* ===== Measurement API ===== */
|
||||
|
||||
void
|
||||
markEnter(uint8_t caseID =0)
|
||||
{
|
||||
UNIMPLEMENTED ("Incidence measurement");
|
||||
}
|
||||
|
||||
void
|
||||
markLeave(uint8_t caseID =0)
|
||||
{
|
||||
UNIMPLEMENTED ("Incidence measurement");
|
||||
}
|
||||
void markEnter(uint8_t caseID =0) { addEntry(caseID, false); }
|
||||
void markLeave(uint8_t caseID =0) { addEntry(caseID, true); }
|
||||
|
||||
|
||||
/* ===== Evaluations ===== */
|
||||
|
||||
struct Statistic
|
||||
{
|
||||
double cumulatedTime{0};
|
||||
};
|
||||
|
||||
Statistic evaluate();
|
||||
|
||||
double
|
||||
calcCumulatedTime()
|
||||
{
|
||||
UNIMPLEMENTED ("Evaluation");
|
||||
return evaluate().cumulatedTime;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Visit all data captured thus far, construct a unified timeline
|
||||
* and then compute statistics evaluations to characterise observations
|
||||
* @warning caller must ensure there was a barrier or visibility sync before invocation.
|
||||
*/
|
||||
IncidenceCount::Statistic
|
||||
IncidenceCount::evaluate()
|
||||
{
|
||||
Statistic stat;
|
||||
size_t numThreads = rec_.size();
|
||||
if (numThreads == 0) return stat;
|
||||
|
||||
size_t numEvents = explore(rec_)
|
||||
.transform([](Sequence& seq){ return seq.size(); })
|
||||
.resultSum();
|
||||
if (numEvents == 0) return stat;
|
||||
Sequence timeline;
|
||||
timeline.reserve(numEvents);
|
||||
for (Sequence& seq : rec_)
|
||||
for (Inc& event : seq)
|
||||
timeline.emplace_back(event);
|
||||
std::sort (timeline.begin(), timeline.end()
|
||||
,[](Inc const& l, Inc const& r) { return l.when < r.when; }
|
||||
);
|
||||
|
||||
int active{0};
|
||||
Instance prev = timeline.front().when;
|
||||
for (Inc& event : timeline)
|
||||
{
|
||||
if (event.isLeave)
|
||||
{
|
||||
ASSERT (0 < active);
|
||||
Dur timeSlice = event.when - prev;
|
||||
stat.cumulatedTime += active * timeSlice.count();
|
||||
--active;
|
||||
}
|
||||
else
|
||||
{
|
||||
++active;
|
||||
}
|
||||
prev = event.when;
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lib
|
||||
#endif /*LIB_INCIDENCE_COUNT_H*/
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ namespace test{
|
|||
|
||||
|
||||
|
||||
/** @test TODO
|
||||
* @todo WIP 2/24 🔁 define ⟶ implement
|
||||
/** @test watch time spent in code bracketed by measurement calls.
|
||||
* @todo WIP 2/24 ✔ define ⟶ ✔ implement
|
||||
*/
|
||||
void
|
||||
demonstrate_usage()
|
||||
|
|
@ -71,11 +71,17 @@ namespace test{
|
|||
watch.markEnter();
|
||||
sleep_for (1ms);
|
||||
watch.markLeave();
|
||||
//
|
||||
sleep_for (5ms);
|
||||
//
|
||||
watch.markEnter();
|
||||
sleep_for (1ms);
|
||||
watch.markLeave();
|
||||
|
||||
double time = watch.calcCumulatedTime();
|
||||
SHOW_EXPR(time)
|
||||
CHECK (time > 900);
|
||||
CHECK (time < 1100);
|
||||
CHECK (time > 1900);
|
||||
CHECK (time < 2500);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -111033,8 +111033,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node CREATED="1707754394399" ID="ID_85130376" MODIFIED="1707754441263" TEXT="∅ Parallellität"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754450711" ID="ID_910369325" MODIFIED="1707754945117" TEXT="Implementierung">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1707754450711" ID="ID_910369325" MODIFIED="1707768337328" TEXT="Implementierung">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1707754455351" ID="ID_1263178646" MODIFIED="1707765868713" TEXT="Rahmen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1707754460590" ID="ID_1078644826" MODIFIED="1707765871131" TEXT="Lib-Implementierung">
|
||||
|
|
@ -111053,32 +111053,44 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#338800" CREATED="1707754857153" ID="ID_259283020" MODIFIED="1707765866391" TEXT="Dimensionierung und automatische Allokation">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754606698" ID="ID_1650260006" MODIFIED="1707754614458" TEXT="Meß-Eingänge">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754656571" ID="ID_1591355619" MODIFIED="1707754905108" TEXT="markEnter">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1707754606698" ID="ID_1650260006" MODIFIED="1707768317205" TEXT="Meß-Eingänge">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1707754656571" ID="ID_1591355619" MODIFIED="1707768315485" TEXT="markEnter">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754666026" ID="ID_1253983399" MODIFIED="1707754905108" TEXT="markLeave">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1707754666026" ID="ID_1253983399" MODIFIED="1707768316541" TEXT="markLeave">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754873263" ID="ID_961298794" MODIFIED="1707754887309" TEXT="Statistik-Auswertung">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754895979" ID="ID_1713684347" MODIFIED="1707754902546" TEXT="Statistik-Record">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1707754873263" ID="ID_961298794" MODIFIED="1707768327245" TEXT="Statistik-Auswertung">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1707754895979" ID="ID_1713684347" MODIFIED="1707768321390" TEXT="Statistik-Record">
|
||||
<icon BUILTIN="pencil"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754913201" ID="ID_177410967" MODIFIED="1707754929796" TEXT="Incident-Timeline etablieren">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1707754913201" ID="ID_177410967" MODIFIED="1707768324431" TEXT="Incident-Timeline etablieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1707754935094" ID="ID_252947705" MODIFIED="1707768333278" TEXT="Zähl-Durchgang">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1707770397112" ID="ID_38773008" MODIFIED="1707770410383" TEXT="Berechnungs-Metode">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1707770411960" ID="ID_1355812150" MODIFIED="1707770438948" TEXT="Zeit-Intervalle Slot-weise zählen">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1707770439946" ID="ID_905201900" MODIFIED="1707770474857" TEXT="muß dann ggfs Array von Zählern anlegen">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1707770479301" ID="ID_1026958053" MODIFIED="1707770500545" TEXT="einfachste Auswertung: beobachtete Zeit in aktiven Intervallen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754935094" ID="ID_252947705" MODIFIED="1707754941846" TEXT="Zähl-Durchgang">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754958979" ID="ID_284055307" MODIFIED="1707754989232" TEXT="IncidenceCount_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707754993819" ID="ID_1476552932" MODIFIED="1707755044792" TEXT="demonstrate_simpleUsage">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1707754993819" ID="ID_1476552932" MODIFIED="1707770394988" TEXT="demonstrate_simpleUsage">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1707755010724" ID="ID_6728381" MODIFIED="1707755044792" TEXT="verify_incidentCount">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue