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

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

Issue 9125015: Implement profiler log writing at shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update for review comments Created 8 years, 10 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 | « chrome/browser/task_profiler/task_profiler_data_serializer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..f37dc1473f312ddc5ef30ebf72e54b993fd407a2
--- /dev/null
+++ b/chrome/browser/task_profiler/task_profiler_data_serializer.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/task_profiler/task_profiler_data_serializer.h"
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/json/json_value_serializer.h"
+#include "base/time.h"
+#include "base/tracked_objects.h"
+#include "content/public/common/content_client.h"
+#include "googleurl/src/gurl.h"
+
+namespace task_profiler {
+
+bool TaskProfilerDataSerializer::WriteToFile(const FilePath &path) {
+ std::string output;
+ JSONStringValueSerializer serializer(&output);
+ serializer.set_pretty_print(true);
+
+ scoped_ptr<base::DictionaryValue> root(new DictionaryValue());
+
+ base::ListValue* snapshot_list = new ListValue();
+ base::DictionaryValue* shutdown_snapshot = new DictionaryValue();
+ base::ListValue* per_process_data = new ListValue();
+
+ root->SetInteger("version", 1);
+ 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);
+
+ shutdown_snapshot->SetInteger(
+ "timestamp",
+ (base::Time::Now() - base::Time::UnixEpoch()).InSeconds());
+ shutdown_snapshot->Set("data", per_process_data);
+ snapshot_list->Append(shutdown_snapshot);
+ root->Set("snapshots", snapshot_list);
+
+ serializer.Serialize(*root);
+ int data_size = static_cast<int>(output.size());
+
+ return data_size == file_util::WriteFile(path, output.data(), data_size);
+}
+
+} // namespace task_profiler
« no previous file with comments | « chrome/browser/task_profiler/task_profiler_data_serializer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698