OmniSciDB  cde582ebc3
 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 651 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 658 of file Logger.cpp.

661  : doc_(json_encoder.doc_), alloc_(doc_->GetAllocator()), begin_(begin), end_(end) {}
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:656
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:655
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:652
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653
logger::JsonEncoder::JsonEncoder ( )
inline

Definition at line 664 of file Logger.cpp.

665  : doc_(std::make_shared<rapidjson::Document>(rapidjson::kObjectType))
666  , alloc_(doc_->GetAllocator()) {}
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:652
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

Member Function Documentation

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

Definition at line 688 of file Logger.cpp.

References alloc_, begin_, and end_.

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

688  {
689  GetDepth const get_depth;
690  rapidjson::Value children(rapidjson::kArrayType);
691  for (auto itr = begin_; itr != end_; ++itr) {
692  int const depth = apply_visitor(get_depth, *itr);
693  if (depth <= parent_depth) {
694  break;
695  }
696  if (depth == parent_depth + 1) {
697  JsonEncoder json_encoder(*this, std::next(itr), end_);
698  children.PushBack(apply_visitor(json_encoder, *itr), alloc_);
699  }
700  }
701  return children;
702  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:656
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:655
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

+ Here is the caller graph for this function:

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

Definition at line 667 of file Logger.cpp.

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

667  {
668  rapidjson::Value retval(rapidjson::kObjectType);
669  retval.AddMember("type", "duration", alloc_);
670  retval.AddMember("duration_ms", rapidjson::Value(duration.value()), alloc_);
671  retval.AddMember(
672  "start_ms", rapidjson::Value(duration.relative_start_time()), alloc_);
673  retval.AddMember("name", rapidjson::StringRef(duration.name_), alloc_);
674  retval.AddMember("file", filename(duration.file_), alloc_);
675  retval.AddMember("line", rapidjson::Value(duration.line_), alloc_);
676  retval.AddMember("children", childNodes(duration.depth_), alloc_);
677  return retval;
678  }
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:688
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

+ Here is the call graph for this function:

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

Definition at line 679 of file Logger.cpp.

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

679  {
680  begin_ = duration_tree.durations().cbegin();
681  end_ = duration_tree.durations().cend();
682  rapidjson::Value retval(rapidjson::kObjectType);
683  retval.AddMember("type", "duration_tree", alloc_);
684  retval.AddMember("thread_id", std::to_string(duration_tree.thread_id_), alloc_);
685  retval.AddMember("children", childNodes(duration_tree.depth_), alloc_);
686  return retval;
687  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:656
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:688
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:655
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

+ Here is the call graph for this function:

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

Definition at line 721 of file Logger.cpp.

References alloc_, doc_, and timer().

Referenced by logger::logAndEraseDurationTree().

721  {
722  doc_->AddMember("timer", timer(kv_pair), alloc_);
723  rapidjson::StringBuffer buffer;
724  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
725  doc_->Accept(writer);
726  return {buffer.GetString(), buffer.GetSize()};
727  }
rapidjson::Value timer(DurationTreeMap::const_reference kv_pair)
Definition: Logger.cpp:705
std::shared_ptr< rapidjson::Document > doc_
Definition: Logger.cpp:652
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

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

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

Referenced by str().

705  {
706  begin_ = kv_pair.second->durations().cbegin();
707  end_ = kv_pair.second->durations().cend();
708  rapidjson::Value retval(rapidjson::kObjectType);
709  if (begin_ != end_) {
710  auto const& root_duration = boost::get<Duration>(*(begin_++));
711  retval.AddMember("type", "root", alloc_);
712  retval.AddMember("thread_id", std::to_string(kv_pair.first), alloc_);
713  retval.AddMember(
714  "total_duration_ms", rapidjson::Value(root_duration.value()), alloc_);
715  retval.AddMember("name", rapidjson::StringRef(root_duration.name_), alloc_);
716  retval.AddMember("children", childNodes(0), alloc_);
717  }
718  return retval;
719  }
DurationTreeNodes::const_iterator end_
Definition: Logger.cpp:656
rapidjson::Value childNodes(int const parent_depth)
Definition: Logger.cpp:688
std::string to_string(char const *&&v)
DurationTreeNodes::const_iterator begin_
Definition: Logger.cpp:655
rapidjson::Document::AllocatorType & alloc_
Definition: Logger.cpp:653

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

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

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

Definition at line 655 of file Logger.cpp.

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

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

Definition at line 652 of file Logger.cpp.

Referenced by str().

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

Definition at line 656 of file Logger.cpp.

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


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