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

Unified Diff: google_apis/gcm/gcm_stats_recorder.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address all code reviews. 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gcm/gcm_stats_recorder.cc
diff --git a/google_apis/gcm/gcm_stats_recorder.cc b/google_apis/gcm/gcm_stats_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e05d04580d28fe916085060f2fd151f2eb9e0501
--- /dev/null
+++ b/google_apis/gcm/gcm_stats_recorder.cc
@@ -0,0 +1,101 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gcm/gcm_stats_recorder.h"
+
+#include <deque>
+
+#include "base/logging.h"
+#include "base/metrics/histogram.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+
+namespace gcm {
+
+const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100;
+
+namespace {
+
+template <typename T>
+T* InsertCircularBuffer(std::deque<T>* q, const T& item) {
+ DCHECK(q);
+ q->push_front(item);
+ if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
+ q->pop_back();
+ }
+ return &q->front();
+}
+
+} // namespace
+
+GCMStatsRecorder::Activity::Activity()
+ : time(base::Time::Now()) {
+}
+
+GCMStatsRecorder::Activity::~Activity() {
+}
+
+GCMStatsRecorder::SendingActivity::SendingActivity() {
+}
+
+GCMStatsRecorder::SendingActivity::~SendingActivity() {
+}
+
+GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) {
+}
+
+GCMStatsRecorder::~GCMStatsRecorder() {
+}
+
+void GCMStatsRecorder::SetRecording(bool recording) {
+ is_recording_ = recording;
+}
+
+void GCMStatsRecorder::Clear() {
+ sending_activities_.clear();
+}
+
+void GCMStatsRecorder::RecordSending(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ const std::string& event,
+ const std::string& details) {
+ if (!is_recording_)
+ return;
+ SendingActivity data;
+ SendingActivity* inserted_data = InsertCircularBuffer(
+ &sending_activities_, data);
+ inserted_data->app_id = app_id;
+ inserted_data->receiver_id = receiver_id;
+ inserted_data->message_id = message_id;
+ inserted_data->event = event;
+ inserted_data->details = details;
+}
+
+void GCMStatsRecorder::RecordSendingWithUMAEnum(
+ const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ const std::string& event,
+ const std::string& details,
+ const std::string& uma_name,
+ int uma_value,
+ int uma_value_bound) {
+ RecordSending(app_id, receiver_id, message_id, event, details);
+ UMA_HISTOGRAM_ENUMERATION(uma_name, uma_value, uma_value_bound);
jianli 2014/03/21 18:25:27 It seems to me the only difference among these 3 R
juyik 2014/03/26 04:06:03 According to team consensus, I have changed the cl
+}
+
+void GCMStatsRecorder::RecordSendingWithUMACounts(
+ const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ const std::string& event,
+ const std::string& details,
+ const std::string& uma_name,
+ int uma_value) {
+ RecordSending(app_id, receiver_id, message_id, event, details);
+ UMA_HISTOGRAM_COUNTS(uma_name, uma_value);
+}
+
+} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698