36std::mutex &GetMetricsExportMutex()
38 static std::mutex mutex;
42thread_local bool gSuppressMetricsExport =
false;
44struct RSuppressMetricsRaii {
45 RSuppressMetricsRaii() { gSuppressMetricsExport =
true; }
46 RSuppressMetricsRaii(
const RSuppressMetricsRaii &other) =
delete;
47 RSuppressMetricsRaii &operator=(
const RSuppressMetricsRaii &other) =
delete;
48 ~RSuppressMetricsRaii() { gSuppressMetricsExport =
false; }
59 return fName + kFieldSeparator + fUnit + kFieldSeparator + fDescription + kFieldSeparator + GetValueAsString();
64 return GetLocalCounter(
name) !=
nullptr;
70 for (
const auto &
c : fCounters) {
71 if (
c->GetName() ==
name)
80 std::string prefix = fName +
".";
81 if (
name.compare(0, prefix.length(), std::string_view(prefix)) != 0)
84 auto innerName =
name.substr(prefix.length());
85 if (
auto counter = GetLocalCounter(innerName))
88 for (
auto m : fObservedMetrics) {
89 auto counter =
m->GetCounter(innerName);
90 if (counter !=
nullptr)
100 output << fName <<
" metrics disabled!\n";
104 for (
const auto &
c : fCounters) {
105 output << prefix << fName << kNamespaceSeparator <<
c->ToString() <<
'\n';
107 for (
const auto c : fObservedMetrics) {
108 c->Print(output, prefix + fName +
".");
114 for (
auto &
c: fCounters)
117 for (
auto m: fObservedMetrics)
123 fObservedMetrics.push_back(&observee);
128 if (gSuppressMetricsExport)
131 if (
const char *env =
gSystem->
Getenv(
"ROOT_EXPERIMENTAL_EXPORT_RNTUPLE_METRICS"); env && *env)
139 if (!fIsEnabled || fExportPath.empty())
150 std::vector<std::pair<std::string, const RNTuplePerfCounter *>> &
counters,
const std::string &prefix)
const
152 constexpr char kSeparator =
'_';
156 std::string qualifiedName = prefix;
157 if (!qualifiedName.empty())
158 qualifiedName += kSeparator;
159 qualifiedName += fName;
161 for (
const auto &counter : fCounters)
162 counters.emplace_back(qualifiedName + kSeparator + counter->GetName(), counter.get());
164 for (
const auto *observed : fObservedMetrics)
165 observed->CollectCounters(
counters, qualifiedName);
173 std::vector<std::pair<std::string, const RNTuplePerfCounter *>>
counters;
178 RSuppressMetricsRaii suppressGuard;
181 for (
const auto &[fullyQualifiedName, counter] :
counters) {
183 if (
const auto *calc =
dynamic_cast<const RNTupleCalcPerf *
>(counter)) {
184 *model->MakeField<
double>(fullyQualifiedName) = calc->GetValue();
186 *model->MakeField<std::int64_t>(fullyQualifiedName) = counter->GetValueAsInt();
190 TMemFile memoryFile(fNTupleName.c_str(),
"RECREATE");
197 std::lock_guard<std::mutex> lock(GetMetricsExportMutex());
202 if (!merger.
OutputFile(fExportPath.c_str(),
"UPDATE")) {
209 <<
"cannot merge metrics for '" << fNTupleName <<
"' into '" << fExportPath <<
"'";
#define R__LOG_ERROR(...)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
R__EXTERN TSystem * gSystem
A metric element that computes its floating point value from other counters.
A collection of Counter objects with a name, a unit, and a description.
const RNTuplePerfCounter * GetCounter(std::string_view name) const
Searches this object and all the observed sub metrics.
void ObserveMetrics(RNTupleMetrics &observee)
const RNTuplePerfCounter * GetLocalCounter(std::string_view name) const
Searches counters registered in this object only. Returns nullptr if name is not found.
void CollectCounters(std::vector< std::pair< std::string, const RNTuplePerfCounter * > > &counters, const std::string &prefix="") const
Retrieves each counter of the observed metrics down to the class instances which own the counters and...
static std::string GetMetricsExportPath()
bool Contains(const std::string &name) const
void Print(std::ostream &output, const std::string &prefix="") const
A performance counter with a name and a unit, which can be activated on demand.
std::string ToString() const
virtual ~RNTuplePerfCounter()
Base class for all ROOT issued exceptions.
static std::unique_ptr< RNTupleModel > Create()
static std::unique_ptr< RNTupleWriter > Append(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter that writes into an existing TFile or TDirectory, without overwriting its co...
This class provides file copy and merging services.
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
@ kAll
Merge all type of objects (default)
@ kIncremental
Merge the input file with the content of the output file (if already existing).
void SetMergeOptions(const TString &options)
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
A TMemFile is like a normal TFile except that it reads and writes only from memory.
virtual const char * Getenv(const char *env)
Get environment variable.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.