XRootD
XrdPfcDirState.cc
Go to the documentation of this file.
1 #include "XrdPfcDirState.hh"
3 
4 #include <string>
5 
6 using namespace XrdPfc;
7 
8 //----------------------------------------------------------------------------
10 //----------------------------------------------------------------------------
11 DirState::DirState() : m_parent(0), m_depth(0)
12 {}
13 
14 //----------------------------------------------------------------------------
17 //----------------------------------------------------------------------------
19  m_parent(parent),
20  m_depth(m_parent->m_depth + 1)
21 {}
22 
23 //----------------------------------------------------------------------------
27 //----------------------------------------------------------------------------
28 DirState::DirState(DirState *parent, const std::string &dname) :
29  DirStateBase(dname),
30  m_parent(parent),
31  m_depth(m_parent->m_depth + 1)
32 {}
33 
34 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
38 DirState *DirState::create_child(const std::string &dir)
39 {
40  std::pair<DsMap_i, bool> ir = m_subdirs.insert(std::make_pair(dir, DirState(this, dir)));
41  return &ir.first->second;
42 }
43 
44 //----------------------------------------------------------------------------
47 //----------------------------------------------------------------------------
48 DirState *DirState::find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs,
49  DirState **last_existing_dir)
50 {
51  if (pos == pt.get_n_dirs())
52  return this;
53 
54  DirState *ds = nullptr;
55 
56  DsMap_i i = m_subdirs.find(pt.m_dirs[pos]);
57 
58  if (i != m_subdirs.end())
59  {
60  ds = &i->second;
61  if (last_existing_dir)
62  *last_existing_dir = ds;
63  }
64  else if (create_subdirs)
65  {
66  ds = create_child(pt.m_dirs[pos]);
67  }
68 
69  if (ds)
70  return ds->find_path_tok(pt, pos + 1, create_subdirs, last_existing_dir);
71 
72  return nullptr;
73 }
74 
75 //----------------------------------------------------------------------------
81 DirState *DirState::find_path(const std::string &path, int max_depth, bool parse_as_lfn,
82  bool create_subdirs, DirState **last_existing_dir)
83 {
84  PathTokenizer pt(path, max_depth, parse_as_lfn);
85 
86  if (last_existing_dir)
87  *last_existing_dir = this;
88 
89  return find_path_tok(pt, 0, create_subdirs, last_existing_dir);
90 }
91 
92 //----------------------------------------------------------------------------
97 DirState *DirState::find_dir(const std::string &dir,
98  bool create_subdirs)
99 {
100  DsMap_i i = m_subdirs.find(dir);
101 
102  if (i != m_subdirs.end())
103  return &i->second;
104 
105  if (create_subdirs)
106  return create_child(dir);
107 
108  return nullptr;
109 }
110 
111 //----------------------------------------------------------------------------
114 //----------------------------------------------------------------------------
116 {
117  DirUsage &here = m_here_usage;
119 
120  for (auto & [name, daughter] : m_subdirs)
121  {
122  daughter.upward_propagate_initial_scan_usages();
123 
124  DirUsage &dhere = daughter.m_here_usage;
125  DirUsage &dsubdirs = daughter.m_recursive_subdir_usage;
126 
127  here.m_NDirectories += 1;
128 
129  subdirs.m_StBlocks += dhere.m_StBlocks + dsubdirs.m_StBlocks;
130  subdirs.m_NFiles += dhere.m_NFiles + dsubdirs.m_NFiles;
131  subdirs.m_NDirectories += dhere.m_NDirectories + dsubdirs.m_NDirectories;
132  }
133 }
134 
135 //----------------------------------------------------------------------------
138 //----------------------------------------------------------------------------
140 {
141  for (DsMap_i i = m_subdirs.begin(); i != m_subdirs.end(); ++i)
142  {
143  i->second.upward_propagate_stats_and_times();
144 
145  m_recursive_subdir_stats.AddUp(i->second.m_recursive_subdir_stats);
146  m_recursive_subdir_stats.AddUp(i->second.m_here_stats);
147  // nothing to do for m_here_stats.
148 
149  m_recursive_subdir_usage.update_last_times(i->second.m_recursive_subdir_usage);
150  m_recursive_subdir_usage.update_last_times(i->second.m_here_usage);
151  }
152 }
153 
155 {
156  for (DsMap_i i = m_subdirs.begin(); i != m_subdirs.end(); ++i)
157  {
158  i->second.apply_stats_to_usages();
159  }
162 }
163 
164 //----------------------------------------------------------------------------
167 //----------------------------------------------------------------------------
169 {
170  for (DsMap_i i = m_subdirs.begin(); i != m_subdirs.end(); ++i)
171  {
172  i->second.reset_stats();
173  }
176 }
177 
178 int DirState::count_dirs_to_level(int max_depth) const
179 {
180  int n_dirs = 1;
181  if (m_depth < max_depth)
182  {
183  for (auto & [name, ds] : m_subdirs)
184  {
185  n_dirs += ds.count_dirs_to_level(max_depth);
186  }
187  }
188  return n_dirs;
189 }
190 
191 //----------------------------------------------------------------------------
194 //----------------------------------------------------------------------------
195 void DirState::dump_recursively(const char *name, int max_depth) const
196 {
197  printf("%*d %s usage_here=%lld usage_sub=%lld usage_total=%lld num_ios=%d duration=%d b_hit=%lld b_miss=%lld b_byps=%lld b_wrtn=%lld\n",
198  2 + 2 * m_depth, m_depth, name,
201  // XXXXX here_stats or sum up? or both?
205 
206  if (m_depth < max_depth)
207  {
208  for (auto & [name, ds] : m_subdirs)
209  {
210  ds.dump_recursively(name.c_str(), max_depth);
211  }
212  }
213 }
214 
215 
216 //==============================================================================
217 // DataFsState
218 //==============================================================================
219 
221 {
223 }
224 
226 {
227  m_usage_update_time = time(0);
229 }
230 
232 {
234  m_stats_reset_time = time(0);
235 }
236 
237 void DataFsState::dump_recursively(int max_depth) const
238 {
239  if (max_depth < 0)
240  max_depth = 4096;
241 
242  printf("DataFsState::dump_recursively delta_t = %lld, max_dump_depth = %d\n",
243  (long long)(m_usage_update_time - m_stats_reset_time), max_depth);
244 
245  m_root.dump_recursively("root", max_depth);
246 }
static void parent()
void AddUp(const DirStats &s)
Definition: XrdPfcStats.hh:187
long long m_BytesMissed
number of bytes served from remote and cached
Definition: XrdPfcStats.hh:40
long long m_BytesBypassed
number of bytes served directly through XrdCl
Definition: XrdPfcStats.hh:41
int m_Duration
total duration of all IOs attached
Definition: XrdPfcStats.hh:38
int m_NumIos
number of IO objects attached during this access
Definition: XrdPfcStats.hh:37
long long m_BytesHit
number of bytes served from disk
Definition: XrdPfcStats.hh:39
long long m_BytesWritten
number of bytes written to disk
Definition: XrdPfcStats.hh:42
Definition: XrdPfc.hh:41
void dump_recursively(int max_depth) const
void upward_propagate_stats_and_times()
DirUsage m_recursive_subdir_usage
DsMap_t::iterator DsMap_i
int count_dirs_to_level(int max_depth) const
DirState * create_child(const std::string &dir)
DirStats m_recursive_subdir_stats
DirState * find_dir(const std::string &dir, bool create_subdirs)
DirState()
Constructor.
DirState * find_path_tok(PathTokenizer &pt, int pos, bool create_subdirs, DirState **last_existing_dir=nullptr)
DirState * find_path(const std::string &path, int max_depth, bool parse_as_lfn, bool create_subdirs, DirState **last_existing_dir=nullptr)
void apply_stats_to_usages()
void dump_recursively(const char *name, int max_depth) const
void upward_propagate_initial_scan_usages()
void upward_propagate_stats_and_times()
void update_from_stats(const DirStats &s)
long long m_StBlocks
void update_last_times(const DirUsage &u)
std::vector< const char * > m_dirs