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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h"
6
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/json/json_value_serializer.h"
10 #include "base/time.h"
11 #include "base/tracked_objects.h"
12 #include "content/public/common/content_client.h"
13 #include "googleurl/src/gurl.h"
14
15 namespace task_profiler {
16
17 bool TaskProfilerDataSerializer::WriteToFile(const FilePath &path) {
18 std::string output;
19 JSONStringValueSerializer serializer(&output);
20 serializer.set_pretty_print(true);
21
22 scoped_ptr<base::DictionaryValue> root(new DictionaryValue());
23
24 base::ListValue* snapshot_list = new ListValue();
25 base::DictionaryValue* shutdown_snapshot = new DictionaryValue();
26 base::ListValue* per_process_data = new ListValue();
27
28 root->SetInteger("version", 1);
29 root->SetString("userAgent", content::GetUserAgent(GURL()));
30
31 // TODO(ramant): Collect data from other processes, then add that data to the
32 // 'per_process_data' array here.
33 base::DictionaryValue* this_process_data =
34 tracked_objects::ThreadData::ToValue(false);
35 per_process_data->Append(this_process_data);
36
37 shutdown_snapshot->SetInteger(
38 "timestamp",
39 (base::Time::Now() - base::Time::UnixEpoch()).InSeconds());
40 shutdown_snapshot->Set("data", per_process_data);
41 snapshot_list->Append(shutdown_snapshot);
42 root->Set("snapshots", snapshot_list);
43
44 serializer.Serialize(*root);
45 int data_size = static_cast<int>(output.size());
46
47 return data_size == file_util::WriteFile(path, output.data(), data_size);
48 }
49
50 } // namespace task_profiler
OLDNEW
« 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