Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: media/cast/logging/stats_serializer.cc

Issue 184853003: Cast: Add GetStats() extensions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/cast/logging/stats_serializer.h"
6
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9
10 namespace media {
11 namespace cast {
12
13 // Writes stats provided in |frame_stats_map| and |packet_stats_map| in JSON
14 // format to |out|. See the .cc file for format.
15 bool SerializeStats(const FrameStatsMap& frame_stats_map,
16 const PacketStatsMap& packet_stats_map,
17 std::string* out) {
18 scoped_ptr<base::DictionaryValue> overall_stats(new base::DictionaryValue);
19
20 scoped_ptr<base::DictionaryValue> overall_frame_stats(
21 new base::DictionaryValue);
22 for (FrameStatsMap::const_iterator it = frame_stats_map.begin();
23 it != frame_stats_map.end();
24 ++it) {
25 scoped_ptr<base::DictionaryValue> frame_stats(new base::DictionaryValue);
26
27 frame_stats->SetDouble("firstEventTime",
28 it->second.first_event_time.ToInternalValue());
29 frame_stats->SetDouble("lastEventTime",
30 it->second.last_event_time.ToInternalValue());
31 frame_stats->SetInteger("count", it->second.event_counter);
32 frame_stats->SetInteger("sizeTotal", it->second.sum_size);
33 frame_stats->SetInteger("minDelayMs",
34 it->second.min_delay.InMilliseconds());
35 frame_stats->SetInteger("maxDelayMs",
36 it->second.max_delay.InMilliseconds());
37 frame_stats->SetInteger("sumDelayMs",
38 it->second.sum_delay.InMilliseconds());
39
40 // This might be wrong because frame_stats is local?
41 overall_frame_stats->Set(CastLoggingToString(it->first),
42 frame_stats.release());
43 }
44
45 overall_stats->Set("frameStats", overall_frame_stats.release());
46
47 scoped_ptr<base::DictionaryValue> overall_packet_stats(
48 new base::DictionaryValue);
49 for (PacketStatsMap::const_iterator it = packet_stats_map.begin();
50 it != packet_stats_map.end();
51 ++it) {
52 scoped_ptr<base::DictionaryValue> packet_stats(new base::DictionaryValue);
53
54 packet_stats->SetDouble("firstEventTime",
55 it->second.first_event_time.ToInternalValue());
56 packet_stats->SetDouble("lastEventTime",
57 it->second.last_event_time.ToInternalValue());
58 packet_stats->SetDouble("lastEventTime",
59 it->second.last_event_time.ToInternalValue());
60 packet_stats->SetInteger("count", it->second.event_counter);
61 packet_stats->SetInteger("sizeTotal", it->second.sum_size);
62
63 // This might be wrong?
64 overall_packet_stats->Set(CastLoggingToString(it->first),
65 packet_stats.release());
66 }
67
68 overall_stats->Set("packetStats", overall_packet_stats.release());
69
70 return base::JSONWriter::Write(overall_stats.get(), out);
71 }
72
73 } // namespace cast
74 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698