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

Unified Diff: sync/engine/traffic_logger.cc

Issue 9732008: [Sync] Store the past 10 traffic records in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 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: sync/engine/traffic_logger.cc
diff --git a/sync/engine/traffic_logger.cc b/sync/engine/traffic_logger.cc
index b066af5902c5319facc0d8e06c9c0d08c839ce64..af16f8520fa45107c3ef632f181175ece90ccf46 100644
--- a/sync/engine/traffic_logger.cc
+++ b/sync/engine/traffic_logger.cc
@@ -4,6 +4,7 @@
#include "sync/engine/traffic_logger.h"
+#include <queue>
#include <string>
#include "base/json/json_writer.h"
@@ -12,9 +13,25 @@
#include "base/values.h"
#include "sync/protocol/proto_value_conversions.h"
#include "sync/protocol/sync.pb.h"
+#include "sync/sessions/sync_session.h"
namespace browser_sync {
+using sessions::SyncSession;
+
+TrafficRecord::TrafficRecord(const std::string& message,
+ TrafficMessageType message_type,
+ bool truncated) :
+ message(message),
+ message_type(message_type),
+ truncated(truncated) {
+}
+
+TrafficRecord::~TrafficRecord() {
+}
+
+static const unsigned int kMaxMessages = 10;
+static const unsigned int kMaxMessageSize = 100 * 1024;
akalin 2012/03/22 20:27:28 100k * 10 = 1MB, which seems like a lot just for l
lipalani1 2012/03/23 00:03:11 Letting the individual message size unbounded and
namespace {
template <class T>
void LogData(const T& data,
@@ -30,21 +47,48 @@ void LogData(const T& data,
DVLOG(1) << "\n" << description << "\n" << message << "\n";
}
}
+
+void AddTrafficToQueue(std::queue<TrafficRecord>* traffic_recorder,
akalin 2012/03/22 20:27:28 you'll run into problems later when reading the en
lipalani1 2012/03/23 00:03:11 The next patch would only need to access the front
akalin 2012/03/23 00:58:50 I see. But that's still not ideal. So if you do
lipalani1 2012/03/26 21:25:21 I did not want the memory to be used for displayin
+ const TrafficRecord& record) {
+ while (traffic_recorder->size() >= kMaxMessages) {
+ traffic_recorder->pop();
+ }
+
+ traffic_recorder->push(record);
akalin 2012/03/22 20:27:28 surely this should come before the popping? Other
lipalani1 2012/03/23 00:03:11 i did not mean >= in the previous while block. Cha
+}
+
+void StoreProtoInQueue(const ::google::protobuf::MessageLite& msg,
+ TrafficMessageType type,
+ SyncSession* session) {
+ bool truncated = false;
+ std::string message;
+ if (msg.ByteSize() >= kMaxMessageSize) {
+ truncated = true;
+ } else {
+ msg.SerializeToString(&message);
+ }
+
+ TrafficRecord record(message, type, truncated);
+ AddTrafficToQueue(session->context()->traffic_recorder(), record);
+}
+
} // namespace
-void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg) {
+void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg,
+ SyncSession* session) {
LogData(msg, &ClientToServerMessageToValue,
"******Client To Server Message******");
- // TODO(lipalani) : Store the data (minus specifics)
- // in a circular buffer in memory.
+
+ StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE, session);
}
void LogClientToServerResponse(
- const sync_pb::ClientToServerResponse& response) {
+ const sync_pb::ClientToServerResponse& response,
+ SyncSession* session) {
LogData(response, &ClientToServerResponseToValue,
"******Server Response******");
- // TODO(lipalani) : Store the data (minus specifics)
- // in a circular buffer in memory.
+
+ StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE, session);
}
} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698