libfoedus-core
FOEDUS Core Library
foedus::debugging::DebuggingSupports Class Referencefinal

APIs to support debugging functionalities. More...

Detailed Description

APIs to support debugging functionalities.

Definition at line 35 of file debugging_supports.hpp.

#include <debugging_supports.hpp>

Inheritance diagram for foedus::debugging::DebuggingSupports:
Collaboration diagram for foedus::debugging::DebuggingSupports:

Classes

struct  PapiCounters
 

Public Member Functions

 DebuggingSupports ()=delete
 
 DebuggingSupports (Engine *engine)
 
ErrorStack initialize_once () override
 
ErrorStack uninitialize_once () override
 
void set_debug_log_to_stderr (bool value)
 Whether to write debug logs to stderr rather than log file. More...
 
void set_debug_log_stderr_threshold (DebuggingOptions::DebugLogLevel level)
 Debug logs at or above this level will be copied to stderr. More...
 
void set_debug_log_min_threshold (DebuggingOptions::DebugLogLevel level)
 Debug logs below this level will be completely ignored. More...
 
void set_verbose_log_level (int verbose)
 Verbose debug logs (VLOG(m)) at or less than this number will be shown. More...
 
void set_verbose_module (const std::string &module, int verbose)
 Per-module verbose level. More...
 
ErrorStack start_profile (const std::string &output_file)
 Start running a CPU profiler (gperftools/PAPI). More...
 
void stop_profile ()
 Stop CPU profiling. More...
 
void start_papi_counters ()
 Start collecting performance counters via PAPI if it's available. More...
 
void stop_papi_counters ()
 Stop collecting performance counters via PAPI. More...
 
const PapiCountersget_papi_counters () const
 Returns the profiled PAPI counters. More...
 
- Public Member Functions inherited from foedus::DefaultInitializable
 DefaultInitializable ()
 
virtual ~DefaultInitializable ()
 
 DefaultInitializable (const DefaultInitializable &)=delete
 
DefaultInitializableoperator= (const DefaultInitializable &)=delete
 
ErrorStack initialize () override final
 Typical implementation of Initializable::initialize() that provides initialize-once semantics. More...
 
ErrorStack uninitialize () override final
 Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics. More...
 
bool is_initialized () const override final
 Returns whether the object has been already initialized or not. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Static Public Member Functions

static std::vector< std::string > describe_papi_counters (const PapiCounters &counters)
 Returns a human-readable explanation of PAPI counters. More...
 

Constructor & Destructor Documentation

foedus::debugging::DebuggingSupports::DebuggingSupports ( )
delete
foedus::debugging::DebuggingSupports::DebuggingSupports ( Engine engine)
inlineexplicit

Definition at line 43 of file debugging_supports.hpp.

43 : engine_(engine) {}

Member Function Documentation

std::vector< std::string > foedus::debugging::DebuggingSupports::describe_papi_counters ( const PapiCounters counters)
static

Returns a human-readable explanation of PAPI counters.

One string for one counter to avoid returning too long string.

Definition at line 220 of file debugging_supports.cpp.

221  {
222  std::vector<std::string> ret;
223  ret.emplace_back("libpapi was not linked. No PAPI profile is collected");
224  return ret;
225 }
const PapiCounters& foedus::debugging::DebuggingSupports::get_papi_counters ( ) const
inline

Returns the profiled PAPI counters.

must be called after stop_profile(). You must call start_profile() with papi_counters=true.

Definition at line 88 of file debugging_supports.hpp.

88 { return papi_counters_; }
ErrorStack foedus::debugging::DebuggingSupports::initialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 117 of file debugging_supports.cpp.

References foedus::Engine::is_emulated_child(), and foedus::kRetOk.

117  {
118  // glog is already initialized by master, so emulated child does nothing
119  if (engine_->is_emulated_child()) {
120  return kRetOk;
121  }
122  initialize_glog(); // initialize glog at the beginning. we can use glog since now
123  std::memset(&papi_counters_, 0, sizeof(papi_counters_));
124  papi_enabled_ = false;
125  return kRetOk;
126 }
bool is_emulated_child() const
Returns if this engine object is a child instance running just as a thread.
Definition: engine.cpp:69
const ErrorStack kRetOk
Normal return value for no-error case.

Here is the call graph for this function:

void foedus::debugging::DebuggingSupports::set_debug_log_min_threshold ( DebuggingOptions::DebugLogLevel  level)

Debug logs below this level will be completely ignored.

Default is kDebugLogInfo. There is an API to change this setting at runtime.

Definition at line 143 of file debugging_supports.cpp.

143  {
144  FLAGS_minloglevel = static_cast<int>(level);
145  LOG(INFO) << "Changed glog's FLAGS_minloglevel to " << level;
146 }
void foedus::debugging::DebuggingSupports::set_debug_log_stderr_threshold ( DebuggingOptions::DebugLogLevel  level)

Debug logs at or above this level will be copied to stderr.

