Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / client / Trace.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software 
11  * Foundation.  See file COPYING.
12  * 
13  */
14
15
16
17 #include "Trace.h"
18 #include "common/debug.h"
19
20 #include <iostream>
21 #include <map>
22
23 #include "common/Mutex.h"
24
25 #include "common/config.h"
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30
31
32
33
34
35 void Trace::start()
36 {
37   //cout << "start" << std::endl;
38   delete fs;
39
40   fs = new ifstream();
41   fs->open(filename);
42   if (!fs->is_open()) {
43     //generic_dout(0) << "** unable to open trace file " << filename << dendl;
44     ceph_abort();
45   }
46   //generic_dout(2) << "opened traced file '" << filename << "'" << dendl;
47   
48   // read first line
49   getline(*fs, line);
50   //cout << "first line is " << line << std::endl;
51
52   _line = 1;
53 }
54
55 const char *Trace::peek_string(string &buf, const char *prefix)
56 {
57   //if (prefix) cout << "prefix '" << prefix << "' line '" << line << "'" << std::endl;
58   if (prefix &&
59       strstr(line.c_str(), "/prefix") == line.c_str()) {
60     buf.clear();
61     buf.append(prefix);
62     buf.append(line.c_str() + strlen("/prefix"));
63   } else {
64     buf = line;
65   }
66   return buf.c_str();
67 }
68
69
70 const char *Trace::get_string(string &buf, const char *prefix)
71 {
72   peek_string(buf, prefix);
73
74   //cout << "buf is " << buf << std::endl;
75   // read next line (and detect eof early)
76   _line++;
77   getline(*fs, line);
78   //cout << "next line is " << line << std::endl;
79
80   return buf.c_str();
81 }