OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/debug/traced_value.h" | 5 #include "cc/debug/traced_value.h" |
6 | 6 |
| 7 #include "base/debug/trace_event_argument.h" |
7 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) { | 14 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) { |
14 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 15 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
15 res->SetString("id_ref", base::StringPrintf("%p", id)); | 16 res->SetString("id_ref", base::StringPrintf("%p", id)); |
16 return res.PassAs<base::Value>(); | 17 return res.PassAs<base::Value>(); |
(...skipping 17 matching lines...) Expand all Loading... |
34 const char* category, | 35 const char* category, |
35 base::DictionaryValue* dict, | 36 base::DictionaryValue* dict, |
36 const char* object_base_type_name, | 37 const char* object_base_type_name, |
37 const char* object_name, | 38 const char* object_name, |
38 const void* id) { | 39 const void* id) { |
39 dict->SetString("cat", category); | 40 dict->SetString("cat", category); |
40 dict->SetString("base_type", object_base_type_name); | 41 dict->SetString("base_type", object_base_type_name); |
41 MakeDictIntoImplicitSnapshot(dict, object_name, id); | 42 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
42 } | 43 } |
43 | 44 |
| 45 void TracedValue::AppendIDRef(const void* id, base::debug::TracedValue* state) { |
| 46 state->BeginDictionary(); |
| 47 state->SetString("id_ref", base::StringPrintf("%p", id)); |
| 48 state->EndDictionary(); |
| 49 } |
| 50 |
| 51 void TracedValue::SetIDRef(const void* id, |
| 52 base::debug::TracedValue* state, |
| 53 const char* name) { |
| 54 state->BeginDictionary(name); |
| 55 state->SetString("id_ref", base::StringPrintf("%p", id)); |
| 56 state->EndDictionary(); |
| 57 } |
| 58 |
| 59 void TracedValue::MakeDictIntoImplicitSnapshot(base::debug::TracedValue* dict, |
| 60 const char* object_name, |
| 61 const void* id) { |
| 62 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); |
| 63 } |
| 64 |
| 65 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 66 const char* category, |
| 67 base::debug::TracedValue* dict, |
| 68 const char* object_name, |
| 69 const void* id) { |
| 70 dict->SetString("cat", category); |
| 71 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
| 72 } |
| 73 |
| 74 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 75 const char* category, |
| 76 base::debug::TracedValue* dict, |
| 77 const char* object_base_type_name, |
| 78 const char* object_name, |
| 79 const void* id) { |
| 80 dict->SetString("cat", category); |
| 81 dict->SetString("base_type", object_base_type_name); |
| 82 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
| 83 } |
| 84 |
44 scoped_refptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( | 85 scoped_refptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( |
45 base::Value* value) { | 86 base::Value* value) { |
46 return scoped_refptr<base::debug::ConvertableToTraceFormat>( | 87 return scoped_refptr<base::debug::ConvertableToTraceFormat>( |
47 new TracedValue(value)); | 88 new TracedValue(value)); |
48 } | 89 } |
49 | 90 |
50 TracedValue::TracedValue(base::Value* value) | 91 TracedValue::TracedValue(base::Value* value) |
51 : value_(value) { | 92 : value_(value) { |
52 } | 93 } |
53 | 94 |
54 TracedValue::~TracedValue() { | 95 TracedValue::~TracedValue() { |
55 } | 96 } |
56 | 97 |
57 void TracedValue::AppendAsTraceFormat(std::string* out) const { | 98 void TracedValue::AppendAsTraceFormat(std::string* out) const { |
58 std::string tmp; | 99 std::string tmp; |
59 base::JSONWriter::Write(value_.get(), &tmp); | 100 base::JSONWriter::Write(value_.get(), &tmp); |
60 *out += tmp; | 101 *out += tmp; |
61 } | 102 } |
62 | 103 |
63 } // namespace cc | 104 } // namespace cc |
OLD | NEW |