OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/logging/stats_event_subscriber.h" | 5 #include "media/cast/logging/stats_event_subscriber.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 bool IsReceiverEvent(CastLoggingEvent event) { | 29 bool IsReceiverEvent(CastLoggingEvent event) { |
30 return event == FRAME_DECODED | 30 return event == FRAME_DECODED |
31 || event == FRAME_PLAYOUT | 31 || event == FRAME_PLAYOUT |
32 || event == FRAME_ACK_SENT | 32 || event == FRAME_ACK_SENT |
33 || event == PACKET_RECEIVED; | 33 || event == PACKET_RECEIVED; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 StatsEventSubscriber::SimpleHistogram::SimpleHistogram(int64 min, | 38 StatsEventSubscriber::SimpleHistogram::SimpleHistogram(int64_t min, |
39 int64 max, | 39 int64_t max, |
40 int64 width) | 40 int64_t width) |
41 : min_(min), max_(max), width_(width), buckets_((max - min) / width + 2) { | 41 : min_(min), max_(max), width_(width), buckets_((max - min) / width + 2) { |
42 CHECK_GT(buckets_.size(), 2u); | 42 CHECK_GT(buckets_.size(), 2u); |
43 CHECK_EQ(0, (max_ - min_) % width_); | 43 CHECK_EQ(0, (max_ - min_) % width_); |
44 } | 44 } |
45 | 45 |
46 StatsEventSubscriber::SimpleHistogram::~SimpleHistogram() { | 46 StatsEventSubscriber::SimpleHistogram::~SimpleHistogram() { |
47 } | 47 } |
48 | 48 |
49 void StatsEventSubscriber::SimpleHistogram::Add(int64 sample) { | 49 void StatsEventSubscriber::SimpleHistogram::Add(int64_t sample) { |
50 if (sample < min_) { | 50 if (sample < min_) { |
51 ++buckets_.front(); | 51 ++buckets_.front(); |
52 } else if (sample >= max_) { | 52 } else if (sample >= max_) { |
53 ++buckets_.back(); | 53 ++buckets_.back(); |
54 } else { | 54 } else { |
55 size_t index = 1 + (sample - min_) / width_; | 55 size_t index = 1 + (sample - min_) / width_; |
56 DCHECK_LT(index, buckets_.size()); | 56 DCHECK_LT(index, buckets_.size()); |
57 ++buckets_[index]; | 57 ++buckets_[index]; |
58 } | 58 } |
59 } | 59 } |
(...skipping 11 matching lines...) Expand all Loading... |
71 if (buckets_.front()) { | 71 if (buckets_.front()) { |
72 bucket->SetInteger(base::StringPrintf("<%" PRId64, min_), | 72 bucket->SetInteger(base::StringPrintf("<%" PRId64, min_), |
73 buckets_.front()); | 73 buckets_.front()); |
74 histo->Append(bucket.release()); | 74 histo->Append(bucket.release()); |
75 } | 75 } |
76 | 76 |
77 for (size_t i = 1; i < buckets_.size() - 1; i++) { | 77 for (size_t i = 1; i < buckets_.size() - 1; i++) { |
78 if (!buckets_[i]) | 78 if (!buckets_[i]) |
79 continue; | 79 continue; |
80 bucket.reset(new base::DictionaryValue); | 80 bucket.reset(new base::DictionaryValue); |
81 int64 lower = min_ + (i - 1) * width_; | 81 int64_t lower = min_ + (i - 1) * width_; |
82 int64 upper = lower + width_ - 1; | 82 int64_t upper = lower + width_ - 1; |
83 bucket->SetInteger( | 83 bucket->SetInteger( |
84 base::StringPrintf("%" PRId64 "-%" PRId64, lower, upper), | 84 base::StringPrintf("%" PRId64 "-%" PRId64, lower, upper), |
85 buckets_[i]); | 85 buckets_[i]); |
86 histo->Append(bucket.release()); | 86 histo->Append(bucket.release()); |
87 } | 87 } |
88 | 88 |
89 if (buckets_.back()) { | 89 if (buckets_.back()) { |
90 bucket.reset(new base::DictionaryValue); | 90 bucket.reset(new base::DictionaryValue); |
91 bucket->SetInteger(base::StringPrintf(">=%" PRId64, max_), | 91 bucket->SetInteger(base::StringPrintf(">=%" PRId64, max_), |
92 buckets_.back()); | 92 buckets_.back()); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 base::TimeTicks receiver_time) { | 589 base::TimeTicks receiver_time) { |
590 base::TimeDelta receiver_offset; | 590 base::TimeDelta receiver_offset; |
591 if (!GetReceiverOffset(&receiver_offset)) | 591 if (!GetReceiverOffset(&receiver_offset)) |
592 return; | 592 return; |
593 base::TimeTicks sender_time = receiver_time - receiver_offset; | 593 base::TimeTicks sender_time = receiver_time - receiver_offset; |
594 last_response_received_time_ = sender_time; | 594 last_response_received_time_ = sender_time; |
595 } | 595 } |
596 | 596 |
597 void StatsEventSubscriber::ErasePacketSentTime( | 597 void StatsEventSubscriber::ErasePacketSentTime( |
598 const PacketEvent& packet_event) { | 598 const PacketEvent& packet_event) { |
599 std::pair<RtpTimestamp, uint16> key( | 599 std::pair<RtpTimestamp, uint16_t> key( |
600 std::make_pair(packet_event.rtp_timestamp, packet_event.packet_id)); | 600 std::make_pair(packet_event.rtp_timestamp, packet_event.packet_id)); |
601 packet_sent_times_.erase(key); | 601 packet_sent_times_.erase(key); |
602 } | 602 } |
603 | 603 |
604 void StatsEventSubscriber::RecordPacketRelatedLatencies( | 604 void StatsEventSubscriber::RecordPacketRelatedLatencies( |
605 const PacketEvent& packet_event) { | 605 const PacketEvent& packet_event) { |
606 // Log queueing latency. | 606 // Log queueing latency. |
607 if (packet_event.type == PACKET_SENT_TO_NETWORK) { | 607 if (packet_event.type == PACKET_SENT_TO_NETWORK) { |
608 FrameInfoMap::iterator it = | 608 FrameInfoMap::iterator it = |
609 recent_frame_infos_.find(packet_event.rtp_timestamp); | 609 recent_frame_infos_.find(packet_event.rtp_timestamp); |
610 if (it != recent_frame_infos_.end()) { | 610 if (it != recent_frame_infos_.end()) { |
611 base::TimeDelta latency = | 611 base::TimeDelta latency = |
612 packet_event.timestamp - it->second.encode_end_time; | 612 packet_event.timestamp - it->second.encode_end_time; |
613 total_queueing_latency_ += latency; | 613 total_queueing_latency_ += latency; |
614 queueing_latency_datapoints_++; | 614 queueing_latency_datapoints_++; |
615 histograms_[QUEUEING_LATENCY_MS_HISTO]->Add( | 615 histograms_[QUEUEING_LATENCY_MS_HISTO]->Add( |
616 latency.InMillisecondsF()); | 616 latency.InMillisecondsF()); |
617 } | 617 } |
618 } | 618 } |
619 | 619 |
620 // Log network latency and total packet latency; | 620 // Log network latency and total packet latency; |
621 base::TimeDelta receiver_offset; | 621 base::TimeDelta receiver_offset; |
622 if (!GetReceiverOffset(&receiver_offset)) | 622 if (!GetReceiverOffset(&receiver_offset)) |
623 return; | 623 return; |
624 | 624 |
625 std::pair<RtpTimestamp, uint16> key( | 625 std::pair<RtpTimestamp, uint16_t> key( |
626 std::make_pair(packet_event.rtp_timestamp, packet_event.packet_id)); | 626 std::make_pair(packet_event.rtp_timestamp, packet_event.packet_id)); |
627 PacketEventTimeMap::iterator it = packet_sent_times_.find(key); | 627 PacketEventTimeMap::iterator it = packet_sent_times_.find(key); |
628 if (it == packet_sent_times_.end()) { | 628 if (it == packet_sent_times_.end()) { |
629 std::pair<base::TimeTicks, CastLoggingEvent> value = | 629 std::pair<base::TimeTicks, CastLoggingEvent> value = |
630 std::make_pair(packet_event.timestamp, packet_event.type); | 630 std::make_pair(packet_event.timestamp, packet_event.type); |
631 packet_sent_times_.insert(std::make_pair(key, value)); | 631 packet_sent_times_.insert(std::make_pair(key, value)); |
632 if (packet_sent_times_.size() > kMaxPacketEventTimeMapSize) | 632 if (packet_sent_times_.size() > kMaxPacketEventTimeMapSize) |
633 packet_sent_times_.erase(packet_sent_times_.begin()); | 633 packet_sent_times_.erase(packet_sent_times_.begin()); |
634 } else { | 634 } else { |
635 std::pair<base::TimeTicks, CastLoggingEvent> value = it->second; | 635 std::pair<base::TimeTicks, CastLoggingEvent> value = it->second; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 : event_counter(0), sum_size(0) {} | 747 : event_counter(0), sum_size(0) {} |
748 StatsEventSubscriber::PacketLogStats::~PacketLogStats() {} | 748 StatsEventSubscriber::PacketLogStats::~PacketLogStats() {} |
749 | 749 |
750 StatsEventSubscriber::FrameInfo::FrameInfo() : encoded(false) { | 750 StatsEventSubscriber::FrameInfo::FrameInfo() : encoded(false) { |
751 } | 751 } |
752 StatsEventSubscriber::FrameInfo::~FrameInfo() { | 752 StatsEventSubscriber::FrameInfo::~FrameInfo() { |
753 } | 753 } |
754 | 754 |
755 } // namespace cast | 755 } // namespace cast |
756 } // namespace media | 756 } // namespace media |
OLD | NEW |