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

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..6e27c235d9e1660ad2ae5607db3ab42e2efee00e 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;
};
@@ -41,28 +42,56 @@ bool operator<(const AsyncEventStackId& t, const AsyncEventStackId& o) {
}
// ID uniquely identifying a duration event stack.
-typedef int DurationEventStackId;
+typedef std::string DurationEventStackId;
// Makes a unique id for a duration event stack.
bool GetDurationEventStackId(base::DictionaryValue* event_dict,
DurationEventStackId* durationId) {
- if (!event_dict->GetInteger("tid", durationId)) {
- LOG(ERROR) << "Incorrect trace event (missing tid).";
+ const base::Value* value;
+ if (!event_dict->Get("tid", &value)) {
+ LOG(ERROR) << "Incorrect duration trace event (missing tid): "
+ << *event_dict;
return false;
}
+
+ if (value->IsType(base::Value::TYPE_INTEGER)) {
+ int tid_int;
+ // We already verified the type, so it should be an integer.
+ DCHECK(value->GetAsInteger(&tid_int));
ppi 2015/10/01 13:31:16 please extract the common part between this and th
etiennej 2015/10/01 13:41:47 Done.
+ *durationId = base::IntToString(tid_int);
+ } else if (value->IsType(base::Value::TYPE_STRING)) {
+ DCHECK(value->GetAsString(durationId));
+ } else {
+ LOG(ERROR)
+ << "Incorrect duration trace event (tid not a string or integer): "
+ << *event_dict;
+ }
return true;
}
// 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,
- // per the documentation.
+ 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 not a string or integer): "
+ << *event_dict;
+ }
+
+ // We can have an empty category, but it is still relevant for event
+ // merging per the documentation.
std::string cat;
event_dict->GetString("cat", &asyncId->cat);
@@ -195,11 +224,6 @@ bool ParseEvents(base::ListValue* event_list, std::vector<Event>* result) {
return false;
}
- if (!event_dict->GetString("cat", &event.categories)) {
ppi 2015/10/01 13:31:16 Why this change?
etiennej 2015/10/01 13:41:47 Some real-world events do not have a category, yet
- LOG(WARNING) << "Ignoring incorrect trace event (no categories)";
- continue;
- }
-
double timestamp;
if (!event_dict->GetDouble("ts", &timestamp)) {
LOG(WARNING) << "Ingoring incorrect trace event (no timestamp)";
« 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