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

Unified Diff: google_apis/gcm/engine/mcs_client.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/engine/mcs_client.cc
diff --git a/google_apis/gcm/engine/mcs_client.cc b/google_apis/gcm/engine/mcs_client.cc
index c203c2a6bb259545de2d3b32dadd7e57505d4721..02dccc39b2d9c40ff858b9f826086a45b23f1954 100644
--- a/google_apis/gcm/engine/mcs_client.cc
+++ b/google_apis/gcm/engine/mcs_client.cc
@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringprintf.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "google_apis/gcm/base/mcs_util.h"
@@ -63,6 +64,30 @@ bool BuildPersistentIdListFromProto(const google::protobuf::string& bytes,
return true;
}
+// Helper for getting string representation of the MessageSendStatus enum.
+std::string GetMessageSendStatusString(
+ gcm::MCSClient::MessageSendStatus status) {
+ switch (status) {
+ case gcm::MCSClient::QUEUED:
+ return "QUEUED";
+ case gcm::MCSClient::SENT:
+ return "SENT";
+ case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED:
+ return "QUEUE_SIZE_LIMIT_REACHED";
+ case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
+ return "APP_QUEUE_SIZE_LIMIT_REACHED";
+ case gcm::MCSClient::MESSAGE_TOO_LARGE:
+ return "MESSAGE_TOO_LARGE";
+ case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL:
+ return "NO_CONNECTION_ON_ZERO_TTL";
+ case gcm::MCSClient::TTL_EXCEEDED:
+ return "TTL_EXCEEDED";
+ default:
+ NOTREACHED();
+ return "UNKNOWN";
+ }
+}
+
} // namespace
class CollapseKey {
@@ -128,6 +153,14 @@ ReliablePacketInfo::ReliablePacketInfo()
}
ReliablePacketInfo::~ReliablePacketInfo() {}
+int MCSClient::GetSendQueueSize() const {
+ return to_send_.size();
+}
+
+int MCSClient::GetUnackedQueueSize() const {
+ return to_resend_.size();
+}
+
std::string MCSClient::GetStateString() const {
switch(state_) {
case UNINITIALIZED:
@@ -147,7 +180,8 @@ std::string MCSClient::GetStateString() const {
MCSClient::MCSClient(const std::string& version_string,
base::Clock* clock,
ConnectionFactory* connection_factory,
- GCMStore* gcm_store)
+ GCMStore* gcm_store,
+ GCMStatsRecorder* recorder)
: version_string_(version_string),
clock_(clock),
state_(UNINITIALIZED),
@@ -160,6 +194,7 @@ MCSClient::MCSClient(const std::string& version_string,
stream_id_out_(0),
stream_id_in_(0),
gcm_store_(gcm_store),
+ recorder_(recorder),
weak_ptr_factory_(this) {
}
@@ -495,6 +530,12 @@ void MCSClient::SendPacketToWire(ReliablePacketInfo* packet_info) {
base::Time::kMicrosecondsPerSecond) - sent;
DVLOG(1) << "Message was queued for " << queued << " seconds.";
data_message->set_queued(queued);
+ recorder_->RecordSending(
+ data_message->category(),
+ data_message->to(),
+ data_message->id(),
+ "Sent to wire",
+ base::StringPrintf("Msg queued for %d seconds", queued));
}
// Set the proper last received stream id to acknowledge received server
@@ -862,6 +903,17 @@ void MCSClient::NotifyMessageSendStatus(
const mcs_proto::DataMessageStanza* data_message_stanza =
reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf);
+ recorder_->RecordSendingWithUMAEnum(
+ data_message_stanza->category(),
+ data_message_stanza->to(),
+ data_message_stanza->id(),
+ base::StringPrintf("SEND status: %s",
+ GetMessageSendStatusString(status).c_str()),
+ base::StringPrintf("Msg size: %d bytes, TTL: %d", protobuf.ByteSize(),
+ data_message_stanza->ttl()),
+ "GCM.SendMessageStatus",
+ status,
+ gcm::MCSClient::SEND_STATUS_COUNT);
message_sent_callback_.Run(
data_message_stanza->device_user_id(),
data_message_stanza->category(),

Powered by Google App Engine
This is Rietveld 408576698