Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timelinenode.h
Go to the documentation of this file.
1 
18 #ifndef ION_PROFILE_TIMELINENODE_H_
19 #define ION_PROFILE_TIMELINENODE_H_
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "base/integral_types.h"
26 
28 class TimelineNode {
29  public:
30  typedef std::vector<std::unique_ptr<TimelineNode>> Children;
31  enum class Type : char { kNode, kEvent, kThread, kFrame, kScope, kRange };
32 
33  explicit TimelineNode(const std::string& name);
34  TimelineNode(const std::string& name, const uint32 begin,
35  const uint32 duration);
36  virtual ~TimelineNode();
37 
39  void AddChild(std::unique_ptr<TimelineNode> child);
41  void UpdateDuration(const uint32 end) { duration_ = end - begin_; }
42 
43  const std::string& GetName() const { return name_; }
44  virtual Type GetType() const { return Type::kNode; }
45  uint32 GetBegin() const { return begin_; }
46  uint32 GetEnd() const { return begin_ + duration_; }
47  uint32 GetDuration() const { return duration_; }
48  double GetBeginMs() const { return begin_ * 0.001; }
49  double GetEndMs() const { return (begin_ + duration_) * 0.001; }
50  double GetDurationMs() const { return duration_ * 0.001; }
51  const TimelineNode* GetParent() const { return parent_; }
52  TimelineNode* GetParent() { return parent_; }
53  const Children& GetChildren() const { return children_; }
54  const TimelineNode* GetChild(const size_t i) const {
55  return children_[i].get();
56  }
57 
58  private:
60  std::string name_;
62  uint32 begin_;
64  uint32 duration_;
66  TimelineNode* parent_;
68  Children children_;
69 };
70 
71 inline void TimelineNode::AddChild(std::unique_ptr<TimelineNode> child) {
72  child->parent_ = this;
73  children_.push_back(std::move(child));
74 }
75 
76 #endif // ION_PROFILE_TIMELINENODE_H_
void UpdateDuration(const uint32 end)
Update the duration of the event given a new end timestamp.
Definition: timelinenode.h:41
double GetDurationMs() const
Definition: timelinenode.h:50
void AddChild(std::unique_ptr< TimelineNode > child)
Add a node to the children. It becomes the last child.
Definition: timelinenode.h:71
TimelineNode * GetParent()
Definition: timelinenode.h:52
uint32 GetBegin() const
Definition: timelinenode.h:45
virtual Type GetType() const
Definition: timelinenode.h:44
double GetEndMs() const
Definition: timelinenode.h:49
virtual ~TimelineNode()
Definition: timelinenode.cc:32
const Children & GetChildren() const
Definition: timelinenode.h:53
std::string name
Definition: printer.cc:324
const TimelineNode * GetParent() const
Definition: timelinenode.h:51
Copyright 2016 Google Inc.
Definition: timelinenode.h:28
std::vector< std::unique_ptr< TimelineNode > > Children
Definition: timelinenode.h:30
double GetBeginMs() const
Definition: timelinenode.h:48
uint32 GetDuration() const
Definition: timelinenode.h:47
TimelineNode(const std::string &name)
Copyright 2016 Google Inc.
Definition: timelinenode.cc:25
uint32 GetEnd() const
Definition: timelinenode.h:46
const std::string & GetName() const
Definition: timelinenode.h:43
const TimelineNode * GetChild(const size_t i) const
Definition: timelinenode.h:54