Remove Unused AsTextButtonBorder RTTI helper.
[chromium-blink-merge.git] / media / cast / logging / logging_stats.cc
blobe9e6d729b5eb980c03a5ab005c99630ae9f1451a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/logging/logging_stats.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
10 namespace media {
11 namespace cast {
13 LoggingStats::LoggingStats()
14 : frame_stats_(),
15 packet_stats_(),
16 generic_stats_() {
19 LoggingStats::~LoggingStats() {}
21 void LoggingStats::Reset() {
22 frame_stats_.clear();
23 packet_stats_.clear();
24 generic_stats_.clear();
27 void LoggingStats::InsertFrameEvent(const base::TimeTicks& time_of_event,
28 CastLoggingEvent event,
29 uint32 rtp_timestamp,
30 uint32 frame_id) {
31 InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp);
34 void LoggingStats::InsertFrameEventWithSize(
35 const base::TimeTicks& time_of_event,
36 CastLoggingEvent event,
37 uint32 rtp_timestamp,
38 uint32 frame_id,
39 int frame_size) {
40 InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp);
41 // Update size.
42 FrameStatsMap::iterator it = frame_stats_.find(event);
43 DCHECK(it != frame_stats_.end());
44 it->second.sum_size += frame_size;
47 void LoggingStats::InsertFrameEventWithDelay(
48 const base::TimeTicks& time_of_event,
49 CastLoggingEvent event,
50 uint32 rtp_timestamp,
51 uint32 frame_id,
52 base::TimeDelta delay) {
53 InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp);
54 // Update size.
55 FrameStatsMap::iterator it = frame_stats_.find(event);
56 DCHECK(it != frame_stats_.end());
57 it->second.sum_delay += delay;
58 if (delay > it->second.max_delay || it->second.event_counter == 1)
59 it->second.max_delay = delay;
60 if (delay < it->second.min_delay || it->second.event_counter == 1)
61 it->second.min_delay = delay;
64 void LoggingStats::InsertBaseFrameEvent(const base::TimeTicks& time_of_event,
65 CastLoggingEvent event,
66 uint32 frame_id,
67 uint32 rtp_timestamp) {
68 // Does this belong to an existing event?
69 FrameStatsMap::iterator it = frame_stats_.find(event);
70 if (it == frame_stats_.end()) {
71 // New event.
72 FrameLogStats stats;
73 stats.first_event_time = time_of_event;
74 stats.last_event_time = time_of_event;
75 stats.event_counter = 1;
76 frame_stats_.insert(std::make_pair(event, stats));
77 } else {
78 it->second.last_event_time = time_of_event;
79 ++(it->second.event_counter);
83 void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event,
84 CastLoggingEvent event,
85 uint32 rtp_timestamp,
86 uint32 frame_id,
87 uint16 packet_id,
88 uint16 max_packet_id,
89 size_t size) {
90 // Does this packet belong to an existing event?
91 PacketStatsMap::iterator it = packet_stats_.find(event);
92 if (it == packet_stats_.end()) {
93 // New event.
94 PacketLogStats stats;
95 stats.first_event_time = time_of_event;
96 stats.last_event_time = time_of_event;
97 stats.sum_size = size;
98 stats.event_counter = 1;
99 packet_stats_.insert(std::make_pair(event, stats));
100 } else {
101 // Add to an existing event.
102 it->second.sum_size += size;
103 ++(it->second.event_counter);
107 void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event,
108 CastLoggingEvent event, int value) {
109 // Does this event belong to an existing event?
110 GenericStatsMap::iterator it = generic_stats_.find(event);
111 if (it == generic_stats_.end()) {
112 // New event.
113 GenericLogStats stats;
114 stats.first_event_time = time_of_event;
115 stats.last_event_time = time_of_event;
116 stats.sum = value;
117 stats.sum_squared = value * value;
118 stats.min = value;
119 stats.max = value;
120 stats.event_counter = 1;
121 generic_stats_.insert(std::make_pair(event, stats));
122 } else {
123 // Add to existing event.
124 it->second.sum += value;
125 it->second.sum_squared += value * value;
126 ++(it->second.event_counter);
127 it->second.last_event_time = time_of_event;
128 if (it->second.min > value) {
129 it->second.min = value;
130 } else if (it->second.max < value) {
131 it->second.max = value;
136 FrameStatsMap LoggingStats::GetFrameStatsData() const {
137 return frame_stats_;
140 PacketStatsMap LoggingStats::GetPacketStatsData() const {
141 return packet_stats_;
144 GenericStatsMap LoggingStats::GetGenericStatsData() const {
145 return generic_stats_;
148 } // namespace cast
149 } // namespace media