Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make thread safe statistics accounting in TStorageFactoryFile #41308

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions IOPool/TFileAdaptor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# IOPool/TFileAdaptor Description

## Introduction
The package contains a plugin to ROOT to allow a custom `TFile` to be generated by calls to `TFile::Open`. The custom class internally uses the `Storage` object from Utilities/StorageFactory.

## TStorageFactorySystem
A ROOT plugin which allows the use of `TStorageFactoryFile` when `TFile::Open` is called.

## TStorageFactoryFile
A specialization of `TFile` which uses a `edm::storage::Storage` instance internally.
### storage accounting
The `read` measurement statistics only encompasses a single buffer read. `readActual` encompasses both a single buffer read and a vector read. Only `readAsync` measures statistics for reading asynchronously (prefetching?).
rappoccio marked this conversation as resolved.
Show resolved Hide resolved

## TFileAdaptor
A cmsRun service which allows configuration of the `StorageFactory` and assigns which protocols for which ROOT should use `TStorageFactorySystem`.
42 changes: 23 additions & 19 deletions IOPool/TFileAdaptor/src/TStorageFactoryFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fcntl.h>
#include <iostream>
#include <cassert>
#include <atomic>

#if 0
#include "TTreeCache.h"
Expand Down Expand Up @@ -72,27 +73,30 @@ class TTreeCacheDebug : public TTreeCache {
using namespace edm::storage;

ClassImp(TStorageFactoryFile);
static StorageAccount::Counter *s_statsCtor = nullptr;
static StorageAccount::Counter *s_statsOpen = nullptr;
static StorageAccount::Counter *s_statsClose = nullptr;
static StorageAccount::Counter *s_statsFlush = nullptr;
static StorageAccount::Counter *s_statsStat = nullptr;
static StorageAccount::Counter *s_statsSeek = nullptr;
static StorageAccount::Counter *s_statsRead = nullptr;
static StorageAccount::Counter *s_statsCRead = nullptr;
static StorageAccount::Counter *s_statsCPrefetch = nullptr;
static StorageAccount::Counter *s_statsARead = nullptr;
static StorageAccount::Counter *s_statsXRead = nullptr;
static StorageAccount::Counter *s_statsWrite = nullptr;
static StorageAccount::Counter *s_statsCWrite = nullptr;
static StorageAccount::Counter *s_statsXWrite = nullptr;

static inline StorageAccount::Counter &storageCounter(StorageAccount::Counter *&c,
static std::atomic<StorageAccount::Counter *> s_statsCtor = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsOpen = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsClose = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsFlush = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsStat = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsSeek = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsRead = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsCRead = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsCPrefetch = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsARead = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsXRead = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsWrite = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsCWrite = nullptr;
static std::atomic<StorageAccount::Counter *> s_statsXWrite = nullptr;

static inline StorageAccount::Counter &storageCounter(std::atomic<StorageAccount::Counter *> &c,
StorageAccount::Operation operation) {
static const auto token = StorageAccount::tokenForStorageClassName("tstoragefile");
if (!c)
c = &StorageAccount::counter(token, operation);
return *c;
if (!c) {
auto v = &StorageAccount::counter(token, operation);
StorageAccount::Counter *expected = nullptr;
c.compare_exchange_strong(expected, v);
}
return *c.load();
}

TStorageFactoryFile::TStorageFactoryFile(void) : storage_() {
Expand Down