XRootD
XrdStatsFileSystem.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "XrdOss/XrdOss.hh"
5 #include "XrdSys/XrdSysError.hh"
6 
7 #include <atomic>
8 #include <chrono>
9 
10 class XrdXrootdGStream;
11 
12 // The "stats" filesystem is a wrapper that collects information
13 // about the performance of the underlying storage.
14 //
15 // It allows one to accumulate time spent in I/O, the number of operations,
16 // and information about "slow" operations
17 class StatsFileSystem : public XrdOss {
18  friend class StatsFile;
19  friend class StatsDirectory;
20 
21 public:
22  StatsFileSystem(XrdOss *oss, XrdSysLogger *log, const char *configName, XrdOucEnv *envP);
23  virtual ~StatsFileSystem();
24 
25  bool
26  Config(const char *configfn);
27 
28  XrdOssDF *newDir(const char *user=0) override;
29  XrdOssDF *newFile(const char *user=0) override;
30  int Chmod(const char * path, mode_t mode, XrdOucEnv *env=0) override;
31  void Connect(XrdOucEnv &env) override;
32  int Create(const char *tid, const char *path, mode_t mode, XrdOucEnv &env,
33  int opts=0) override;
34  void Disc(XrdOucEnv &env) override;
35  void EnvInfo(XrdOucEnv *env) override;
36  uint64_t Features() override;
37  int FSctl(int cmd, int alen, const char *args, char **resp=0) override;
38  int Init(XrdSysLogger *lp, const char *cfn) override;
39  int Init(XrdSysLogger *lp, const char *cfn, XrdOucEnv *env) override;
40  int Mkdir(const char *path, mode_t mode, int mkpath=0,
41  XrdOucEnv *env=0) override;
42  int Reloc(const char *tident, const char *path,
43  const char *cgName, const char *anchor=0) override;
44  int Remdir(const char *path, int Opts=0, XrdOucEnv *env=0) override;
45  int Rename(const char *oPath, const char *nPath,
46  XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0) override;
47  int Stat(const char *path, struct stat *buff,
48  int opts=0, XrdOucEnv *env=0) override;
49  int Stats(char *buff, int blen) override;
50  int StatFS(const char *path, char *buff, int &blen,
51  XrdOucEnv *env=0) override;
52  int StatLS(XrdOucEnv &env, const char *path,
53  char *buff, int &blen) override;
54  int StatPF(const char *path, struct stat *buff, int opts) override;
55  int StatPF(const char *path, struct stat *buff) override;
56  int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0) override;
57  int StatXA(const char *path, char *buff, int &blen,
58  XrdOucEnv *env=0) override;
59  int StatXP(const char *path, unsigned long long &attr,
60  XrdOucEnv *env=0) override;
61  int Truncate(const char *path, unsigned long long fsize,
62  XrdOucEnv *env=0) override;
63  int Unlink(const char *path, int Opts=0, XrdOucEnv *env=0) override;
64  int Lfn2Pfn(const char *Path, char *buff, int blen) override;
65  const char *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc) override;
66 
67 private:
68  static void * AggregateBootstrap(void *instance);
69  void AggregateStats();
70 
71  XrdXrootdGStream* m_gstream{nullptr};
72 
73  XrdOss *m_oss;
74  XrdOucEnv *m_env;
75  XrdSysError m_log;
76 
77  class OpTimer {
78  public:
79  OpTimer(std::atomic<uint64_t> &op_count, std::atomic<uint64_t> &slow_op_count, std::atomic<uint64_t> &timing, std::atomic<uint64_t> &slow_timing, std::chrono::steady_clock::duration duration);
80  ~OpTimer();
81 
82  private:
83  std::atomic<uint64_t> &m_op_count;
84  std::atomic<uint64_t> &m_slow_op_count;
85  std::atomic<uint64_t> &m_timing;
86  std::atomic<uint64_t> &m_slow_timing;
87  std::chrono::steady_clock::time_point m_start;
88  std::chrono::steady_clock::duration m_slow_duration;
89  };
90 
91  struct OpRecord {
92  std::atomic<uint64_t> m_read_ops{0};
93  std::atomic<uint64_t> m_write_ops{0};
94  std::atomic<uint64_t> m_stat_ops{0};
95  std::atomic<uint64_t> m_pgread_ops{0};
96  std::atomic<uint64_t> m_pgwrite_ops{0};
97  std::atomic<uint64_t> m_readv_ops{0};
98  std::atomic<uint64_t> m_readv_segs{0};
99  std::atomic<uint64_t> m_dirlist_ops{0};
100  std::atomic<uint64_t> m_dirlist_entries{0};
101  std::atomic<uint64_t> m_truncate_ops{0};
102  std::atomic<uint64_t> m_unlink_ops{0};
103  std::atomic<uint64_t> m_chmod_ops{0};
104  std::atomic<uint64_t> m_open_ops{0};
105  std::atomic<uint64_t> m_rename_ops{0};
106  };
107 
108  struct OpTiming {
109  std::atomic<uint64_t> m_open{0};
110  std::atomic<uint64_t> m_read{0};
111  std::atomic<uint64_t> m_readv{0};
112  std::atomic<uint64_t> m_pgread{0};
113  std::atomic<uint64_t> m_write{0};
114  std::atomic<uint64_t> m_pgwrite{0};
115  std::atomic<uint64_t> m_dirlist{0};
116  std::atomic<uint64_t> m_stat{0};
117  std::atomic<uint64_t> m_truncate{0};
118  std::atomic<uint64_t> m_unlink{0};
119  std::atomic<uint64_t> m_rename{0};
120  std::atomic<uint64_t> m_chmod{0};
121  };
122 
123  OpRecord m_ops;
124  OpTiming m_times;
125  OpRecord m_slow_ops;
126  OpTiming m_slow_times;
127  std::chrono::steady_clock::duration m_slow_duration;
128 };
#define tident
int stat(const char *path, struct stat *buf)
XrdOucString Path
struct myOpts opts
void Disc(XrdOucEnv &env) override
int Init(XrdSysLogger *lp, const char *cfn) override
XrdOssDF * newDir(const char *user=0) override
StatsFileSystem(XrdOss *oss, XrdSysLogger *log, const char *configName, XrdOucEnv *envP)
void EnvInfo(XrdOucEnv *env) override
void Connect(XrdOucEnv &env) override
int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *env=0) override
int StatXP(const char *path, unsigned long long &attr, XrdOucEnv *env=0) override
virtual ~StatsFileSystem()
int Reloc(const char *tident, const char *path, const char *cgName, const char *anchor=0) override
int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
int Create(const char *tid, const char *path, mode_t mode, XrdOucEnv &env, int opts=0) override
XrdOssDF * newFile(const char *user=0) override
bool Config(const char *configfn)
int StatPF(const char *path, struct stat *buff, int opts) override
int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen) override
int Stats(char *buff, int blen) override
int Remdir(const char *path, int Opts=0, XrdOucEnv *env=0) override
int Unlink(const char *path, int Opts=0, XrdOucEnv *env=0) override
int Mkdir(const char *path, mode_t mode, int mkpath=0, XrdOucEnv *env=0) override
int FSctl(int cmd, int alen, const char *args, char **resp=0) override
uint64_t Features() override
int Chmod(const char *path, mode_t mode, XrdOucEnv *env=0) override
int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0) override
int Truncate(const char *path, unsigned long long fsize, XrdOucEnv *env=0) override
int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
int Rename(const char *oPath, const char *nPath, XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0) override
int Lfn2Pfn(const char *Path, char *buff, int blen) override
int Opts
Definition: XrdMpxStats.cc:58
XrdOucEnv * envP
Definition: XrdPss.cc:108