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

Unified Diff: chrome/browser/task_profiler/task_profiler_data_serializer.cc

Issue 9702014: [UMA] Use proper C++ objects to serialize tracked_objects across process boundaries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure to initialize all primitive fields 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: chrome/browser/task_profiler/task_profiler_data_serializer.cc
diff --git a/chrome/browser/task_profiler/task_profiler_data_serializer.cc b/chrome/browser/task_profiler/task_profiler_data_serializer.cc
index fd767418a5ce7f0eab1b2f2f002c6b4aa2c9b8c8..2ada8344f3e8c7b880cbff79a4e31bb9ff484ff1 100644
--- a/chrome/browser/task_profiler/task_profiler_data_serializer.cc
+++ b/chrome/browser/task_profiler/task_profiler_data_serializer.cc
@@ -10,11 +10,120 @@
#include "base/time.h"
#include "base/tracked_objects.h"
#include "content/public/common/content_client.h"
+#include "content/public/common/process_type.h"
#include "googleurl/src/gurl.h"
+using base::DictionaryValue;
+using base::ListValue;
+using base::Value;
+using tracked_objects::SerializedBirthOnThread;
+using tracked_objects::SerializedDeathData;
+using tracked_objects::SerializedLocation;
+using tracked_objects::SerializedParentChildPair;
+using tracked_objects::SerializedSnapshot;
+using tracked_objects::SerializedProcessData;
+
+namespace {
+
+// Re-serializes the |location| into |dictionary|.
+void SerializedLocationToJson(const SerializedLocation& location,
+ DictionaryValue* dictionary) {
+ dictionary->Set("file_name", Value::CreateStringValue(location.file_name));
+ // Note: This function name is not escaped, and templates have less-than
+ // characters, which means this is not suitable for display as HTML unless
+ // properly escaped.
+ dictionary->Set("function_name",
+ Value::CreateStringValue(location.function_name));
+ dictionary->Set("line_number",
+ Value::CreateIntegerValue(location.line_number));
+}
+
+// Re-serializes the |birth| into |dictionary|. Prepends the |prefix| to the
+// "thread" and "location" key names in the dictionary.
+void SerializedBirthOnThreadToJson(const SerializedBirthOnThread& birth,
+ const std::string& prefix,
+ DictionaryValue* dictionary) {
+ DCHECK(!prefix.empty());
+
+ scoped_ptr<DictionaryValue> location_value(new DictionaryValue);
+ SerializedLocationToJson(birth.location, location_value.get());
+ dictionary->Set(prefix + "_location", location_value.release());
+
+ dictionary->Set(prefix + "_thread",
+ Value::CreateStringValue(birth.thread_name));
+}
+
+// Re-serializes the |death_data| into |dictionary|.
+void SerializedDeathDataToJson(const SerializedDeathData& death_data,
+ base::DictionaryValue* dictionary) {
+ dictionary->Set("count",
+ Value::CreateIntegerValue(death_data.count));
+ dictionary->Set("run_ms",
+ Value::CreateIntegerValue(death_data.run_duration_sum));
+ dictionary->Set("run_ms_max",
+ Value::CreateIntegerValue(death_data.run_duration_max));
+ dictionary->Set("run_ms_sample",
+ Value::CreateIntegerValue(death_data.run_duration_sample));
+ dictionary->Set("queue_ms",
+ Value::CreateIntegerValue(death_data.queue_duration_sum));
+ dictionary->Set("queue_ms_max",
+ Value::CreateIntegerValue(death_data.queue_duration_max));
+ dictionary->Set("queue_ms_sample",
+ Value::CreateIntegerValue(death_data.queue_duration_sample));
+
+}
+
+// Re-serializes the |snapshot| into |dictionary|.
+void SerializedSnapshotToJson(const SerializedSnapshot& snapshot,
+ base::DictionaryValue* dictionary) {
+ SerializedBirthOnThreadToJson(snapshot.birth, "birth", dictionary);
+
+ scoped_ptr<DictionaryValue> death_data(new DictionaryValue);
+ SerializedDeathDataToJson(snapshot.death_data, death_data.get());
+ dictionary->Set("death_data", death_data.release());
+
+ dictionary->Set("death_thread",
+ Value::CreateStringValue(snapshot.death_thread_name));
+
+}
+
+} // anonymous namespace
+
namespace task_profiler {
-bool TaskProfilerDataSerializer::WriteToFile(const FilePath &path) {
+// static
+void TaskProfilerDataSerializer::SerializeToJson(
+ const SerializedProcessData& process_data,
+ content::ProcessType process_type,
+ base::DictionaryValue* dictionary) {
+ scoped_ptr<base::ListValue> snapshots_list(new base::ListValue);
+ for (std::vector<SerializedSnapshot>::const_iterator it =
+ process_data.snapshots.begin();
+ it != process_data.snapshots.end(); ++it) {
+ scoped_ptr<DictionaryValue> snapshot(new DictionaryValue);
jar (doing other things) 2012/04/04 17:55:35 Can a value instance work here, instead of a scope
Ilya Sherman 2012/04/05 02:51:04 Unfortunately no, because the |snapshots_list| wil
+ SerializedSnapshotToJson(*it, snapshot.get());
+ snapshots_list->Append(snapshot.release());
+ }
+ dictionary->Set("list", snapshots_list.release());
+
+ dictionary->SetInteger("process_id", process_data.process_id);
+ dictionary->SetString("process_type",
+ content::GetProcessTypeNameInEnglish(process_type));
+
+ scoped_ptr<base::ListValue> descendants_list(new base::ListValue);
+ for (std::vector<SerializedParentChildPair>::const_iterator it =
+ process_data.descendants.begin();
+ it != process_data.descendants.end(); ++it) {
+ scoped_ptr<base::DictionaryValue> parent_child(new base::DictionaryValue);
jar (doing other things) 2012/04/04 17:55:35 instance vs scoped ptr?
Ilya Sherman 2012/04/05 02:51:04 Ditto.
+ SerializedBirthOnThreadToJson(it->parent, "parent", parent_child.get());
+ SerializedBirthOnThreadToJson(it->child, "child", parent_child.get());
+ descendants_list->Append(parent_child.release());
+ }
+ dictionary->Set("descendants", descendants_list.release());
+}
+
+
+bool TaskProfilerDataSerializer::WriteToFile(const FilePath& path) {
std::string output;
JSONStringValueSerializer serializer(&output);
serializer.set_pretty_print(true);
@@ -29,10 +138,17 @@ bool TaskProfilerDataSerializer::WriteToFile(const FilePath &path) {
root->SetString("userAgent", content::GetUserAgent(GURL()));
// TODO(ramant): Collect data from other processes, then add that data to the
- // 'per_process_data' array here.
- base::DictionaryValue* this_process_data =
- tracked_objects::ThreadData::ToValue(false);
- per_process_data->Append(this_process_data);
+ // 'per_process_data' array here. Should leverage the TrackingSynchronizer
+ // class to implement this.
+ SerializedProcessData this_process_data;
+ tracked_objects::ThreadData::ToSerializedProcessData(false,
+ &this_process_data);
+ scoped_ptr<base::DictionaryValue> this_process_data_json(
jar (doing other things) 2012/04/04 17:55:35 instance?
Ilya Sherman 2012/04/05 02:51:04 Ditto.
+ new base::DictionaryValue);
+ TaskProfilerDataSerializer::SerializeToJson(this_process_data,
+ content::PROCESS_TYPE_BROWSER,
+ this_process_data_json.get());
+ per_process_data->Append(this_process_data_json.release());
shutdown_snapshot->SetInteger(
"timestamp",

Powered by Google App Engine
This is Rietveld 408576698