CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tracer.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_TRACER_H_
6 #define CVMFS_TRACER_H_ 1
7 
8 #include <inttypes.h>
9 #include <pthread.h>
10 #include <sys/time.h>
11 
12 #include <cstdio>
13 #include <string>
14 
15 #include "atomic.h"
16 #include "shortstring.h"
17 #include "util/single_copy.h"
18 
35 class Tracer : SingleCopy {
36  public:
37  enum TraceEvents {
46  };
47 
48  Tracer();
49  ~Tracer();
50 
51  void Activate(const int buffer_size, const int flush_threshold,
52  const std::string &trace_file);
53  void Spawn();
54  void Flush();
55  void inline __attribute__((used)) Trace(const int event,
56  const PathString &path,
57  const std::string &msg)
58  {
59  if (active_) DoTrace(event, path, msg);
60  }
61 
62  bool inline __attribute__((used)) IsActive() {
63  return active_;
64  }
65 
66  private:
70  static const int kEventStart = -1;
74  static const int kEventStop = -2;
78  static const int kEventFlush = -3;
79 
83  struct BufferEntry {
87  timeval time_stamp;
91  int code;
93  std::string msg;
94  };
95 
96  static void *MainFlush(void *data);
97  void GetTimespecRel(const int64_t ms, timespec *ts);
98  int WriteCsvFile(FILE *fp, const std::string &field);
99  int32_t DoTrace(const int event,
100  const PathString &path,
101  const std::string &msg);
102 
103  bool active_;
104  bool spawned_;
105  std::string trace_file_;
115  pthread_t thread_flush_;
116  pthread_cond_t sig_flush_;
117  pthread_mutex_t sig_flush_mutex_;
118  pthread_cond_t sig_continue_trace_;
119  pthread_mutex_t sig_continue_trace_mutex_;
132 };
133 
134 #endif // CVMFS_TRACER_H_
timeval time_stamp
Definition: tracer.h:87
Tracer()
Definition: tracer.cc:223
PathString path
Definition: tracer.h:92
void Activate(const int buffer_size, const int flush_threshold, const std::string &trace_file)
Definition: tracer.cc:25
void GetTimespecRel(const int64_t ms, timespec *ts)
Definition: tracer.cc:133
void const PathString const std::string & msg
Definition: tracer.h:58
static void * MainFlush(void *data)
Definition: tracer.cc:147
pthread_mutex_t sig_flush_mutex_
Definition: tracer.h:117
atomic_int32 seq_no_
Definition: tracer.h:124
void Spawn()
Definition: tracer.cc:212
std::string msg
Definition: tracer.h:93
int code
Definition: tracer.h:91
void __attribute__((used)) Trace(const int event
int WriteCsvFile(FILE *fp, const std::string &field)
Definition: tracer.cc:269
pthread_cond_t sig_flush_
Definition: tracer.h:116
pthread_cond_t sig_continue_trace_
Definition: tracer.h:118
int buffer_size_
Definition: tracer.h:106
Definition: tracer.h:35
atomic_int32 flush_immediately_
Definition: tracer.h:131
int32_t atomic_int32
Definition: atomic.h:17
int32_t DoTrace(const int event, const PathString &path, const std::string &msg)
Definition: tracer.cc:69
int flush_threshold_
Definition: tracer.h:107
void Flush()
Definition: tracer.cc:106
pthread_t thread_flush_
Definition: tracer.h:115
static const int kEventFlush
Definition: tracer.h:78
~Tracer()
Definition: tracer.cc:239
atomic_int32 terminate_flush_thread_
Definition: tracer.h:130
bool active_
Definition: tracer.h:103
static const int kEventStart
Definition: tracer.h:70
BufferEntry * ring_buffer_
Definition: tracer.h:108
void const PathString & path
Definition: tracer.h:56
static const int kEventStop
Definition: tracer.h:74
bool __attribute__((used)) IsActive()
Definition: tracer.h:62
Definition: tracer.h:83
pthread_mutex_t sig_continue_trace_mutex_
Definition: tracer.h:119
std::string trace_file_
Definition: tracer.h:105
TraceEvents
Definition: tracer.h:37
atomic_int32 flushed_
Definition: tracer.h:129
bool spawned_
Definition: tracer.h:104
atomic_int32 * commit_buffer_
Definition: tracer.h:114