27 #include "XrdOuc/XrdOucJson.hh"
36 m_oss(oss), m_verbose(v), m_json(j), m_indent(i), m_ossUser(
"nobody")
41 m_unit[0] = u; m_unit[1] =
'B'; m_unit[2] = 0;
42 }
else if (u ==
'M') {
45 m_unit[0] = u; m_unit[1] =
'B'; m_unit[2] = 0;
49 m_unit[0] =
'B'; m_unit[1] = 0;
54 if (m_json) printFileJson(std::string(path));
55 else printFile(std::string(path));
60 if ( dh->
Opendir(path, m_env) >= 0 )
68 bool Print::isInfoFile(
const char* path)
70 if (strncmp(&path[strlen(path)-6],
".cinfo", 6))
79 void Print::printFileJson(
const std::string& path)
82 fh->
Open((path).c_str(),O_RDONLY, 0600, m_env);
87 if ( ! cfi.Read(fh, path.c_str()))
93 for (
int i = 0; i < cfi.GetNBlocks(); ++i)
95 if (cfi.TestBitWritten(i)) cntd++;
103 {
"version", cfi.GetVersion() },
104 {
"created", timeBuff },
105 {
"cksum", cfi.GetCkSumStateAsText() },
106 {
"file_size", cfi.GetFileSize() },
107 {
"buffer_size", cfi.GetBufferSize() },
108 {
"n_blocks", cfi.GetNBlocks() },
109 {
"state_complete", cntd < cfi.GetNBlocks() ?
"incomplete" :
"complete" },
110 {
"state_percentage", 100.0 * cntd / cfi.GetNBlocks() },
114 if (cfi.HasNoCkSumTime()) {
115 strftime(timeBuff, 128,
"%c", localtime(&store.
m_noCkSumTime));
116 jobj[
"no-cksum-time"] = timeBuff;
123 for (
int i = 0; i < cfi.GetNBlocks(); ++i)
125 jarr.push_back(cfi.TestBitWritten(i) ? 1 : 0);
127 jobj[
"block_array"] = jarr;
131 const std::vector<Info::AStat> &astats = cfi.RefAStats();
133 for (std::vector<Info::AStat>::const_iterator it = astats.begin(); it != astats.end(); ++it)
138 strftime(s, MM,
"%y%m%d:%H%M%S", localtime(&(it->AttachTime)));
140 strftime(s, MM,
"%y%m%d:%H%M%S", localtime(&(it->DetachTime)));
141 std::string dt = it->DetachTime > 0 ? s :
"------:------";
143 int hours = it->Duration/3600;
144 int min = (it->Duration - hours * 3600)/60;
145 int sec = it->Duration % 60;
146 snprintf(s, MM,
"%d:%02d:%02d", hours, min, sec);
155 {
"n_ios", it->NumIos },
156 {
"n_mrg", it->NumMerged },
157 {
"B_hit", it->BytesHit },
158 {
"B_miss", it->BytesMissed },
159 {
"B_bypass", it->BytesBypassed }
161 acc_arr.push_back(acc);
163 jobj[
"accesses"] = acc_arr;
165 std::cout << jobj.dump(m_indent) <<
"\n";
171 void Print::printFile(
const std::string& path)
173 printf(
"FILE: %s\n", path.c_str());
175 fh->
Open((path).c_str(),O_RDONLY, 0600, m_env);
180 if ( ! cfi.Read(fh, path.c_str()))
186 for (
int i = 0; i < cfi.GetNBlocks(); ++i)
188 if (cfi.TestBitWritten(i)) cntd++;
194 printf(
"version %d, created %s; cksum %s", cfi.GetVersion(), timeBuff, cfi.GetCkSumStateAsText());
195 if (cfi.HasNoCkSumTime()) {
196 strftime(timeBuff, 128,
"%c", localtime(&store.
m_noCkSumTime));
197 printf(
", no-cksum-time %s\n", timeBuff);
200 printf(
"file_size %lld %s, buffer_size %lld %s, n_blocks %d, n_downloaded %d, state %scomplete [%.3f%%]\n",
201 cfi.GetFileSize() >> m_unit_shift, m_unit,
202 cfi.GetBufferSize() >> (m_unit[0] ==
'M' ? 10 : m_unit_shift), m_unit[0] ==
'M' ?
"kB" : m_unit,
203 cfi.GetNBlocks(), cntd,
204 (cntd < cfi.GetNBlocks()) ?
"in" :
"", 100.0 * cntd / cfi.GetNBlocks());
209 {
int x = cfi.GetNBlocks();
while (x)
214 static const char *nums =
"0123456789";
215 printf(
"printing %d blocks:\n", cfi.GetNBlocks());
216 printf(
"%*s %10d%10d%10d%10d%10d%10d\n", n_db,
"", 1, 2, 3, 4, 5, 6);
217 printf(
"%*s %s%s%s%s%s%s0123", n_db,
"", nums, nums, nums, nums, nums, nums);
218 for (
int i = 0; i < cfi.GetNBlocks(); ++i)
221 printf(
"\n%*d ", n_db, i);
222 printf(
"%c", cfi.TestBitWritten(i) ?
'x' :
'.');
227 int ww = m_unit_width - 2 - strlen(m_unit);
228 printf(
"Access records (N_acc_total=%llu):\n"
229 "%-6s %-13s %-13s %-12s %-5s %-5s %*s[%s] %*s[%s] %*s[%s]\n",
231 "Record",
"Attach",
"Detach",
"Duration",
"N_ios",
"N_mrg",
232 ww,
"B_hit", m_unit, ww,
"B_miss", m_unit, ww,
"B_bypass", m_unit);
235 const std::vector<Info::AStat> &astats = cfi.RefAStats();
236 for (std::vector<Info::AStat>::const_iterator it = astats.begin(); it != astats.end(); ++it)
241 strftime(s, MM,
"%y%m%d:%H%M%S", localtime(&(it->AttachTime)));
243 strftime(s, MM,
"%y%m%d:%H%M%S", localtime(&(it->DetachTime)));
244 std::string dt = it->DetachTime > 0 ? s :
"------:------";
246 int hours = it->Duration/3600;
247 int min = (it->Duration - hours * 3600)/60;
248 int sec = it->Duration % 60;
249 snprintf(s, MM,
"%d:%02d:%02d", hours, min, sec);
253 printf(
"%-6d %-13s %-13s %-12s %5d %5d %*lld %*lld %*lld\n", idx++,
254 at.c_str(), dt.c_str(), dur.c_str(), it->NumIos, it->NumMerged,
255 m_unit_width, it->BytesHit >> m_unit_shift,
256 m_unit_width, it->BytesMissed >> m_unit_shift,
257 m_unit_width, it->BytesBypassed >> m_unit_shift);
263 void Print::printDir(
XrdOssDF* iOssDF,
const std::string& path)
272 while ((rdr = iOssDF->
Readdir(&buff[0], MM)) >= 0)
274 if (strncmp(
"..", &buff[0], 2) && strncmp(
".", &buff[0], 1))
276 if (strlen(buff) == 0)
280 std::string np = path +
"/" + std::string(&buff[0]);
281 if (isInfoFile(buff))
286 if (first) first =
false;
294 if (dh->
Opendir(np.c_str(), m_env) >= 0)
307 int main(
int argc,
char *argv[])
309 static const char*
usage =
"Usage: pfc_print [-h] [-c config_file] [-u B|kB|MB] [-v] [-j] [-i indent] path ...\n";
311 bool verbose =
false;
314 const char* cfgn = 0;
331 Spec.
Set(argc-1, &argv[1]);
334 while ((theOpt = Spec.
getopt()) != (
char)-1)
341 int fd =
open(cfgn, O_RDONLY, 0);
346 if (strcmp(Spec.
argval,
"B") && strcmp(Spec.
argval,
"kB") && strcmp(Spec.
argval,
"MB")) {
347 printf(
"%s Error: -unit argument can only be B, kB or MB\n",
usage);
362 indent = std::stoi(Spec.
argval);
374 int efs =
open(
"/dev/null",O_RDWR, 0);
382 printf(
"can't load oss\n");
388 while ((path = Spec.
getarg()))
397 if ( ! strncmp(&path[0],
"root:/", 6))
401 printf(
"Configuration file not specified.\n");
405 while((var =
Config.GetFirstWord()))
408 if ( ! strncmp(var,
"oss.localroot", strlen(
"oss.localroot")))
410 std::string tmp =
Config.GetWord();
int main(int argc, char *argv[])
int open(const char *path, int oflag,...)
bool Plugin(XrdAccAuthorize *&piP)
Get Authorization plugin.
static XrdOfsConfigPI * New(const char *cfn, XrdOucStream *cfgP, XrdSysError *errP, XrdVersionInfo *verP=0, XrdSfsFileSystem *sfsP=0)
bool Load(int what, XrdOucEnv *envP=0)
virtual int Opendir(const char *path, XrdOucEnv &env)
virtual int Readdir(char *buff, int blen)
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
virtual XrdOssDF * newDir(const char *tident)=0
virtual XrdOssDF * newFile(const char *tident)=0
Status of cached file. Can be read from and written into a binary file.
Print(XrdOss *oss, char u, bool v, bool j, int i, const char *path)
Constructor.
time_t m_noCkSumTime
time when first non-cksummed block was detected
size_t m_accessCnt
total access count for the file
time_t m_creationTime
time the info file was created