CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tracer Class Reference

#include <tracer.h>

Inheritance diagram for Tracer:
Collaboration diagram for Tracer:

Classes

struct  BufferEntry
 

Public Types

enum  TraceEvents {
  kEventOpen = 1, kEventOpenDir, kEventReadlink, kEventLookup,
  kEventStatFs, kEventGetAttr, kEventListAttr, kEventGetXAttr
}
 

Public Member Functions

 Tracer ()
 
 ~Tracer ()
 
void Activate (const int buffer_size, const int flush_threshold, const std::string &trace_file)
 
void Spawn ()
 
void Flush ()
 
void __attribute__ ((used)) Trace(const int event
 
bool __attribute__ ((used)) IsActive()
 

Public Attributes

void const PathStringpath
 
void const PathString const
std::string & 
msg
 

Private Member Functions

void GetTimespecRel (const int64_t ms, timespec *ts)
 
int WriteCsvFile (FILE *fp, const std::string &field)
 
int32_t DoTrace (const int event, const PathString &path, const std::string &msg)
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Static Private Member Functions

static void * MainFlush (void *data)
 

Private Attributes

bool active_
 
bool spawned_
 
std::string trace_file_
 
int buffer_size_
 
int flush_threshold_
 
BufferEntryring_buffer_
 
atomic_int32commit_buffer_
 
pthread_t thread_flush_
 
pthread_cond_t sig_flush_
 
pthread_mutex_t sig_flush_mutex_
 
pthread_cond_t sig_continue_trace_
 
pthread_mutex_t sig_continue_trace_mutex_
 
atomic_int32 seq_no_
 
atomic_int32 flushed_
 
atomic_int32 terminate_flush_thread_
 
atomic_int32 flush_immediately_
 

Static Private Attributes

static const int kEventStart = -1
 
static const int kEventStop = -2
 
static const int kEventFlush = -3
 

Detailed Description

This file is part of the CernVM File System. Tracer is a thread-safe logging helper. It uses a ring buffer and spawns a helper thread, that flushes the messages onto the disk when necessary. The output file is in csv format. Usually tracing a message is a lock-free process, which therefore should have minimal overhead.

This is not supposed to be a debugging system. It is optimized for speed and does not try to gather any additional information (like threadid, status of variables, etc.).

Csv output is adapted from libcsv.

Todo:
If anything goes wrong, the whole thing breaks down on assertion. This might be not desired behavior.

Definition at line 35 of file tracer.h.

Member Enumeration Documentation

Enumerator
kEventOpen 
kEventOpenDir 
kEventReadlink 
kEventLookup 
kEventStatFs 
kEventGetAttr 
kEventListAttr 
kEventGetXAttr 

Definition at line 37 of file tracer.h.

Constructor & Destructor Documentation

Tracer::Tracer ( )

Definition at line 223 of file tracer.cc.

Tracer::~Tracer ( )

Definition at line 239 of file tracer.cc.

Here is the call graph for this function:

Member Function Documentation

void Tracer::__attribute__ ( (used)  ) const
inline
bool Tracer::__attribute__ ( (used)  )
inline

Definition at line 62 of file tracer.h.

void Tracer::Activate ( const int  buffer_size,
const int  flush_threshold,
const std::string &  trace_file 
)

Definition at line 25 of file tracer.cc.

Referenced by MountPoint::CreateTracer().

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t Tracer::DoTrace ( const int  event,
const PathString path,
const std::string &  msg 
)
private

Trace a message. This is usually a lock-free procedure that just requires two fetch_and_add operations and a gettimeofday syscall. There are two exceptions:

  1. If the ring buffer is full, the function blocks until the flush thread made some space. Avoid that by carefully choosing size and threshold.
  2. If this message reaches the threshold, the flush thread gets signaled.
Parameters
[in]eventArbitrary code, for consistency applications should use one of the TraceEvents constants. Negative codes are reserved for internal use.
[in]idArbitrary id, for example file name or module name which is doing the trace.
Returns
The sequence number which was used to trace the record

Definition at line 69 of file tracer.cc.

Referenced by ~Tracer().

Here is the call graph for this function:

Here is the caller graph for this function:

void Tracer::Flush ( )

Definition at line 106 of file tracer.cc.

Referenced by TalkManager::MainResponder().

Here is the call graph for this function:

Here is the caller graph for this function:

void Tracer::GetTimespecRel ( const int64_t  ms,
timespec *  ts 
)
private

Definition at line 133 of file tracer.cc.

Referenced by MainFlush().

Here is the caller graph for this function:

void * Tracer::MainFlush ( void *  data)
staticprivate

Definition at line 147 of file tracer.cc.

Here is the call graph for this function:

void Tracer::Spawn ( )

Definition at line 212 of file tracer.cc.

Referenced by Spawn().

Here is the call graph for this function:

Here is the caller graph for this function:

int Tracer::WriteCsvFile ( FILE *  fp,
const std::string &  field 
)
private

Definition at line 269 of file tracer.cc.

Referenced by MainFlush().

Here is the caller graph for this function:

Member Data Documentation

bool Tracer::active_
private

Definition at line 103 of file tracer.h.

Referenced by __attribute__(), and ~Tracer().

int Tracer::buffer_size_
private

Definition at line 106 of file tracer.h.

Referenced by MainFlush().

atomic_int32* Tracer::commit_buffer_
private

Has the same size as the ring buffer. If a message is actually copied to the ring buffer memory, the respective flag is set to 1. Flags are reset to 0 by the flush thread.

Definition at line 114 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

atomic_int32 Tracer::flush_immediately_
private

Definition at line 131 of file tracer.h.

Referenced by MainFlush(), and Tracer().

int Tracer::flush_threshold_
private

Definition at line 107 of file tracer.h.

Referenced by MainFlush().

atomic_int32 Tracer::flushed_
private

Starts with 0 and gets incremented by the flush thread. Points to the first non-flushed message. flushed <= seq_no holds.

Definition at line 129 of file tracer.h.

Referenced by MainFlush(), and Tracer().

const int Tracer::kEventFlush = -3
staticprivate

Manual flush

Definition at line 78 of file tracer.h.

const int Tracer::kEventStart = -1
staticprivate

Code of the first log line in the trace file.

Definition at line 70 of file tracer.h.

const int Tracer::kEventStop = -2
staticprivate

Code of the lasr log line in the trace file.

Definition at line 74 of file tracer.h.

Referenced by ~Tracer().

void const PathString const std::string& Tracer::msg
Initial value:
{
if (active_) DoTrace(event, path, msg)

Definition at line 58 of file tracer.h.

void const PathString& Tracer::path

Definition at line 56 of file tracer.h.

BufferEntry* Tracer::ring_buffer_
private

Definition at line 108 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

atomic_int32 Tracer::seq_no_
private

Starts with 0 and gets incremented by each call to trace. Contains the first non-used sequence number.

Definition at line 124 of file tracer.h.

Referenced by MainFlush(), and Tracer().

pthread_cond_t Tracer::sig_continue_trace_
private

Definition at line 118 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

pthread_mutex_t Tracer::sig_continue_trace_mutex_
private

Definition at line 119 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

pthread_cond_t Tracer::sig_flush_
private

Definition at line 116 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

pthread_mutex_t Tracer::sig_flush_mutex_
private

Definition at line 117 of file tracer.h.

Referenced by MainFlush(), and ~Tracer().

bool Tracer::spawned_
private

Definition at line 104 of file tracer.h.

Referenced by ~Tracer().

atomic_int32 Tracer::terminate_flush_thread_
private

Definition at line 130 of file tracer.h.

Referenced by MainFlush(), Tracer(), and ~Tracer().

pthread_t Tracer::thread_flush_
private

Definition at line 115 of file tracer.h.

Referenced by Tracer(), and ~Tracer().

std::string Tracer::trace_file_
private

Definition at line 105 of file tracer.h.

Referenced by MainFlush().


The documentation for this class was generated from the following files: