Chromium Code Reviews| 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..243a60b59b4013c45f1b064f4b02f6967608b025 |
| --- /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(rlarocque): We should collect data from other processes as they shut |
| + // 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
|
| + 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 |