OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 709 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 716 of file Logger.cpp.

719  : doc_(json_encoder.doc_), alloc_(doc_->GetAllocator()), begin_(begin), end_(end) {}
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:714
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:713
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:710
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711
logger::JsonEncoder::JsonEncoder ( )
inline

Definition at line 722 of file Logger.cpp.

723  : doc_(std::make_shared<rapidjson::Document>(rapidjson::kObjectType))
724  , alloc_(doc_->GetAllocator()) {}
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:710
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

Member Function Documentation

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

Definition at line 746 of file Logger.cpp.

References alloc_, begin_, and end_.

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

746  {
747  GetDepth const get_depth;
748  rapidjson::Value children(rapidjson::kArrayType);
749  for (auto itr = begin_; itr != end_; ++itr) {
750  int const depth = apply_visitor(get_depth, *itr);
751  if (depth <= parent_depth) {
752  break;
753  }
754  if (depth == parent_depth + 1) {
755  JsonEncoder json_encoder(*this, std::next(itr), end_);
756  children.PushBack(apply_visitor(json_encoder, *itr), alloc_);
757  }
758  }
759  return children;
760  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:714
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:713
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

+ Here is the caller graph for this function:

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

Definition at line 725 of file Logger.cpp.

References alloc_, childNodes(), logger::Duration::depth_, logger::DebugTimerParams::file_, nvtx_helpers::anonymous_namespace{nvtx_helpers.cpp}::filename(), logger::DebugTimerParams::line_, logger::DebugTimerParams::name_, logger::Duration::relative_start_time(), and logger::Duration::value().

725  {
726  rapidjson::Value retval(rapidjson::kObjectType);
727  retval.AddMember("type", "duration", alloc_);
728  retval.AddMember("duration_ms", rapidjson::Value(duration.value()), alloc_);
729  retval.AddMember(
730  "start_ms", rapidjson::Value(duration.relative_start_time()), alloc_);
731  retval.AddMember("name", rapidjson::StringRef(duration->name_), alloc_);
732  retval.AddMember("file", filename(duration->file_), alloc_);
733  retval.AddMember("line", rapidjson::Value(duration->line_), alloc_);
734  retval.AddMember("children", childNodes(duration.depth_), alloc_);
735  return retval;
736  }
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:746
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

+ Here is the call graph for this function:

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

Definition at line 737 of file Logger.cpp.

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

737  {
738  begin_ = duration_tree.durations().cbegin();
739  end_ = duration_tree.durations().cend();
740  rapidjson::Value retval(rapidjson::kObjectType);
741  retval.AddMember("type", "duration_tree", alloc_);
742  retval.AddMember("thread_id", std::to_string(duration_tree.thread_id_), alloc_);
743  retval.AddMember("children", childNodes(duration_tree.depth_), alloc_);
744  return retval;
745  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:714
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:746
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:713
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

+ Here is the call graph for this function:

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

Definition at line 779 of file Logger.cpp.

References alloc_, doc_, and timer().

Referenced by logger::logAndEraseDurationTree().

779  {
780  doc_->AddMember("timer", timer(kv_pair), alloc_);
781  rapidjson::StringBuffer buffer;
782  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
783  doc_->Accept(writer);
784  return {buffer.GetString(), buffer.GetSize()};
785  }
rapidjson::Value timer(DurationTreeMap::const_reference kv_pair)
Definition: Logger.cpp:763
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:710
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

+ 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 763 of file Logger.cpp.

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

Referenced by str().

763  {
764  begin_ = kv_pair.second->durations().cbegin();
765  end_ = kv_pair.second->durations().cend();
766  rapidjson::Value retval(rapidjson::kObjectType);
767  if (begin_ != end_) {
768  auto const& root_duration = boost::get<Duration>(*(begin_++));
769  retval.AddMember("type", "root", alloc_);
770  retval.AddMember("thread_id", std::to_string(kv_pair.first), alloc_);
771  retval.AddMember(
772  "total_duration_ms", rapidjson::Value(root_duration.value()), alloc_);
773  retval.AddMember("name", rapidjson::StringRef(root_duration->name_), alloc_);
774  retval.AddMember("children", childNodes(0), alloc_);
775  }
776  return retval;
777  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:714
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:746
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:713
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:711

+ 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 711 of file Logger.cpp.

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

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

Definition at line 713 of file Logger.cpp.

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

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

Definition at line 710 of file Logger.cpp.

Referenced by str().

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

Definition at line 714 of file Logger.cpp.

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


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