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

Unified Diff: google_apis/gcm/gcm_stats_recorder.h

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: Addressing arv's comments. 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.h
diff --git a/google_apis/gcm/gcm_stats_recorder.h b/google_apis/gcm/gcm_stats_recorder.h
new file mode 100644
index 0000000000000000000000000000000000000000..0357254a48c260992839c9003f781dd4ec635273
--- /dev/null
+++ b/google_apis/gcm/gcm_stats_recorder.h
@@ -0,0 +1,99 @@
+// 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.
+
+#ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_
+#define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_
+
+#include <deque>
+#include <string>
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "base/time/time.h"
+#include "google_apis/gcm/base/gcm_export.h"
+#include "google_apis/gcm/engine/mcs_client.h"
+
+namespace gcm {
+
+// Records GCM internal stats and activities for debugging purpose. Recording
+// can be turned on/off by calling SetRecording(...) function. It is turned off
+// by default.
+// This class is not thread safe. It is meant to be owned by a gcm client
+// instance.
+class GCM_EXPORT GCMStatsRecorder {
+ public:
+ // Contains data that are common to all activity kinds below.
+ struct GCM_EXPORT Activity {
+ Activity();
+ virtual ~Activity();
+
+ base::Time time;
+ std::string event; // A short description of the event.
+ std::string details; // Any additional detail about the event.
+ };
+
+ // Contains relevant data of a send-message step.
+ struct GCM_EXPORT SendingActivity : Activity {
+ SendingActivity();
+ virtual ~SendingActivity() OVERRIDE;
+
+ std::string app_id;
+ std::string receiver_id;
+ std::string message_id;
+ };
+
+ GCMStatsRecorder();
+ virtual ~GCMStatsRecorder();
+
+ // Indicates whether the recorder is currently recording activities or not.
+ bool is_recording() const {
+ return is_recording_;
+ }
+
+ // Turns recording on/off.
+ void SetRecording(bool recording);
+
+ // Clear all recorded activities.
+ void Clear();
+
+ // Records when the outgoing message is sent to wire.
+ void RecordSentToWire(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ int queued);
+ // Records when the MCS client sends a send status notification to callback.
+ void RecordNotifySendStatus(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ MCSClient::MessageSendStatus status,
+ int byte_size,
+ int ttl);
+ // Records when a 'send error' message is received.
+ void RecordIncomingSendError(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ int byte_size,
+ int ttl);
+
+ const std::deque<SendingActivity>& sending_activities() const {
+ return sending_activities_;
+ }
+
+ protected:
+ void RecordSending(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ const std::string& event,
+ const std::string& details);
+
+ bool is_recording_;
+
+ std::deque<SendingActivity> sending_activities_;
Nicolas Zea 2014/03/27 18:55:42 If this is a circular buffer, why use a dequeue ra
juyik 2014/03/27 20:05:11 My intention is to display events in reverse chron
+
+ DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder);
+};
+
+} // namespace gcm
+
+#endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_

Powered by Google App Engine
This is Rietveld 408576698