OLD | NEW |
---|---|
(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(rlarocque): We should collect data from other processes as they shut | |
32 // down, then add that data to the 'per_process_data' array here. | |
jar (doing other things)
2012/01/10 20:51:35
This is a big challenge :-/. Most processes shut
ramant (doing other things)
2012/01/31 01:12:44
Hi rlarocque,
I had done collecting of data from
| |
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 | |
OLD | NEW |