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

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: . 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..7e34256bc7166344c579d96c97ab84a8911f9478
--- /dev/null
+++ b/google_apis/gcm/gcm_stats_recorder.cc
@@ -0,0 +1,198 @@
+// 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/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+
+namespace gcm {
+
+const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100;
+
+namespace {
+
+template <typename T>
+void InsertCircularBuffer(std::deque<T>* q, const T& item) {
+ DCHECK(q);
+ q->push_front(item);
+ if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
+ q->pop_back();
+ }
+}
+
+} // namespace
+
+GCMStatsRecorder::Activity::Activity()
+ : time(base::Time::Now()), type(GCMStatsRecorder::Initiated) {
+}
+
+GCMStatsRecorder::Activity::~Activity() {
+}
+
+std::string GCMStatsRecorder::Activity::GetTypeString() const {
+ switch(type) {
+ case GCMStatsRecorder::Initiated:
+ return "Initiated";
+ case GCMStatsRecorder::RetryRequested:
+ return "RetryRequested";
+ case GCMStatsRecorder::Retry:
+ return "Retry";
+ case GCMStatsRecorder::Success:
+ return "Success";
+ case GCMStatsRecorder::Intermediate:
+ return "Intermediate";
+ case GCMStatsRecorder::Failure:
+ return "Failure";
+ case GCMStatsRecorder::Error:
+ return "Error";
+ default:
+ return "Unknown";
+ }
+}
+
+GCMStatsRecorder::CheckinActivity::CheckinActivity()
+ : android_id(0) {
+}
+
+GCMStatsRecorder::CheckinActivity::~CheckinActivity() {
+}
+
+GCMStatsRecorder::RegisterActivity::RegisterActivity() {
+}
+
+GCMStatsRecorder::RegisterActivity::~RegisterActivity() {
+}
+
+GCMStatsRecorder::SendMessageActivity::SendMessageActivity()
+ : message_len(0) {
+}
+
+GCMStatsRecorder::SendMessageActivity::~SendMessageActivity() {
+}
+
+GCMStatsRecorder::ReceiveMessageActivity::ReceiveMessageActivity()
+ : message_size(0) {
+}
+
+GCMStatsRecorder::ReceiveMessageActivity::~ReceiveMessageActivity() {
+}
+
+GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) {
+}
+
+GCMStatsRecorder::~GCMStatsRecorder() {
+}
+
+void GCMStatsRecorder::SetRecording(bool recording) {
+ is_recording_ = recording;
+}
+
+void GCMStatsRecorder::Clear() {
+ checkin_activities_.clear();
+ register_activities_.clear();
+ send_activities_.clear();
+ receive_activities_.clear();
+}
+
+void GCMStatsRecorder::RecordCheckin(uint64 android_id, ActivityType type){
+ if (!is_recording_)
+ return;
+ CheckinActivity data;
+ data.type = type;
+ data.android_id = android_id;
+ InsertCircularBuffer(&checkin_activities_, data);
jianli 2014/03/18 23:53:23 It might be a bit more efficient by doing somethin
juyik 2014/03/20 01:09:53 Done.
+}
+
+void GCMStatsRecorder::RecordRegister(
+ const std::string& app_id,
+ ActivityType type,
+ const std::vector<std::string>& sender_id) {
+ if (!is_recording_)
+ return;
+ RegisterActivity data;
+ data.type = type;
+ data.app_id = app_id;
+ data.sender_id = JoinString(sender_id, ',');
+ InsertCircularBuffer(&register_activities_, data);
+}
+
+void GCMStatsRecorder::RecordRegisterWithStatus(
+ const std::string& app_id,
+ ActivityType type,
+ const std::vector<std::string>& sender_id,
+ std::string status) {
+ if (!is_recording_)
+ return;
+ RegisterActivity data;
+ data.type = type;
+ data.app_id = app_id;
+ data.sender_id = JoinString(sender_id, ',');
+ data.details = status;
+ InsertCircularBuffer(&register_activities_, data);
+}
+
+void GCMStatsRecorder::RecordSend(const std::string& app_id,
+ ActivityType type,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ uint64 msg_len) {
+ if (!is_recording_)
+ return;
+ RecordSendWithDetails(app_id,
+ type,
+ receiver_id,
+ message_id,
+ msg_len,
+ std::string());
+}
+
+void GCMStatsRecorder::RecordSendWithDetails(const std::string& app_id,
+ ActivityType type,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ uint64 msg_len,
fgorski 2014/03/18 21:28:37 you are not using msg_len
juyik 2014/03/20 01:09:53 Done.
+ const std::string& details) {
+ if (!is_recording_)
+ return;
+ SendMessageActivity data;
+ data.type = type;
+ data.app_id = app_id;
+ data.receiver_id = receiver_id;
+ data.message_id = message_id;
+ data.details = details;
+ InsertCircularBuffer(&send_activities_, data);
+}
+
+void GCMStatsRecorder::RecordReceiveDataMessage(const std::string& sender_id,
+ const std::string& app_id,
+ int message_size) {
+ if (!is_recording_)
+ return;
+ ReceiveMessageActivity data;
+ data.type = GCMStatsRecorder::Success;
+ data.app_id = app_id;
+ data.sender_id = sender_id;
+ data.message_size = message_size;
+ InsertCircularBuffer(&receive_activities_, data);
+}
+
+void GCMStatsRecorder::RecordReceiveWithDetails(ActivityType type,
+ const std::string& sender_id,
+ const std::string& app_id,
+ const std::string& details) {
+ if (!is_recording_)
+ return;
+ ReceiveMessageActivity data;
+ data.type = type;
+ data.app_id = app_id;
+ data.sender_id = sender_id;
+ data.details = details;
+ InsertCircularBuffer(&receive_activities_, data);
+}
+
+} // namespace gcm
« google_apis/gcm/gcm_stats_recorder.h ('K') | « google_apis/gcm/gcm_stats_recorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698