forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallbacksPolicy.cxx
More file actions
90 lines (84 loc) · 3.6 KB
/
CallbacksPolicy.cxx
File metadata and controls
90 lines (84 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "Framework/CallbacksPolicy.h"
#include "Framework/CallbackService.h"
#include "Framework/CompletionPolicy.h"
#include "Framework/ServiceRegistryRef.h"
#include "Framework/TimingInfo.h"
#include "Framework/Logger.h"
#include "Framework/CommonServices.h"
#include "Framework/DataTakingContext.h"
#include "Framework/DefaultsHelpers.h"
#include <cstdlib>
#include <uv.h>
namespace o2::framework
{
static bool checkPrescale(const TimingInfo& info, int prescale, bool startProcessing, bool noDownscaling)
{
if (prescale <= 1) {
static size_t counter = 0;
static size_t downscaleFactor = 1;
if (startProcessing) {
counter++;
}
if (counter <= 100000 || noDownscaling) {
return true;
}
if (counter > 100000 * downscaleFactor) {
downscaleFactor *= 10;
LOG(info) << "Processed " << counter << " timeslices / timers, increasing reporting downscale factor to " << downscaleFactor;
}
return counter % downscaleFactor == 0;
}
return info.isTimer() || !(info.timeslice % prescale);
}
CallbacksPolicy epnProcessReporting()
{
int prescale = 1;
bool forceReport = false;
if (getenv("DPL_REPORT_PROCESSING") != nullptr && (prescale = std::abs(atoi(getenv("DPL_REPORT_PROCESSING"))))) {
forceReport = true;
}
if (!prescale) {
prescale = 1;
}
static bool noDownscaling = getenv("DPL_REPORT_PROCESSING_NO_DOWNSCALING") != nullptr && std::abs(atoi(getenv("DPL_REPORT_PROCESSING_NO_DOWNSCALING")));
return {
.matcher = [forceReport](DeviceSpec const&, ConfigContext const& context) -> bool {
static bool report = DefaultsHelpers::deploymentMode() == DeploymentMode::OnlineDDS || forceReport;
return report;
},
.policy = [prescale](CallbackService& callbacks, InitContext& context) -> void {
callbacks.set<CallbackService::Id::PreProcessing>([prescale](ServiceRegistryRef registry, int op) {
auto& info = registry.get<TimingInfo>();
if ((int)info.firstTForbit != -1 && checkPrescale(info, prescale, true, noDownscaling)) {
char const* what = info.isTimer() ? "timer" : "timeslice";
LOGP(info, "Processing {}:{}, tfCounter:{}, firstTForbit:{}, runNumber:{}, creation:{}, action:{}",
what, info.timeslice, info.tfCounter, info.firstTForbit, info.runNumber, info.creation, op);
}
info.lapse = uv_hrtime();
});
callbacks.set<CallbackService::Id::PostProcessing>([prescale](ServiceRegistryRef registry, int op) {
auto& info = registry.get<TimingInfo>();
if ((int)info.firstTForbit != -1 && checkPrescale(info, prescale, false, noDownscaling)) {
char const* what = info.isTimer() ? "timer" : "timeslice";
LOGP(info, "Done processing {}:{}, tfCounter:{}, firstTForbit:{}, runNumber:{}, creation:{}, action:{}, wall:{}",
what, info.timeslice, info.tfCounter, info.firstTForbit, info.runNumber, info.creation, op, uv_hrtime() - info.lapse);
}
});
}};
}
std::vector<CallbacksPolicy> CallbacksPolicy::createDefaultPolicies()
{
return {
epnProcessReporting()};
}
} // namespace o2::framework