XRootD
XrdOssStatsFileSystem.hh
Go to the documentation of this file.
1 
2 #ifndef __XRDOSSSTATS_FILESYSTEM_H
3 #define __XRDOSSSTATS_FILESYSTEM_H
4 
6 #include "XrdSys/XrdSysError.hh"
8 
9 #include <chrono>
10 #include <memory>
11 #include <string>
12 
13 class XrdXrootdGStream;
14 
15 namespace XrdOssStats {
16 
17 // The "stats" filesystem is a wrapper that collects information
18 // about the performance of the underlying storage.
19 //
20 // It allows one to accumulate time spent in I/O, the number of operations,
21 // and information about "slow" operations
22 class FileSystem : public XrdOssWrapper {
23  friend class File;
24  friend class Directory;
25 
26 public:
27  // Note: FileSystem takes ownership of the underlying oss
28  FileSystem(XrdOss *oss, XrdSysLogger *log, const char *configName, XrdOucEnv *envP);
29  virtual ~FileSystem();
30 
31  bool
32  Config(const char *configfn);
33 
34  // Indicate whether the initialization of the object was successful
35  //
36  // If `false` and `errMsg` is set, then the failure is fatal and the
37  // xrootd server should not startup.
38  // If `false` and `errMsg` is empty, then it's OK to bypass this object
39  // and just use the wrapped OSS pointer directly.
40  bool
41  InitSuccessful(std::string &errMsg);
42 
43  XrdOssDF *newDir(const char *user=0) override;
44  XrdOssDF *newFile(const char *user=0) override;
45  int Chmod(const char * path, mode_t mode, XrdOucEnv *env=0) override;
46  int Rename(const char *oPath, const char *nPath,
47  XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0) override;
48  int Stat(const char *path, struct stat *buff,
49  int opts=0, XrdOucEnv *env=0) 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 
65 private:
66  static void * AggregateBootstrap(void *instance);
67  void AggregateStats();
68 
69  XrdXrootdGStream* m_gstream{nullptr};
70 
71  // Indicates whether the class was able to initialize.
72  // On initialization failure, if there is no failure message
73  // set, then we assume it is OK to proceed with the wrapped OSS.
74  // If m_failure is set, then we assume the initialization failure
75  // was fatal and it's better to halt startup than proceed.
76  bool m_ready{false};
77  std::string m_failure;
78  std::unique_ptr<XrdOss> m_oss;
79  XrdOucEnv *m_env;
80  XrdSysError m_log;
81 
82  class OpTimer {
83  public:
84  OpTimer(RAtomic_uint64_t &op_count, RAtomic_uint64_t &slow_op_count, RAtomic_uint64_t &timing, RAtomic_uint64_t &slow_timing, std::chrono::steady_clock::duration duration);
85  ~OpTimer();
86 
87  private:
88  RAtomic_uint64_t &m_op_count;
89  RAtomic_uint64_t &m_slow_op_count;
90  RAtomic_uint64_t &m_timing;
91  RAtomic_uint64_t &m_slow_timing;
92  std::chrono::steady_clock::time_point m_start;
93  std::chrono::steady_clock::duration m_slow_duration;
94  };
95 
96  struct OpRecord {
97  RAtomic_uint64_t m_read_ops{0};
98  RAtomic_uint64_t m_write_ops{0};
99  RAtomic_uint64_t m_stat_ops{0};
100  RAtomic_uint64_t m_pgread_ops{0};
101  RAtomic_uint64_t m_pgwrite_ops{0};
102  RAtomic_uint64_t m_readv_ops{0};
103  RAtomic_uint64_t m_readv_segs{0};
104  RAtomic_uint64_t m_dirlist_ops{0};
105  RAtomic_uint64_t m_dirlist_entries{0};
106  RAtomic_uint64_t m_truncate_ops{0};
107  RAtomic_uint64_t m_unlink_ops{0};
108  RAtomic_uint64_t m_chmod_ops{0};
109  RAtomic_uint64_t m_open_ops{0};
110  RAtomic_uint64_t m_rename_ops{0};
111  };
112 
113  struct OpTiming {
114  RAtomic_uint64_t m_open{0};
115  RAtomic_uint64_t m_read{0};
116  RAtomic_uint64_t m_readv{0};
117  RAtomic_uint64_t m_pgread{0};
118  RAtomic_uint64_t m_write{0};
119  RAtomic_uint64_t m_pgwrite{0};
120  RAtomic_uint64_t m_dirlist{0};
121  RAtomic_uint64_t m_stat{0};
122  RAtomic_uint64_t m_truncate{0};
123  RAtomic_uint64_t m_unlink{0};
124  RAtomic_uint64_t m_rename{0};
125  RAtomic_uint64_t m_chmod{0};
126  };
127 
128  OpRecord m_ops;
129  OpTiming m_times;
130  OpRecord m_slow_ops;
131  OpTiming m_slow_times;
132  std::chrono::steady_clock::duration m_slow_duration;
133 };
134 
135 } // XrdOssStats
136 
137 #endif // __XRDOSSSTATS_FILESYSTEM_H
int stat(const char *path, struct stat *buf)
struct myOpts opts
int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *env=0) override
FileSystem(XrdOss *oss, XrdSysLogger *log, const char *configName, XrdOucEnv *envP)
int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0) override
int StatPF(const char *path, struct stat *buff, int opts) override
int Rename(const char *oPath, const char *nPath, XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0) override
XrdOssDF * newDir(const char *user=0) override
int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
XrdOssDF * newFile(const char *user=0) override
int Chmod(const char *path, mode_t mode, XrdOucEnv *env=0) override
int Unlink(const char *path, int Opts=0, XrdOucEnv *env=0) override
bool InitSuccessful(std::string &errMsg)
int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
int Truncate(const char *path, unsigned long long fsize, XrdOucEnv *env=0) override
bool Config(const char *configfn)
int StatXP(const char *path, unsigned long long &attr, XrdOucEnv *env=0) override
int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen) override
int Opts
Definition: XrdMpxStats.cc:58
XrdOucEnv * envP
Definition: XrdPss.cc:109