OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logger::JsonEncoder Class Reference
+ Inheritance diagram for logger::JsonEncoder:
+ Collaboration diagram for logger::JsonEncoder:

Public Member Functions

 JsonEncoder ()
 
rapidjson::Value operator() (Duration const &duration)
 
rapidjson::Value operator() (DurationTree const &duration_tree)
 
rapidjson::Value childNodes (int const parent_depth)
 
rapidjson::Value timer (DurationTreeMap::const_reference kv_pair)
 
std::string str (DurationTreeMap::const_reference kv_pair)
 

Private Member Functions

 JsonEncoder (JsonEncoder &json_encoder, DurationTreeNodes::const_iterator begin, DurationTreeNodes::const_iterator end)
 

Private Attributes

std::shared_ptr
< rapidjson::Document > 
doc_
 
rapidjson::Document::AllocatorType & alloc_
 
DurationTreeNodes::const_iterator begin_
 
DurationTreeNodes::const_iterator end_
 

Detailed Description

Definition at line 561 of file Logger.cpp.

Constructor & Destructor Documentation

logger::JsonEncoder::JsonEncoder ( JsonEncoder json_encoder,
DurationTreeNodes::const_iterator  begin,
DurationTreeNodes::const_iterator  end 
)
inlineprivate

Definition at line 568 of file Logger.cpp.

571  : doc_(json_encoder.doc_), alloc_(doc_->GetAllocator()), begin_(begin), end_(end) {}
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:566
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:565
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:562
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563
logger::JsonEncoder::JsonEncoder ( )
inline

Definition at line 574 of file Logger.cpp.

575  : doc_(std::make_shared<rapidjson::Document>(rapidjson::kObjectType))
576  , alloc_(doc_->GetAllocator()) {}
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:562
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

Member Function Documentation

rapidjson::Value logger::JsonEncoder::childNodes ( int const  parent_depth)
inline

Definition at line 598 of file Logger.cpp.

References alloc_, begin_, and end_.

Referenced by operator()(), and timer().

598  {
599  GetDepth const get_depth;
600  rapidjson::Value children(rapidjson::kArrayType);
601  for (auto itr = begin_; itr != end_; ++itr) {
602  int const depth = apply_visitor(get_depth, *itr);
603  if (depth <= parent_depth) {
604  break;
605  }
606  if (depth == parent_depth + 1) {
607  JsonEncoder json_encoder(*this, std::next(itr), end_);
608  children.PushBack(apply_visitor(json_encoder, *itr), alloc_);
609  }
610  }
611  return children;
612  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:566
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:565
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

+ Here is the caller graph for this function:

rapidjson::Value logger::JsonEncoder::operator() ( Duration const &  duration)
inline

Definition at line 577 of file Logger.cpp.

References alloc_, childNodes(), logger::Duration::depth_, logger::Duration::file_, logger::filename(), logger::Duration::line_, logger::Duration::name_, logger::Duration::relative_start_time(), and logger::Duration::value().

577  {
578  rapidjson::Value retval(rapidjson::kObjectType);
579  retval.AddMember("type", "duration", alloc_);
580  retval.AddMember("duration_ms", rapidjson::Value(duration.value()), alloc_);
581  retval.AddMember(
582  "start_ms", rapidjson::Value(duration.relative_start_time()), alloc_);
583  retval.AddMember("name", rapidjson::StringRef(duration.name_), alloc_);
584  retval.AddMember("file", filename(duration.file_), alloc_);
585  retval.AddMember("line", rapidjson::Value(duration.line_), alloc_);
586  retval.AddMember("children", childNodes(duration.depth_), alloc_);
587  return retval;
588  }
std::string filename(char const *path)
Definition: Logger.cpp:62
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:598
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

+ Here is the call graph for this function:

rapidjson::Value logger::JsonEncoder::operator() ( DurationTree const &  duration_tree)
inline

Definition at line 589 of file Logger.cpp.

References alloc_, begin_, childNodes(), logger::DurationTree::depth_, logger::DurationTree::durations(), end_, logger::DurationTree::thread_id_, and to_string().

589  {
590  begin_ = duration_tree.durations().cbegin();
591  end_ = duration_tree.durations().cend();
592  rapidjson::Value retval(rapidjson::kObjectType);
593  retval.AddMember("type", "duration_tree", alloc_);
594  retval.AddMember("thread_id", to_string(duration_tree.thread_id_), alloc_);
595  retval.AddMember("children", childNodes(duration_tree.depth_), alloc_);
596  return retval;
597  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:566
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:598
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:565
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

+ Here is the call graph for this function:

std::string logger::JsonEncoder::str ( DurationTreeMap::const_reference  kv_pair)
inline

Definition at line 631 of file Logger.cpp.

References alloc_, doc_, and timer().

Referenced by logger::logAndEraseDurationTree().

631  {
632  doc_->AddMember("timer", timer(kv_pair), alloc_);
633  rapidjson::StringBuffer buffer;
634  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
635  doc_->Accept(writer);
636  return {buffer.GetString(), buffer.GetSize()};
637  }
rapidjson::Value timer(DurationTreeMap::const_reference kv_pair)
Definition: Logger.cpp:615
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:562
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rapidjson::Value logger::JsonEncoder::timer ( DurationTreeMap::const_reference  kv_pair)
inline

Definition at line 615 of file Logger.cpp.

References alloc_, begin_, childNodes(), end_, and to_string().

Referenced by str().

615  {
616  begin_ = kv_pair.second->durations().cbegin();
617  end_ = kv_pair.second->durations().cend();
618  rapidjson::Value retval(rapidjson::kObjectType);
619  if (begin_ != end_) {
620  auto const& root_duration = boost::get<Duration>(*(begin_++));
621  retval.AddMember("type", "root", alloc_);
622  retval.AddMember("thread_id", to_string(kv_pair.first), alloc_);
623  retval.AddMember(
624  "total_duration_ms", rapidjson::Value(root_duration.value()), alloc_);
625  retval.AddMember("name", rapidjson::StringRef(root_duration.name_), alloc_);
626  retval.AddMember("children", childNodes(0), alloc_);
627  }
628  return retval;
629  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:566
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:598
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:565
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:563

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

rapidjson::Document::AllocatorType& logger::JsonEncoder::alloc_
private

Definition at line 563 of file Logger.cpp.

Referenced by childNodes(), operator()(), str(), and timer().

DurationTreeNodes::const_iterator logger::JsonEncoder::begin_
private

Definition at line 565 of file Logger.cpp.

Referenced by childNodes(), operator()(), and timer().

std::shared_ptr<rapidjson::Document> logger::JsonEncoder::doc_
private

Definition at line 562 of file Logger.cpp.

Referenced by str().

DurationTreeNodes::const_iterator logger::JsonEncoder::end_
private

Definition at line 566 of file Logger.cpp.

Referenced by childNodes(), operator()(), and timer().


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