Default is kDebugLogInfo. There is an API to change this setting at runtime.

Definition at line 139 of file debugging_supports.cpp.

139  {
140  FLAGS_stderrthreshold = static_cast<int>(level);
141  LOG(INFO) << "Changed glog's FLAGS_stderrthreshold to " << level;
142 }
void foedus::debugging::DebuggingSupports::set_debug_log_to_stderr ( bool  value)

Whether to write debug logs to stderr rather than log file.

Default is false. There is an API to change this setting at runtime.

Definition at line 135 of file debugging_supports.cpp.

135  {
136  FLAGS_logtostderr = value;
137  LOG(INFO) << "Changed glog's FLAGS_logtostderr to " << value;
138 }
void foedus::debugging::DebuggingSupports::set_verbose_log_level ( int  verbose)

Verbose debug logs (VLOG(m)) at or less than this number will be shown.

Default is 0. There is an API to change this setting at runtime.

Definition at line 147 of file debugging_supports.cpp.

147  {
148  FLAGS_v = verbose;
149  LOG(INFO) << "Changed glog's FLAGS_v to " << verbose;
150 }
void foedus::debugging::DebuggingSupports::set_verbose_module ( const std::string &  module,
int  verbose 
)

Per-module verbose level.

The value has to contain a comma-separated list of 'module name'='log level'. 'module name' is a glob pattern (e.g., gfs* for all modules whose name starts with "gfs"), matched against the filename base (that is, name ignoring .cc/.h./-inl.h) Default is "". There is an API to change this setting at runtime.

Definition at line 151 of file debugging_supports.cpp.

151  {
152  // Watch out for this bug, if we get a crash here:
153  // https://code.google.com/p/google-glog/issues/detail?id=172
154  google::SetVLOGLevel(module.c_str(), verbose);
155  LOG(INFO) << "Invoked google::SetVLOGLevel for " << module << ", level=" << verbose;
156 }
void foedus::debugging::DebuggingSupports::start_papi_counters ( )

Start collecting performance counters via PAPI if it's available.

Definition at line 216 of file debugging_supports.cpp.

216  {
217  LOG(WARNING) << "libpapi was not linked. No PAPI profile is collected.";
218 }
ErrorStack foedus::debugging::DebuggingSupports::start_profile ( const std::string &  output_file)

Start running a CPU profiler (gperftools/PAPI).

Parameters
[in]output_filepath to output the profile result.

This feature is enabled only when you link to libprofiler.so. For example, use it like this:

CHECK_ERROR(engine.get_debug()->start_profile("hoge.prof"));
for (int i = 0; i < 1000000; ++i) do_something();
engine.get_debug()->stop_profile("hoge.prof");

Then, after the execution,

1 pprof --pdf your_binary hoge.prof > hoge.pdf
2 okular hoge.pdf

Definition at line 229 of file debugging_supports.cpp.

References ERROR_STACK, foedus::kErrorCodeDbgGperftools, foedus::kRetOk, and foedus::assorted::os_error().

229  {
230 #ifdef HAVE_GOOGLEPERFTOOLS
231  int ret = ::ProfilerStart(output_file.c_str());
232  if (ret == 0) {
233  LOG(ERROR) << "ProfilerStart() returned zero (an error). os_error=" << assorted::os_error();
235  }
236 #else // HAVE_GOOGLEPERFTOOLS
237  LOG(WARNING) << "Google perftools was not linked. No profile is provided. " << output_file;
238 #endif // HAVE_GOOGLEPERFTOOLS
239  return kRetOk;
240 }
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
std::string os_error()
Thread-safe strerror(errno).
const ErrorStack kRetOk
Normal return value for no-error case.
0x0B01 : "DEBUG : Gperftools reported an error" .
Definition: error_code.hpp:212

Here is the call graph for this function:

void foedus::debugging::DebuggingSupports::stop_papi_counters ( )

Stop collecting performance counters via PAPI.

Definition at line 219 of file debugging_supports.cpp.

219 {}
void foedus::debugging::DebuggingSupports::stop_profile ( )

Stop CPU profiling.

Definition at line 242 of file debugging_supports.cpp.

242  {
243 #ifdef HAVE_GOOGLEPERFTOOLS
244  ::ProfilerStop();
245 #endif // HAVE_GOOGLEPERFTOOLS
246 }
ErrorStack foedus::debugging::DebuggingSupports::uninitialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 127 of file debugging_supports.cpp.

References foedus::Engine::is_emulated_child(), and foedus::kRetOk.

127  {
128  if (engine_->is_emulated_child()) {
129  return kRetOk;
130  }
131  uninitialize_glog(); // release glog at the end. we can't use glog since now
132  return kRetOk;
133 }
bool is_emulated_child() const
Returns if this engine object is a child instance running just as a thread.
Definition: engine.cpp:69
const ErrorStack kRetOk
Normal return value for no-error case.

Here is the call graph for this function:


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