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

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') | no next file with comments »
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..bdaff1d64300592926a25b53957204059f4c3482 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,49 @@ bool operator<(const AsyncEventStackId& t, const AsyncEventStackId& o) {
}
// ID uniquely identifying a duration event stack.
-typedef int DurationEventStackId;
+typedef std::string DurationEventStackId;
+
+bool ExtractKeyAsString(base::DictionaryValue* event_dict,
+ const std::string& key,
+ std::string* output) {
+ const base::Value* value;
+ if (!event_dict->Get(key, &value)) {
+ LOG(ERROR) << "Incorrect trace event (missing " + key + "): "
+ << *event_dict;
+ return false;
+ }
-// 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).";
+ 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));
+ *output = base::IntToString(id_int);
+ } else if (value->IsType(base::Value::TYPE_STRING)) {
+ DCHECK(value->GetAsString(output));
+ } else {
+ LOG(ERROR) << "Incorrect trace event (" + key +
+ " not a string or integer): "
+ << *event_dict;
return false;
}
return true;
}
+// Makes a unique id for a duration event stack.
+bool GetDurationEventStackId(base::DictionaryValue* event_dict,
+ DurationEventStackId* durationId) {
+ return ExtractKeyAsString(event_dict, "tid", durationId);
+}
+
// 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).";
+ if (!ExtractKeyAsString(event_dict, "id", &asyncId->id)) {
return false;
}
- // We can have an empty category, but it is still relevant for event merging,
- // per the documentation.
+ // 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,10 +217,9 @@ bool ParseEvents(base::ListValue* event_list, std::vector<Event>* result) {
return false;
}
- if (!event_dict->GetString("cat", &event.categories)) {
- LOG(WARNING) << "Ignoring incorrect trace event (no categories)";
- continue;
- }
+ // Some clients do not add categories to events, but we don't want to fail
+ // nor skip the event.
+ event_dict->GetString("cat", &event.categories);
double timestamp;
if (!event_dict->GetDouble("ts", &timestamp)) {
« no previous file with comments | « no previous file | apps/benchmark/event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698