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

Unified Diff: apps/benchmark/event.cc

Issue 1381933002: Fix the benchmark app to handle real-world events (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | apps/benchmark/event_unittest.cc » ('j') | apps/benchmark/event_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/benchmark/event.cc
diff --git a/apps/benchmark/event.cc b/apps/benchmark/event.cc
index 146d8dfb5b05c68c35896ec51d824c0ceb40db13..4cf8595bce3bcd67478913d20c4ff0c20bf9e33e 100644
--- a/apps/benchmark/event.cc
+++ b/apps/benchmark/event.cc
@@ -10,6 +10,7 @@
#include "base/json/json_reader.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_number_conversions.h"
#include "base/values.h"
namespace benchmark {
@@ -32,7 +33,7 @@ Event::~Event() {}
namespace {
// ID uniquely identifying an asynchronous event stack.
struct AsyncEventStackId {
- int id;
+ std::string id;
std::string cat;
};
@@ -47,7 +48,7 @@ typedef int DurationEventStackId;
bool GetDurationEventStackId(base::DictionaryValue* event_dict,
DurationEventStackId* durationId) {
if (!event_dict->GetInteger("tid", durationId)) {
- LOG(ERROR) << "Incorrect trace event (missing tid).";
+ LOG(ERROR) << "Incorrect trace event (missing tid): " << *event_dict;
return false;
}
return true;
@@ -56,12 +57,26 @@ bool GetDurationEventStackId(base::DictionaryValue* event_dict,
// Makes a unique key for an async event stack.
bool GetAsyncEventStackId(base::DictionaryValue* event_dict,
AsyncEventStackId* asyncId) {
- if (!event_dict->GetInteger("id", &asyncId->id)) {
- LOG(ERROR) << "Incorrect async trace event (missing id).";
+ const base::Value* value;
+ if (!event_dict->Get("id", &value)) {
+ LOG(ERROR) << "Incorrect async trace event (missing id): " << *event_dict;
return false;
}
- // We can have an empty category, but it is still relevant for event merging,
+ if (value->IsType(base::Value::TYPE_INTEGER)) {
+ int id_int;
+ // We already verified the type, so it should be an integer.
+ DCHECK(value->GetAsInteger(&id_int));
+ asyncId->id = base::IntToString(id_int);
+ } else if (value->IsType(base::Value::TYPE_STRING)) {
+ DCHECK(value->GetAsString(&asyncId->id));
+ } else {
+ LOG(ERROR) << "Incorrect async trace event (id of wrong type): "
ppi 2015/10/01 13:09:44 (id of wrong type) -> (id is neither string nor in
etiennej 2015/10/01 13:25:17 Done.
+ << *event_dict;
+ }
+
+ // We can have an empty category, but it is still relevant for event
+ // merging,
ppi 2015/10/01 13:09:44 the comment block needs re-align
etiennej 2015/10/01 13:25:17 Done.
// per the documentation.
std::string cat;
event_dict->GetString("cat", &asyncId->cat);
« no previous file with comments | « no previous file | apps/benchmark/event_unittest.cc » ('j') | apps/benchmark/event_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698