scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 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 "base/debug/trace_event.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/command_line.h" |
| 9 | #include "base/json/json_reader.h" |
| 10 | #include "base/json/json_writer.h" |
jbates@chromium.org | 1f18e46 | 2011-09-07 02:56:24 +0900 | [diff] [blame] | 11 | #include "base/memory/ref_counted_memory.h" |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
joth@chromium.org | 088ae01 | 2011-11-11 01:26:23 +0900 | [diff] [blame] | 13 | #include "base/memory/singleton.h" |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 14 | #include "base/process_util.h" |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 15 | #include "base/stringprintf.h" |
| 16 | #include "base/synchronization/waitable_event.h" |
joth@chromium.org | 088ae01 | 2011-11-11 01:26:23 +0900 | [diff] [blame] | 17 | #include "base/threading/platform_thread.h" |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 18 | #include "base/threading/thread.h" |
| 19 | #include "base/values.h" |
| 20 | #include "testing/gmock/include/gmock/gmock.h" |
| 21 | #include "testing/gtest/include/gtest/gtest.h" |
| 22 | |
| 23 | namespace base { |
| 24 | namespace debug { |
| 25 | |
| 26 | namespace { |
| 27 | |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 28 | enum CompareOp { |
| 29 | IS_EQUAL, |
| 30 | IS_NOT_EQUAL, |
| 31 | }; |
| 32 | |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 33 | struct JsonKeyValue { |
| 34 | const char* key; |
| 35 | const char* value; |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 36 | CompareOp op; |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 37 | }; |
| 38 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 39 | class TraceEventTestFixture : public testing::Test { |
| 40 | public: |
joth@chromium.org | 113de99 | 2011-07-21 21:28:59 +0900 | [diff] [blame] | 41 | // This fixture does not use SetUp() because the fixture must be manually set |
| 42 | // up multiple times when testing AtExit. Use ManualTestSetUp for this. |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 43 | void ManualTestSetUp(); |
ajwong@chromium.org | ec1750a | 2011-06-27 01:22:50 +0900 | [diff] [blame] | 44 | void OnTraceDataCollected( |
sail@chromium.org | eb8d972 | 2011-12-15 06:48:54 +0900 | [diff] [blame] | 45 | scoped_refptr<TraceLog::RefCountedString> events_str); |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 46 | DictionaryValue* FindMatchingTraceEntry(const JsonKeyValue* key_values); |
| 47 | DictionaryValue* FindNamePhase(const char* name, const char* phase); |
| 48 | DictionaryValue* FindNamePhaseKeyValue(const char* name, |
| 49 | const char* phase, |
| 50 | const char* key, |
| 51 | const char* value); |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 52 | bool FindMatchingValue(const char* key, |
| 53 | const char* value); |
| 54 | bool FindNonMatchingValue(const char* key, |
| 55 | const char* value); |
| 56 | void Clear() { |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 57 | trace_parsed_.Clear(); |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 58 | json_output_.json_output.clear(); |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 59 | } |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 60 | |
joth@chromium.org | 088ae01 | 2011-11-11 01:26:23 +0900 | [diff] [blame] | 61 | virtual void SetUp() { |
| 62 | old_thread_name_ = PlatformThread::GetName(); |
| 63 | } |
| 64 | virtual void TearDown() { |
| 65 | PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); |
| 66 | } |
| 67 | |
| 68 | const char* old_thread_name_; |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 69 | ListValue trace_parsed_; |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 70 | base::debug::TraceResultBuffer trace_buffer_; |
| 71 | base::debug::TraceResultBuffer::SimpleOutput json_output_; |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | // We want our singleton torn down after each test. |
| 75 | ShadowingAtExitManager at_exit_manager_; |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 76 | Lock lock_; |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | void TraceEventTestFixture::ManualTestSetUp() { |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 80 | TraceLog::DeleteForTesting(); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 81 | TraceLog::Resurrect(); |
| 82 | TraceLog* tracelog = TraceLog::GetInstance(); |
| 83 | ASSERT_TRUE(tracelog); |
| 84 | ASSERT_FALSE(tracelog->IsEnabled()); |
| 85 | tracelog->SetOutputCallback( |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 86 | base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| 87 | base::Unretained(this))); |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 88 | trace_buffer_.SetOutputCallback(json_output_.GetCallback()); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void TraceEventTestFixture::OnTraceDataCollected( |
sail@chromium.org | eb8d972 | 2011-12-15 06:48:54 +0900 | [diff] [blame] | 92 | scoped_refptr<TraceLog::RefCountedString> events_str) { |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 93 | AutoLock lock(lock_); |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 94 | json_output_.json_output.clear(); |
| 95 | trace_buffer_.Start(); |
| 96 | trace_buffer_.AddFragment(events_str->data); |
| 97 | trace_buffer_.Finish(); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 98 | |
| 99 | scoped_ptr<Value> root; |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 100 | root.reset(base::JSONReader::Read(json_output_.json_output, false)); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 101 | |
| 102 | ListValue* root_list = NULL; |
| 103 | ASSERT_TRUE(root.get()); |
| 104 | ASSERT_TRUE(root->GetAsList(&root_list)); |
| 105 | |
| 106 | // Move items into our aggregate collection |
| 107 | while (root_list->GetSize()) { |
| 108 | Value* item = NULL; |
| 109 | root_list->Remove(0, &item); |
| 110 | trace_parsed_.Append(item); |
| 111 | } |
| 112 | } |
| 113 | |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 114 | static bool CompareJsonValues(const std::string& lhs, |
| 115 | const std::string& rhs, |
| 116 | CompareOp op) { |
| 117 | switch (op) { |
| 118 | case IS_EQUAL: |
| 119 | return lhs == rhs; |
| 120 | case IS_NOT_EQUAL: |
| 121 | return lhs != rhs; |
| 122 | default: |
| 123 | CHECK(0); |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 128 | static bool IsKeyValueInDict(const JsonKeyValue* key_value, |
| 129 | DictionaryValue* dict) { |
| 130 | Value* value = NULL; |
| 131 | std::string value_str; |
| 132 | if (dict->Get(key_value->key, &value) && |
| 133 | value->GetAsString(&value_str) && |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 134 | CompareJsonValues(value_str, key_value->value, key_value->op)) |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 135 | return true; |
| 136 | |
| 137 | // Recurse to test arguments |
| 138 | DictionaryValue* args_dict = NULL; |
| 139 | dict->GetDictionary("args", &args_dict); |
| 140 | if (args_dict) |
| 141 | return IsKeyValueInDict(key_value, args_dict); |
| 142 | |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | static bool IsAllKeyValueInDict(const JsonKeyValue* key_values, |
| 147 | DictionaryValue* dict) { |
| 148 | // Scan all key_values, they must all be present and equal. |
| 149 | while (key_values && key_values->key) { |
| 150 | if (!IsKeyValueInDict(key_values, dict)) |
| 151 | return false; |
| 152 | ++key_values; |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 157 | DictionaryValue* TraceEventTestFixture::FindMatchingTraceEntry( |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 158 | const JsonKeyValue* key_values) { |
| 159 | // Scan all items |
| 160 | size_t trace_parsed_count = trace_parsed_.GetSize(); |
| 161 | for (size_t i = 0; i < trace_parsed_count; i++) { |
| 162 | Value* value = NULL; |
| 163 | trace_parsed_.Get(i, &value); |
| 164 | if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
| 165 | continue; |
| 166 | DictionaryValue* dict = static_cast<DictionaryValue*>(value); |
| 167 | |
| 168 | if (IsAllKeyValueInDict(key_values, dict)) |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 169 | return dict; |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 170 | } |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 171 | return NULL; |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 172 | } |
| 173 | |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 174 | DictionaryValue* TraceEventTestFixture::FindNamePhase(const char* name, |
| 175 | const char* phase) { |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 176 | JsonKeyValue key_values[] = { |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 177 | {"name", name, IS_EQUAL}, |
| 178 | {"ph", phase, IS_EQUAL}, |
| 179 | {0, 0, IS_EQUAL} |
| 180 | }; |
| 181 | return FindMatchingTraceEntry(key_values); |
| 182 | } |
| 183 | |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 184 | DictionaryValue* TraceEventTestFixture::FindNamePhaseKeyValue( |
| 185 | const char* name, |
| 186 | const char* phase, |
| 187 | const char* key, |
| 188 | const char* value) { |
| 189 | JsonKeyValue key_values[] = { |
| 190 | {"name", name, IS_EQUAL}, |
| 191 | {"ph", phase, IS_EQUAL}, |
| 192 | {key, value, IS_EQUAL}, |
| 193 | {0, 0, IS_EQUAL} |
| 194 | }; |
| 195 | return FindMatchingTraceEntry(key_values); |
| 196 | } |
| 197 | |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 198 | bool TraceEventTestFixture::FindMatchingValue(const char* key, |
| 199 | const char* value) { |
| 200 | JsonKeyValue key_values[] = { |
| 201 | {key, value, IS_EQUAL}, |
| 202 | {0, 0, IS_EQUAL} |
| 203 | }; |
| 204 | return FindMatchingTraceEntry(key_values); |
| 205 | } |
| 206 | |
| 207 | bool TraceEventTestFixture::FindNonMatchingValue(const char* key, |
| 208 | const char* value) { |
| 209 | JsonKeyValue key_values[] = { |
| 210 | {key, value, IS_NOT_EQUAL}, |
| 211 | {0, 0, IS_EQUAL} |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 212 | }; |
| 213 | return FindMatchingTraceEntry(key_values); |
| 214 | } |
| 215 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 216 | bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) { |
| 217 | for (DictionaryValue::key_iterator ikey = dict->begin_keys(); |
| 218 | ikey != dict->end_keys(); ++ikey) { |
| 219 | Value* child = NULL; |
| 220 | if (!dict->GetWithoutPathExpansion(*ikey, &child)) |
| 221 | continue; |
| 222 | |
| 223 | if ((*ikey).find(string_to_match) != std::string::npos) |
| 224 | return true; |
| 225 | |
| 226 | std::string value_str; |
| 227 | child->GetAsString(&value_str); |
| 228 | if (value_str.find(string_to_match) != std::string::npos) |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | // Recurse to test arguments |
| 233 | DictionaryValue* args_dict = NULL; |
| 234 | dict->GetDictionary("args", &args_dict); |
| 235 | if (args_dict) |
| 236 | return IsStringInDict(string_to_match, args_dict); |
| 237 | |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | DictionaryValue* FindTraceEntry(const ListValue& trace_parsed, |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 242 | const char* string_to_match, |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 243 | DictionaryValue* match_after_this_item = NULL) { |
| 244 | // Scan all items |
| 245 | size_t trace_parsed_count = trace_parsed.GetSize(); |
| 246 | for (size_t i = 0; i < trace_parsed_count; i++) { |
| 247 | Value* value = NULL; |
| 248 | trace_parsed.Get(i, &value); |
| 249 | if (match_after_this_item) { |
| 250 | if (value == match_after_this_item) |
| 251 | match_after_this_item = NULL; |
| 252 | continue; |
| 253 | } |
| 254 | if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
| 255 | continue; |
| 256 | DictionaryValue* dict = static_cast<DictionaryValue*>(value); |
| 257 | |
| 258 | if (IsStringInDict(string_to_match, dict)) |
| 259 | return dict; |
| 260 | } |
| 261 | return NULL; |
| 262 | } |
| 263 | |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 264 | std::vector<DictionaryValue*> FindTraceEntries( |
| 265 | const ListValue& trace_parsed, |
| 266 | const char* string_to_match) { |
| 267 | std::vector<DictionaryValue*> hits; |
| 268 | size_t trace_parsed_count = trace_parsed.GetSize(); |
| 269 | for (size_t i = 0; i < trace_parsed_count; i++) { |
| 270 | Value* value = NULL; |
| 271 | trace_parsed.Get(i, &value); |
| 272 | if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
| 273 | continue; |
| 274 | DictionaryValue* dict = static_cast<DictionaryValue*>(value); |
| 275 | |
| 276 | if (IsStringInDict(string_to_match, dict)) |
| 277 | hits.push_back(dict); |
| 278 | } |
| 279 | return hits; |
| 280 | } |
| 281 | |
| 282 | void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 283 | { |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 284 | TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 0x1122, "extrastring1"); |
| 285 | TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW call", 0x3344, "extrastring2"); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 286 | TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW call", |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 287 | 0x5566, "extrastring3"); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 288 | |
| 289 | TRACE_EVENT0("all", "TRACE_EVENT0 call"); |
| 290 | TRACE_EVENT1("all", "TRACE_EVENT1 call", "name1", "value1"); |
| 291 | TRACE_EVENT2("all", "TRACE_EVENT2 call", |
jbates@chromium.org | 788d5a1 | 2011-09-07 09:43:11 +0900 | [diff] [blame] | 292 | "name1", "\"value1\"", |
| 293 | "name2", "value\\2"); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 294 | |
| 295 | TRACE_EVENT_INSTANT0("all", "TRACE_EVENT_INSTANT0 call"); |
| 296 | TRACE_EVENT_INSTANT1("all", "TRACE_EVENT_INSTANT1 call", "name1", "value1"); |
| 297 | TRACE_EVENT_INSTANT2("all", "TRACE_EVENT_INSTANT2 call", |
| 298 | "name1", "value1", |
| 299 | "name2", "value2"); |
| 300 | |
| 301 | TRACE_EVENT_BEGIN0("all", "TRACE_EVENT_BEGIN0 call"); |
| 302 | TRACE_EVENT_BEGIN1("all", "TRACE_EVENT_BEGIN1 call", "name1", "value1"); |
| 303 | TRACE_EVENT_BEGIN2("all", "TRACE_EVENT_BEGIN2 call", |
| 304 | "name1", "value1", |
| 305 | "name2", "value2"); |
| 306 | |
| 307 | TRACE_EVENT_END0("all", "TRACE_EVENT_END0 call"); |
| 308 | TRACE_EVENT_END1("all", "TRACE_EVENT_END1 call", "name1", "value1"); |
| 309 | TRACE_EVENT_END2("all", "TRACE_EVENT_END2 call", |
| 310 | "name1", "value1", |
| 311 | "name2", "value2"); |
nduca@chromium.org | 62210b0 | 2011-11-18 18:36:36 +0900 | [diff] [blame] | 312 | |
| 313 | TRACE_COUNTER1("all", "TRACE_COUNTER1 call", 31415); |
| 314 | TRACE_COUNTER2("all", "TRACE_COUNTER2 call", |
| 315 | "a", 30000, |
| 316 | "b", 1415); |
piman@chromium.org | 902b295 | 2011-12-16 10:19:06 +0900 | [diff] [blame^] | 317 | |
| 318 | TRACE_COUNTER_ID1("all", "TRACE_COUNTER_ID1 call", 0x319009, 31415); |
| 319 | TRACE_COUNTER_ID2("all", "TRACE_COUNTER_ID2 call", 0x319009, |
| 320 | "a", 30000, "b", 1415); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 321 | } // Scope close causes TRACE_EVENT0 etc to send their END events. |
| 322 | |
| 323 | if (task_complete_event) |
| 324 | task_complete_event->Signal(); |
| 325 | } |
| 326 | |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 327 | void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) { |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 328 | DictionaryValue* item = NULL; |
| 329 | |
| 330 | #define EXPECT_FIND_(string) \ |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 331 | EXPECT_TRUE((item = FindTraceEntry(trace_parsed, string))); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 332 | #define EXPECT_NOT_FIND_(string) \ |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 333 | EXPECT_FALSE((item = FindTraceEntry(trace_parsed, string))); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 334 | #define EXPECT_SUB_FIND_(string) \ |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 335 | if (item) EXPECT_TRUE((IsStringInDict(string, item))); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 336 | |
| 337 | EXPECT_FIND_("ETW Trace Event"); |
| 338 | EXPECT_FIND_("all"); |
| 339 | EXPECT_FIND_("TRACE_EVENT_BEGIN_ETW call"); |
| 340 | { |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 341 | std::string str_val; |
| 342 | EXPECT_TRUE(item && item->GetString("args.id", &str_val)); |
| 343 | EXPECT_STREQ("1122", str_val.c_str()); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 344 | } |
| 345 | EXPECT_SUB_FIND_("extrastring1"); |
| 346 | EXPECT_FIND_("TRACE_EVENT_END_ETW call"); |
| 347 | EXPECT_FIND_("TRACE_EVENT_INSTANT_ETW call"); |
| 348 | EXPECT_FIND_("TRACE_EVENT0 call"); |
| 349 | { |
| 350 | std::string ph_begin; |
| 351 | std::string ph_end; |
| 352 | EXPECT_TRUE((item = FindTraceEntry(trace_parsed, "TRACE_EVENT0 call"))); |
| 353 | EXPECT_TRUE((item && item->GetString("ph", &ph_begin))); |
| 354 | EXPECT_TRUE((item = FindTraceEntry(trace_parsed, "TRACE_EVENT0 call", |
| 355 | item))); |
| 356 | EXPECT_TRUE((item && item->GetString("ph", &ph_end))); |
| 357 | EXPECT_EQ("B", ph_begin); |
| 358 | EXPECT_EQ("E", ph_end); |
| 359 | } |
| 360 | EXPECT_FIND_("TRACE_EVENT1 call"); |
| 361 | EXPECT_FIND_("TRACE_EVENT2 call"); |
| 362 | EXPECT_SUB_FIND_("name1"); |
jbates@chromium.org | 788d5a1 | 2011-09-07 09:43:11 +0900 | [diff] [blame] | 363 | EXPECT_SUB_FIND_("\"value1\""); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 364 | EXPECT_SUB_FIND_("name2"); |
jbates@chromium.org | 788d5a1 | 2011-09-07 09:43:11 +0900 | [diff] [blame] | 365 | EXPECT_SUB_FIND_("value\\2"); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 366 | EXPECT_FIND_("TRACE_EVENT_INSTANT0 call"); |
| 367 | EXPECT_FIND_("TRACE_EVENT_INSTANT1 call"); |
| 368 | EXPECT_FIND_("TRACE_EVENT_INSTANT2 call"); |
| 369 | EXPECT_SUB_FIND_("name1"); |
| 370 | EXPECT_SUB_FIND_("value1"); |
| 371 | EXPECT_SUB_FIND_("name2"); |
| 372 | EXPECT_SUB_FIND_("value2"); |
| 373 | EXPECT_FIND_("TRACE_EVENT_BEGIN0 call"); |
| 374 | EXPECT_FIND_("TRACE_EVENT_BEGIN1 call"); |
| 375 | EXPECT_FIND_("TRACE_EVENT_BEGIN2 call"); |
| 376 | EXPECT_SUB_FIND_("name1"); |
| 377 | EXPECT_SUB_FIND_("value1"); |
| 378 | EXPECT_SUB_FIND_("name2"); |
| 379 | EXPECT_SUB_FIND_("value2"); |
| 380 | EXPECT_FIND_("TRACE_EVENT_END0 call"); |
| 381 | EXPECT_FIND_("TRACE_EVENT_END1 call"); |
| 382 | EXPECT_FIND_("TRACE_EVENT_END2 call"); |
| 383 | EXPECT_SUB_FIND_("name1"); |
| 384 | EXPECT_SUB_FIND_("value1"); |
| 385 | EXPECT_SUB_FIND_("name2"); |
| 386 | EXPECT_SUB_FIND_("value2"); |
nduca@chromium.org | 62210b0 | 2011-11-18 18:36:36 +0900 | [diff] [blame] | 387 | |
| 388 | EXPECT_FIND_("TRACE_COUNTER1 call"); |
| 389 | { |
| 390 | std::string ph; |
| 391 | EXPECT_TRUE((item && item->GetString("ph", &ph))); |
| 392 | EXPECT_EQ("C", ph); |
| 393 | |
| 394 | int value; |
| 395 | EXPECT_TRUE((item && item->GetInteger("args.value", &value))); |
| 396 | EXPECT_EQ(31415, value); |
| 397 | } |
| 398 | |
| 399 | EXPECT_FIND_("TRACE_COUNTER2 call"); |
| 400 | { |
| 401 | std::string ph; |
| 402 | EXPECT_TRUE((item && item->GetString("ph", &ph))); |
| 403 | EXPECT_EQ("C", ph); |
| 404 | |
| 405 | int value; |
| 406 | EXPECT_TRUE((item && item->GetInteger("args.a", &value))); |
| 407 | EXPECT_EQ(30000, value); |
| 408 | |
| 409 | EXPECT_TRUE((item && item->GetInteger("args.b", &value))); |
| 410 | EXPECT_EQ(1415, value); |
| 411 | } |
| 412 | |
piman@chromium.org | 902b295 | 2011-12-16 10:19:06 +0900 | [diff] [blame^] | 413 | EXPECT_FIND_("TRACE_COUNTER_ID1 call"); |
| 414 | { |
| 415 | std::string id; |
| 416 | EXPECT_TRUE((item && item->GetString("id", &id))); |
| 417 | EXPECT_EQ("319009", id); |
| 418 | |
| 419 | std::string ph; |
| 420 | EXPECT_TRUE((item && item->GetString("ph", &ph))); |
| 421 | EXPECT_EQ("C", ph); |
| 422 | |
| 423 | int value; |
| 424 | EXPECT_TRUE((item && item->GetInteger("args.value", &value))); |
| 425 | EXPECT_EQ(31415, value); |
| 426 | } |
| 427 | |
| 428 | EXPECT_FIND_("TRACE_COUNTER_ID2 call"); |
| 429 | { |
| 430 | std::string id; |
| 431 | EXPECT_TRUE((item && item->GetString("id", &id))); |
| 432 | EXPECT_EQ("319009", id); |
| 433 | |
| 434 | std::string ph; |
| 435 | EXPECT_TRUE((item && item->GetString("ph", &ph))); |
| 436 | EXPECT_EQ("C", ph); |
| 437 | |
| 438 | int value; |
| 439 | EXPECT_TRUE((item && item->GetInteger("args.a", &value))); |
| 440 | EXPECT_EQ(30000, value); |
| 441 | |
| 442 | EXPECT_TRUE((item && item->GetInteger("args.b", &value))); |
| 443 | EXPECT_EQ(1415, value); |
| 444 | } |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 445 | } |
| 446 | |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 447 | void TraceManyInstantEvents(int thread_id, int num_events, |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 448 | WaitableEvent* task_complete_event) { |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 449 | for (int i = 0; i < num_events; i++) { |
| 450 | TRACE_EVENT_INSTANT2("all", "multi thread event", |
| 451 | "thread", thread_id, |
| 452 | "event", i); |
| 453 | } |
| 454 | |
| 455 | if (task_complete_event) |
| 456 | task_complete_event->Signal(); |
| 457 | } |
| 458 | |
| 459 | void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed, |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 460 | int num_threads, |
| 461 | int num_events) { |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 462 | std::map<int, std::map<int, bool> > results; |
| 463 | |
| 464 | size_t trace_parsed_count = trace_parsed.GetSize(); |
| 465 | for (size_t i = 0; i < trace_parsed_count; i++) { |
| 466 | Value* value = NULL; |
| 467 | trace_parsed.Get(i, &value); |
| 468 | if (!value || value->GetType() != Value::TYPE_DICTIONARY) |
| 469 | continue; |
| 470 | DictionaryValue* dict = static_cast<DictionaryValue*>(value); |
| 471 | std::string name; |
| 472 | dict->GetString("name", &name); |
| 473 | if (name != "multi thread event") |
| 474 | continue; |
| 475 | |
| 476 | int thread = 0; |
| 477 | int event = 0; |
| 478 | EXPECT_TRUE(dict->GetInteger("args.thread", &thread)); |
| 479 | EXPECT_TRUE(dict->GetInteger("args.event", &event)); |
| 480 | results[thread][event] = true; |
| 481 | } |
| 482 | |
| 483 | EXPECT_FALSE(results[-1][-1]); |
| 484 | for (int thread = 0; thread < num_threads; thread++) { |
| 485 | for (int event = 0; event < num_events; event++) { |
| 486 | EXPECT_TRUE(results[thread][event]); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) { |
| 492 | TRACE_EVENT0("category name1", name_str); |
| 493 | TRACE_EVENT_INSTANT0("category name2", name_str); |
| 494 | TRACE_EVENT_BEGIN0("category name3", name_str); |
| 495 | TRACE_EVENT_END0("category name4", name_str); |
| 496 | } |
| 497 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 498 | } // namespace |
| 499 | |
| 500 | // Simple Test for emitting data and validating it was received. |
| 501 | TEST_F(TraceEventTestFixture, DataCaptured) { |
| 502 | ManualTestSetUp(); |
| 503 | TraceLog::GetInstance()->SetEnabled(true); |
| 504 | |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 505 | TraceWithAllMacroVariants(NULL); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 506 | |
| 507 | TraceLog::GetInstance()->SetEnabled(false); |
| 508 | |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 509 | ValidateAllTraceMacrosCreatedData(trace_parsed_); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 510 | } |
| 511 | |
jbates@chromium.org | 11d4c36 | 2011-09-13 07:03:41 +0900 | [diff] [blame] | 512 | // Test that categories work. |
| 513 | TEST_F(TraceEventTestFixture, Categories) { |
| 514 | ManualTestSetUp(); |
| 515 | |
| 516 | // Test that categories that are used can be retrieved whether trace was |
| 517 | // enabled or disabled when the trace event was encountered. |
| 518 | TRACE_EVENT_INSTANT0("c1", "name"); |
| 519 | TRACE_EVENT_INSTANT0("c2", "name"); |
| 520 | TraceLog::GetInstance()->SetEnabled(true); |
| 521 | TRACE_EVENT_INSTANT0("c3", "name"); |
| 522 | TRACE_EVENT_INSTANT0("c4", "name"); |
| 523 | TraceLog::GetInstance()->SetEnabled(false); |
| 524 | std::vector<std::string> cats; |
| 525 | TraceLog::GetInstance()->GetKnownCategories(&cats); |
| 526 | EXPECT_TRUE(std::find(cats.begin(), cats.end(), "c1") != cats.end()); |
| 527 | EXPECT_TRUE(std::find(cats.begin(), cats.end(), "c2") != cats.end()); |
| 528 | EXPECT_TRUE(std::find(cats.begin(), cats.end(), "c3") != cats.end()); |
| 529 | EXPECT_TRUE(std::find(cats.begin(), cats.end(), "c4") != cats.end()); |
| 530 | |
| 531 | const std::vector<std::string> empty_categories; |
| 532 | std::vector<std::string> included_categories; |
| 533 | std::vector<std::string> excluded_categories; |
| 534 | |
| 535 | // Test that category filtering works. |
| 536 | |
| 537 | // Include nonexistent category -> no events |
| 538 | Clear(); |
| 539 | included_categories.clear(); |
| 540 | included_categories.push_back("not_found823564786"); |
| 541 | TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories); |
| 542 | TRACE_EVENT_INSTANT0("cat1", "name"); |
| 543 | TRACE_EVENT_INSTANT0("cat2", "name"); |
| 544 | TraceLog::GetInstance()->SetDisabled(); |
| 545 | EXPECT_TRUE(trace_parsed_.empty()); |
| 546 | |
| 547 | // Include existent category -> only events of that category |
| 548 | Clear(); |
| 549 | included_categories.clear(); |
| 550 | included_categories.push_back("inc"); |
| 551 | TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories); |
| 552 | TRACE_EVENT_INSTANT0("inc", "name"); |
| 553 | TRACE_EVENT_INSTANT0("inc2", "name"); |
| 554 | TraceLog::GetInstance()->SetDisabled(); |
| 555 | EXPECT_TRUE(FindMatchingValue("cat", "inc")); |
| 556 | EXPECT_FALSE(FindNonMatchingValue("cat", "inc")); |
| 557 | |
| 558 | // Include existent wildcard -> all categories matching wildcard |
| 559 | Clear(); |
| 560 | included_categories.clear(); |
| 561 | included_categories.push_back("inc_wildcard_*"); |
| 562 | included_categories.push_back("inc_wildchar_?_end"); |
| 563 | TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories); |
| 564 | TRACE_EVENT_INSTANT0("inc_wildcard_abc", "included"); |
| 565 | TRACE_EVENT_INSTANT0("inc_wildcard_", "included"); |
| 566 | TRACE_EVENT_INSTANT0("inc_wildchar_x_end", "included"); |
| 567 | TRACE_EVENT_INSTANT0("inc_wildchar_bla_end", "not_inc"); |
| 568 | TRACE_EVENT_INSTANT0("cat1", "not_inc"); |
| 569 | TRACE_EVENT_INSTANT0("cat2", "not_inc"); |
| 570 | TraceLog::GetInstance()->SetDisabled(); |
| 571 | EXPECT_TRUE(FindMatchingValue("cat", "inc_wildcard_abc")); |
| 572 | EXPECT_TRUE(FindMatchingValue("cat", "inc_wildcard_")); |
| 573 | EXPECT_TRUE(FindMatchingValue("cat", "inc_wildchar_x_end")); |
| 574 | EXPECT_FALSE(FindMatchingValue("name", "not_inc")); |
| 575 | |
| 576 | included_categories.clear(); |
| 577 | |
| 578 | // Exclude nonexistent category -> all events |
| 579 | Clear(); |
| 580 | excluded_categories.clear(); |
| 581 | excluded_categories.push_back("not_found823564786"); |
| 582 | TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories); |
| 583 | TRACE_EVENT_INSTANT0("cat1", "name"); |
| 584 | TRACE_EVENT_INSTANT0("cat2", "name"); |
| 585 | TraceLog::GetInstance()->SetDisabled(); |
| 586 | EXPECT_TRUE(FindMatchingValue("cat", "cat1")); |
| 587 | EXPECT_TRUE(FindMatchingValue("cat", "cat2")); |
| 588 | |
| 589 | // Exclude existent category -> only events of other categories |
| 590 | Clear(); |
| 591 | excluded_categories.clear(); |
| 592 | excluded_categories.push_back("inc"); |
| 593 | TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories); |
| 594 | TRACE_EVENT_INSTANT0("inc", "name"); |
| 595 | TRACE_EVENT_INSTANT0("inc2", "name"); |
| 596 | TraceLog::GetInstance()->SetDisabled(); |
| 597 | EXPECT_TRUE(FindMatchingValue("cat", "inc2")); |
| 598 | EXPECT_FALSE(FindMatchingValue("cat", "inc")); |
| 599 | |
| 600 | // Exclude existent wildcard -> all categories not matching wildcard |
| 601 | Clear(); |
| 602 | excluded_categories.clear(); |
| 603 | excluded_categories.push_back("inc_wildcard_*"); |
| 604 | excluded_categories.push_back("inc_wildchar_?_end"); |
| 605 | TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories); |
| 606 | TRACE_EVENT_INSTANT0("inc_wildcard_abc", "not_inc"); |
| 607 | TRACE_EVENT_INSTANT0("inc_wildcard_", "not_inc"); |
| 608 | TRACE_EVENT_INSTANT0("inc_wildchar_x_end", "not_inc"); |
| 609 | TRACE_EVENT_INSTANT0("inc_wildchar_bla_end", "included"); |
| 610 | TRACE_EVENT_INSTANT0("cat1", "included"); |
| 611 | TRACE_EVENT_INSTANT0("cat2", "included"); |
| 612 | TraceLog::GetInstance()->SetDisabled(); |
| 613 | EXPECT_TRUE(FindMatchingValue("cat", "inc_wildchar_bla_end")); |
| 614 | EXPECT_TRUE(FindMatchingValue("cat", "cat1")); |
| 615 | EXPECT_TRUE(FindMatchingValue("cat", "cat2")); |
| 616 | EXPECT_FALSE(FindMatchingValue("name", "not_inc")); |
| 617 | } |
| 618 | |
jbates@chromium.org | b3cab86 | 2011-05-14 08:30:35 +0900 | [diff] [blame] | 619 | // Simple Test for time threshold events. |
| 620 | TEST_F(TraceEventTestFixture, DataCapturedThreshold) { |
| 621 | ManualTestSetUp(); |
| 622 | TraceLog::GetInstance()->SetEnabled(true); |
| 623 | |
| 624 | // Test that events at the same level are properly filtered by threshold. |
| 625 | { |
| 626 | TRACE_EVENT_IF_LONGER_THAN0(100, "time", "threshold 100"); |
| 627 | TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "threshold 1000"); |
| 628 | TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "threshold 10000"); |
| 629 | // 100+ seconds to avoid flakiness. |
| 630 | TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "threshold long1"); |
| 631 | TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "threshold long2"); |
| 632 | base::PlatformThread::Sleep(20); // 20000 us |
| 633 | } |
| 634 | |
| 635 | // Test that a normal nested event remains after it's parent event is dropped. |
| 636 | { |
| 637 | TRACE_EVENT_IF_LONGER_THAN0(1000000, "time", "2threshold10000"); |
| 638 | { |
| 639 | TRACE_EVENT0("time", "nonthreshold1"); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | // Test that parent thresholded events are dropped while some nested events |
| 644 | // remain. |
| 645 | { |
| 646 | TRACE_EVENT0("time", "nonthreshold3"); |
| 647 | { |
| 648 | TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "3thresholdlong2"); |
| 649 | { |
| 650 | TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "3thresholdlong1"); |
| 651 | { |
| 652 | TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "3threshold10000"); |
| 653 | { |
| 654 | TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "3threshold1000"); |
| 655 | { |
| 656 | TRACE_EVENT_IF_LONGER_THAN0(100, "time", "3threshold100"); |
| 657 | base::PlatformThread::Sleep(20); |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | // Test that child thresholded events are dropped while some parent events |
| 666 | // remain. |
| 667 | { |
| 668 | TRACE_EVENT0("time", "nonthreshold4"); |
| 669 | { |
| 670 | TRACE_EVENT_IF_LONGER_THAN0(100, "time", "4threshold100"); |
| 671 | { |
| 672 | TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "4threshold1000"); |
| 673 | { |
| 674 | TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "4threshold10000"); |
| 675 | { |
| 676 | TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", |
| 677 | "4thresholdlong1"); |
| 678 | { |
| 679 | TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", |
| 680 | "4thresholdlong2"); |
| 681 | base::PlatformThread::Sleep(20); |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | TraceLog::GetInstance()->SetEnabled(false); |
| 690 | |
| 691 | #define EXPECT_FIND_BE_(str) \ |
| 692 | EXPECT_TRUE(FindNamePhase(str, "B")); \ |
| 693 | EXPECT_TRUE(FindNamePhase(str, "E")) |
| 694 | #define EXPECT_NOT_FIND_BE_(str) \ |
| 695 | EXPECT_FALSE(FindNamePhase(str, "B")); \ |
| 696 | EXPECT_FALSE(FindNamePhase(str, "E")) |
| 697 | |
| 698 | EXPECT_FIND_BE_("threshold 100"); |
| 699 | EXPECT_FIND_BE_("threshold 1000"); |
| 700 | EXPECT_FIND_BE_("threshold 10000"); |
| 701 | EXPECT_NOT_FIND_BE_("threshold long1"); |
| 702 | EXPECT_NOT_FIND_BE_("threshold long2"); |
| 703 | |
| 704 | EXPECT_NOT_FIND_BE_("2threshold10000"); |
| 705 | EXPECT_FIND_BE_("nonthreshold1"); |
| 706 | |
| 707 | EXPECT_FIND_BE_("nonthreshold3"); |
| 708 | EXPECT_FIND_BE_("3threshold100"); |
| 709 | EXPECT_FIND_BE_("3threshold1000"); |
| 710 | EXPECT_FIND_BE_("3threshold10000"); |
| 711 | EXPECT_NOT_FIND_BE_("3thresholdlong1"); |
| 712 | EXPECT_NOT_FIND_BE_("3thresholdlong2"); |
| 713 | |
| 714 | EXPECT_FIND_BE_("nonthreshold4"); |
| 715 | EXPECT_FIND_BE_("4threshold100"); |
| 716 | EXPECT_FIND_BE_("4threshold1000"); |
| 717 | EXPECT_FIND_BE_("4threshold10000"); |
| 718 | EXPECT_NOT_FIND_BE_("4thresholdlong1"); |
| 719 | EXPECT_NOT_FIND_BE_("4thresholdlong2"); |
| 720 | } |
| 721 | |
jbates@chromium.org | 8bb0ee6 | 2011-12-03 02:17:38 +0900 | [diff] [blame] | 722 | // Test Start/Finish events |
| 723 | TEST_F(TraceEventTestFixture, StartFinishEvents) { |
| 724 | ManualTestSetUp(); |
| 725 | TraceLog::GetInstance()->SetEnabled(true); |
| 726 | |
| 727 | unsigned long long id = 0xfeedbeeffeedbeefull; |
| 728 | TRACE_EVENT_START0( "cat", "name1", id); |
| 729 | TRACE_EVENT_FINISH0("cat", "name1", id); |
| 730 | TRACE_EVENT_BEGIN0( "cat", "name2"); |
| 731 | TRACE_EVENT_START0( "cat", "name3", 0); |
| 732 | |
| 733 | TraceLog::GetInstance()->SetEnabled(false); |
| 734 | |
| 735 | EXPECT_TRUE(FindNamePhase("name1", "S")); |
| 736 | EXPECT_TRUE(FindNamePhase("name1", "F")); |
| 737 | |
| 738 | std::string id_str; |
| 739 | StringAppendF(&id_str, "%llx", id); |
| 740 | |
| 741 | EXPECT_TRUE(FindNamePhaseKeyValue("name1", "S", "id", id_str.c_str())); |
| 742 | EXPECT_TRUE(FindNamePhaseKeyValue("name1", "F", "id", id_str.c_str())); |
| 743 | EXPECT_TRUE(FindNamePhaseKeyValue("name3", "S", "id", "0")); |
| 744 | |
| 745 | // BEGIN events should not have id |
| 746 | EXPECT_FALSE(FindNamePhaseKeyValue("name2", "B", "id", "0")); |
| 747 | } |
| 748 | |
| 749 | // Test Start/Finish events |
| 750 | TEST_F(TraceEventTestFixture, StartFinishPointerMangling) { |
| 751 | ManualTestSetUp(); |
| 752 | |
| 753 | void* ptr = this; |
| 754 | |
| 755 | TraceLog::GetInstance()->SetProcessID(100); |
| 756 | TraceLog::GetInstance()->SetEnabled(true); |
| 757 | TRACE_EVENT_START0( "cat", "name1", ptr); |
| 758 | TRACE_EVENT_START0( "cat", "name2", ptr); |
| 759 | TraceLog::GetInstance()->SetEnabled(false); |
| 760 | |
| 761 | TraceLog::GetInstance()->SetProcessID(200); |
| 762 | TraceLog::GetInstance()->SetEnabled(true); |
| 763 | TRACE_EVENT_FINISH0( "cat", "name1", ptr); |
| 764 | TraceLog::GetInstance()->SetEnabled(false); |
| 765 | |
| 766 | DictionaryValue* start = FindNamePhase("name1", "S"); |
| 767 | DictionaryValue* start2 = FindNamePhase("name2", "S"); |
| 768 | DictionaryValue* finish = FindNamePhase("name1", "F"); |
| 769 | EXPECT_TRUE(start); |
| 770 | EXPECT_TRUE(start2); |
| 771 | EXPECT_TRUE(finish); |
| 772 | |
| 773 | Value* value = NULL; |
| 774 | std::string start_id_str; |
| 775 | std::string start2_id_str; |
| 776 | std::string finish_id_str; |
| 777 | ASSERT_TRUE(start->Get("id", &value)); |
| 778 | ASSERT_TRUE(value->GetAsString(&start_id_str)); |
| 779 | ASSERT_TRUE(start2->Get("id", &value)); |
| 780 | ASSERT_TRUE(value->GetAsString(&start2_id_str)); |
| 781 | ASSERT_TRUE(finish->Get("id", &value)); |
| 782 | ASSERT_TRUE(value->GetAsString(&finish_id_str)); |
| 783 | |
| 784 | EXPECT_STREQ(start_id_str.c_str(), start2_id_str.c_str()); |
| 785 | EXPECT_STRNE(start_id_str.c_str(), finish_id_str.c_str()); |
| 786 | } |
| 787 | |
jbates@chromium.org | 1f18e46 | 2011-09-07 02:56:24 +0900 | [diff] [blame] | 788 | // Test that static strings are not copied. |
| 789 | TEST_F(TraceEventTestFixture, StaticStringVsString) { |
| 790 | ManualTestSetUp(); |
| 791 | TraceLog* tracer = TraceLog::GetInstance(); |
| 792 | // Make sure old events are flushed: |
| 793 | tracer->SetEnabled(false); |
| 794 | EXPECT_EQ(0u, tracer->GetEventsSize()); |
| 795 | |
| 796 | { |
| 797 | tracer->SetEnabled(true); |
| 798 | // Test that string arguments are copied. |
| 799 | TRACE_EVENT2("cat", "name1", |
| 800 | "arg1", std::string("argval"), "arg2", std::string("argval")); |
| 801 | // Test that static TRACE_STR_COPY string arguments are copied. |
| 802 | TRACE_EVENT2("cat", "name2", |
| 803 | "arg1", TRACE_STR_COPY("argval"), |
| 804 | "arg2", TRACE_STR_COPY("argval")); |
| 805 | size_t num_events = tracer->GetEventsSize(); |
| 806 | EXPECT_GT(num_events, 1u); |
| 807 | const TraceEvent& event1 = tracer->GetEventAt(num_events - 2); |
| 808 | const TraceEvent& event2 = tracer->GetEventAt(num_events - 1); |
| 809 | EXPECT_STREQ("name1", event1.name()); |
| 810 | EXPECT_STREQ("name2", event2.name()); |
| 811 | EXPECT_TRUE(event1.parameter_copy_storage() != NULL); |
| 812 | EXPECT_TRUE(event2.parameter_copy_storage() != NULL); |
| 813 | EXPECT_GT(event1.parameter_copy_storage()->size(), 0u); |
| 814 | EXPECT_GT(event2.parameter_copy_storage()->size(), 0u); |
| 815 | tracer->SetEnabled(false); |
| 816 | } |
| 817 | |
| 818 | { |
| 819 | tracer->SetEnabled(true); |
| 820 | // Test that static literal string arguments are not copied. |
| 821 | TRACE_EVENT2("cat", "name1", |
| 822 | "arg1", "argval", "arg2", "argval"); |
| 823 | // Test that static TRACE_STR_COPY NULL string arguments are not copied. |
| 824 | const char* str1 = NULL; |
| 825 | const char* str2 = NULL; |
| 826 | TRACE_EVENT2("cat", "name2", |
| 827 | "arg1", TRACE_STR_COPY(str1), |
| 828 | "arg2", TRACE_STR_COPY(str2)); |
| 829 | size_t num_events = tracer->GetEventsSize(); |
| 830 | EXPECT_GT(num_events, 1u); |
| 831 | const TraceEvent& event1 = tracer->GetEventAt(num_events - 2); |
| 832 | const TraceEvent& event2 = tracer->GetEventAt(num_events - 1); |
| 833 | EXPECT_STREQ("name1", event1.name()); |
| 834 | EXPECT_STREQ("name2", event2.name()); |
| 835 | EXPECT_TRUE(event1.parameter_copy_storage() == NULL); |
| 836 | EXPECT_TRUE(event2.parameter_copy_storage() == NULL); |
| 837 | tracer->SetEnabled(false); |
| 838 | } |
| 839 | } |
| 840 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 841 | // Test that data sent from other threads is gathered |
| 842 | TEST_F(TraceEventTestFixture, DataCapturedOnThread) { |
| 843 | ManualTestSetUp(); |
| 844 | TraceLog::GetInstance()->SetEnabled(true); |
| 845 | |
| 846 | Thread thread("1"); |
| 847 | WaitableEvent task_complete_event(false, false); |
| 848 | thread.Start(); |
| 849 | |
| 850 | thread.message_loop()->PostTask( |
jbates@chromium.org | 0b837e4 | 2011-10-06 01:58:20 +0900 | [diff] [blame] | 851 | FROM_HERE, base::Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 852 | task_complete_event.Wait(); |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 853 | thread.Stop(); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 854 | |
| 855 | TraceLog::GetInstance()->SetEnabled(false); |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 856 | ValidateAllTraceMacrosCreatedData(trace_parsed_); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 857 | } |
| 858 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 859 | // Test that data sent from multiple threads is gathered |
| 860 | TEST_F(TraceEventTestFixture, DataCapturedManyThreads) { |
| 861 | ManualTestSetUp(); |
| 862 | TraceLog::GetInstance()->SetEnabled(true); |
| 863 | |
| 864 | const int num_threads = 4; |
| 865 | const int num_events = 4000; |
| 866 | Thread* threads[num_threads]; |
| 867 | WaitableEvent* task_complete_events[num_threads]; |
| 868 | for (int i = 0; i < num_threads; i++) { |
| 869 | threads[i] = new Thread(StringPrintf("Thread %d", i).c_str()); |
| 870 | task_complete_events[i] = new WaitableEvent(false, false); |
| 871 | threads[i]->Start(); |
| 872 | threads[i]->message_loop()->PostTask( |
jbates@chromium.org | 0b837e4 | 2011-10-06 01:58:20 +0900 | [diff] [blame] | 873 | FROM_HERE, base::Bind(&TraceManyInstantEvents, |
| 874 | i, num_events, task_complete_events[i])); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | for (int i = 0; i < num_threads; i++) { |
| 878 | task_complete_events[i]->Wait(); |
| 879 | } |
| 880 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 881 | for (int i = 0; i < num_threads; i++) { |
| 882 | threads[i]->Stop(); |
| 883 | delete threads[i]; |
| 884 | delete task_complete_events[i]; |
| 885 | } |
| 886 | |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 887 | TraceLog::GetInstance()->SetEnabled(false); |
| 888 | |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 889 | ValidateInstantEventPresentOnEveryThread(trace_parsed_, |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 890 | num_threads, num_events); |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 891 | } |
| 892 | |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 893 | // Test that thread and process names show up in the trace |
| 894 | TEST_F(TraceEventTestFixture, ThreadNames) { |
| 895 | ManualTestSetUp(); |
| 896 | |
| 897 | // Create threads before we enable tracing to make sure |
| 898 | // that tracelog still captures them. |
| 899 | const int num_threads = 4; |
| 900 | const int num_events = 10; |
| 901 | Thread* threads[num_threads]; |
| 902 | PlatformThreadId thread_ids[num_threads]; |
| 903 | for (int i = 0; i < num_threads; i++) |
| 904 | threads[i] = new Thread(StringPrintf("Thread %d", i).c_str()); |
| 905 | |
| 906 | // Enable tracing. |
| 907 | TraceLog::GetInstance()->SetEnabled(true); |
| 908 | |
| 909 | // Now run some trace code on these threads. |
| 910 | WaitableEvent* task_complete_events[num_threads]; |
| 911 | for (int i = 0; i < num_threads; i++) { |
| 912 | task_complete_events[i] = new WaitableEvent(false, false); |
| 913 | threads[i]->Start(); |
| 914 | thread_ids[i] = threads[i]->thread_id(); |
| 915 | threads[i]->message_loop()->PostTask( |
jbates@chromium.org | 0b837e4 | 2011-10-06 01:58:20 +0900 | [diff] [blame] | 916 | FROM_HERE, base::Bind(&TraceManyInstantEvents, |
| 917 | i, num_events, task_complete_events[i])); |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 918 | } |
| 919 | for (int i = 0; i < num_threads; i++) { |
| 920 | task_complete_events[i]->Wait(); |
| 921 | } |
| 922 | |
| 923 | // Shut things down. |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 924 | for (int i = 0; i < num_threads; i++) { |
| 925 | threads[i]->Stop(); |
| 926 | delete threads[i]; |
| 927 | delete task_complete_events[i]; |
| 928 | } |
| 929 | |
jbates@chromium.org | b84db52 | 2011-10-04 02:51:25 +0900 | [diff] [blame] | 930 | TraceLog::GetInstance()->SetEnabled(false); |
| 931 | |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 932 | std::string tmp; |
| 933 | int tmp_int; |
| 934 | DictionaryValue* item; |
| 935 | |
| 936 | // Make sure we get thread name metadata. |
| 937 | // Note, the test suite may have created a ton of threads. |
| 938 | // So, we'll have thread names for threads we didn't create. |
| 939 | std::vector<DictionaryValue*> items = |
| 940 | FindTraceEntries(trace_parsed_, "thread_name"); |
| 941 | for (int i = 0; i < static_cast<int>(items.size()); i++) { |
| 942 | item = items[i]; |
joth@chromium.org | 088ae01 | 2011-11-11 01:26:23 +0900 | [diff] [blame] | 943 | ASSERT_TRUE(item); |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 944 | EXPECT_TRUE(item->GetInteger("tid", &tmp_int)); |
| 945 | |
| 946 | // See if this thread name is one of the threads we just created |
| 947 | for (int j = 0; j < num_threads; j++) { |
| 948 | if(static_cast<int>(thread_ids[j]) != tmp_int) |
| 949 | continue; |
| 950 | |
| 951 | std::string expected_name = StringPrintf("Thread %d", j).c_str(); |
| 952 | EXPECT_TRUE(item->GetString("ph", &tmp) && tmp == "M"); |
| 953 | EXPECT_TRUE(item->GetInteger("pid", &tmp_int) && |
| 954 | tmp_int == static_cast<int>(base::GetCurrentProcId())); |
| 955 | EXPECT_TRUE(item->GetString("args.name", &tmp) && |
| 956 | tmp == expected_name); |
| 957 | } |
| 958 | } |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 959 | } |
| 960 | |
joth@chromium.org | 088ae01 | 2011-11-11 01:26:23 +0900 | [diff] [blame] | 961 | TEST_F(TraceEventTestFixture, ThreadNameChanges) { |
| 962 | ManualTestSetUp(); |
| 963 | |
| 964 | TraceLog::GetInstance()->SetEnabled(true); |
| 965 | |
| 966 | PlatformThread::SetName(""); |
| 967 | TRACE_EVENT_INSTANT0("drink", "water"); |
| 968 | |
| 969 | PlatformThread::SetName("cafe"); |
| 970 | TRACE_EVENT_INSTANT0("drink", "coffee"); |
| 971 | |
| 972 | PlatformThread::SetName("shop"); |
| 973 | // No event here, so won't appear in combined name. |
| 974 | |
| 975 | PlatformThread::SetName("pub"); |
| 976 | TRACE_EVENT_INSTANT0("drink", "beer"); |
| 977 | TRACE_EVENT_INSTANT0("drink", "wine"); |
| 978 | |
| 979 | PlatformThread::SetName(" bar"); |
| 980 | TRACE_EVENT_INSTANT0("drink", "whisky"); |
| 981 | |
| 982 | TraceLog::GetInstance()->SetEnabled(false); |
| 983 | |
| 984 | std::vector<DictionaryValue*> items = |
| 985 | FindTraceEntries(trace_parsed_, "thread_name"); |
| 986 | EXPECT_EQ(1u, items.size()); |
| 987 | ASSERT_GT(items.size(), 0u); |
| 988 | DictionaryValue* item = items[0]; |
| 989 | ASSERT_TRUE(item); |
| 990 | int tid; |
| 991 | EXPECT_TRUE(item->GetInteger("tid", &tid)); |
| 992 | EXPECT_EQ(PlatformThread::CurrentId(), static_cast<PlatformThreadId>(tid)); |
| 993 | |
| 994 | std::string expected_name = "cafe,pub, bar"; |
| 995 | std::string tmp; |
| 996 | EXPECT_TRUE(item->GetString("args.name", &tmp)); |
| 997 | EXPECT_EQ(expected_name, tmp); |
| 998 | } |
nduca@chromium.org | 6d04877 | 2011-08-10 00:16:25 +0900 | [diff] [blame] | 999 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 1000 | // Test trace calls made after tracing singleton shut down. |
| 1001 | // |
| 1002 | // The singleton is destroyed by our base::AtExitManager, but there can be |
| 1003 | // code still executing as the C++ static objects are destroyed. This test |
| 1004 | // forces the singleton to destroy early, and intentinally makes trace calls |
| 1005 | // afterwards. |
| 1006 | TEST_F(TraceEventTestFixture, AtExit) { |
| 1007 | // Repeat this test a few times. Besides just showing robustness, it also |
| 1008 | // allows us to test that events at shutdown do not appear with valid events |
| 1009 | // recorded after the system is started again. |
| 1010 | for (int i = 0; i < 4; i++) { |
| 1011 | // Scope to contain the then destroy the TraceLog singleton. |
| 1012 | { |
| 1013 | base::ShadowingAtExitManager exit_manager_will_destroy_singletons; |
| 1014 | |
| 1015 | // Setup TraceLog singleton inside this test's exit manager scope |
| 1016 | // so that it will be destroyed when this scope closes. |
| 1017 | ManualTestSetUp(); |
| 1018 | |
| 1019 | TRACE_EVENT_INSTANT0("all", "not recorded; system not enabled"); |
| 1020 | |
| 1021 | TraceLog::GetInstance()->SetEnabled(true); |
| 1022 | |
| 1023 | TRACE_EVENT_INSTANT0("all", "is recorded 1; system has been enabled"); |
| 1024 | // Trace calls that will cache pointers to categories; they're valid here |
| 1025 | TraceCallsWithCachedCategoryPointersPointers( |
| 1026 | "is recorded 2; system has been enabled"); |
| 1027 | |
| 1028 | TraceLog::GetInstance()->SetEnabled(false); |
| 1029 | } // scope to destroy singleton |
| 1030 | ASSERT_FALSE(TraceLog::GetInstance()); |
| 1031 | |
| 1032 | // Now that singleton is destroyed, check what trace events were recorded |
| 1033 | DictionaryValue* item = NULL; |
| 1034 | ListValue& trace_parsed = trace_parsed_; |
| 1035 | EXPECT_FIND_("is recorded 1"); |
| 1036 | EXPECT_FIND_("is recorded 2"); |
| 1037 | EXPECT_NOT_FIND_("not recorded"); |
| 1038 | |
| 1039 | // Make additional trace event calls on the shutdown system. They should |
| 1040 | // all pass cleanly, but the data not be recorded. We'll verify that next |
| 1041 | // time around the loop (the only way to flush the trace buffers). |
| 1042 | TRACE_EVENT_BEGIN_ETW("not recorded; system shutdown", 0, NULL); |
| 1043 | TRACE_EVENT_END_ETW("not recorded; system shutdown", 0, NULL); |
| 1044 | TRACE_EVENT_INSTANT_ETW("not recorded; system shutdown", 0, NULL); |
| 1045 | TRACE_EVENT0("all", "not recorded; system shutdown"); |
| 1046 | TRACE_EVENT_INSTANT0("all", "not recorded; system shutdown"); |
| 1047 | TRACE_EVENT_BEGIN0("all", "not recorded; system shutdown"); |
| 1048 | TRACE_EVENT_END0("all", "not recorded; system shutdown"); |
| 1049 | |
| 1050 | TRACE_EVENT0("new category 0!", "not recorded; system shutdown"); |
| 1051 | TRACE_EVENT_INSTANT0("new category 1!", "not recorded; system shutdown"); |
| 1052 | TRACE_EVENT_BEGIN0("new category 2!", "not recorded; system shutdown"); |
| 1053 | TRACE_EVENT_END0("new category 3!", "not recorded; system shutdown"); |
| 1054 | |
| 1055 | // Cached categories should be safe to check, and still disable traces |
| 1056 | TraceCallsWithCachedCategoryPointersPointers( |
| 1057 | "not recorded; system shutdown"); |
| 1058 | } |
| 1059 | } |
| 1060 | |
joth@chromium.org | 113de99 | 2011-07-21 21:28:59 +0900 | [diff] [blame] | 1061 | TEST_F(TraceEventTestFixture, NormallyNoDeepCopy) { |
| 1062 | // Test that the TRACE_EVENT macros do not deep-copy their string. If they |
| 1063 | // do so it may indicate a performance regression, but more-over it would |
| 1064 | // make the DEEP_COPY overloads redundant. |
| 1065 | ManualTestSetUp(); |
| 1066 | |
| 1067 | std::string name_string("event name"); |
| 1068 | |
| 1069 | TraceLog::GetInstance()->SetEnabled(true); |
| 1070 | TRACE_EVENT_INSTANT0("category", name_string.c_str()); |
| 1071 | |
| 1072 | // Modify the string in place (a wholesale reassignment may leave the old |
| 1073 | // string intact on the heap). |
| 1074 | name_string[0] = '@'; |
| 1075 | |
| 1076 | TraceLog::GetInstance()->SetEnabled(false); |
| 1077 | |
| 1078 | EXPECT_FALSE(FindTraceEntry(trace_parsed_, "event name")); |
| 1079 | EXPECT_TRUE(FindTraceEntry(trace_parsed_, name_string.c_str())); |
| 1080 | } |
| 1081 | |
| 1082 | TEST_F(TraceEventTestFixture, DeepCopy) { |
| 1083 | ManualTestSetUp(); |
| 1084 | |
| 1085 | static const char kOriginalName1[] = "name1"; |
| 1086 | static const char kOriginalName2[] = "name2"; |
| 1087 | static const char kOriginalName3[] = "name3"; |
| 1088 | std::string name1(kOriginalName1); |
| 1089 | std::string name2(kOriginalName2); |
| 1090 | std::string name3(kOriginalName3); |
| 1091 | std::string arg1("arg1"); |
| 1092 | std::string arg2("arg2"); |
| 1093 | std::string val1("val1"); |
| 1094 | std::string val2("val2"); |
| 1095 | |
| 1096 | TraceLog::GetInstance()->SetEnabled(true); |
| 1097 | TRACE_EVENT_COPY_INSTANT0("category", name1.c_str()); |
| 1098 | TRACE_EVENT_COPY_BEGIN1("category", name2.c_str(), |
| 1099 | arg1.c_str(), 5); |
| 1100 | TRACE_EVENT_COPY_END2("category", name3.c_str(), |
jbates@chromium.org | 1f18e46 | 2011-09-07 02:56:24 +0900 | [diff] [blame] | 1101 | arg1.c_str(), val1, |
| 1102 | arg2.c_str(), val2); |
joth@chromium.org | 113de99 | 2011-07-21 21:28:59 +0900 | [diff] [blame] | 1103 | |
| 1104 | // As per NormallyNoDeepCopy, modify the strings in place. |
| 1105 | name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; |
| 1106 | |
| 1107 | TraceLog::GetInstance()->SetEnabled(false); |
| 1108 | |
| 1109 | EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); |
| 1110 | EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); |
| 1111 | EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); |
| 1112 | |
| 1113 | DictionaryValue* entry1 = FindTraceEntry(trace_parsed_, kOriginalName1); |
| 1114 | DictionaryValue* entry2 = FindTraceEntry(trace_parsed_, kOriginalName2); |
| 1115 | DictionaryValue* entry3 = FindTraceEntry(trace_parsed_, kOriginalName3); |
| 1116 | ASSERT_TRUE(entry1); |
| 1117 | ASSERT_TRUE(entry2); |
| 1118 | ASSERT_TRUE(entry3); |
| 1119 | |
| 1120 | int i; |
| 1121 | EXPECT_FALSE(entry2->GetInteger("args.@rg1", &i)); |
| 1122 | EXPECT_TRUE(entry2->GetInteger("args.arg1", &i)); |
| 1123 | EXPECT_EQ(5, i); |
| 1124 | |
| 1125 | std::string s; |
| 1126 | EXPECT_TRUE(entry3->GetString("args.arg1", &s)); |
| 1127 | EXPECT_EQ("val1", s); |
| 1128 | EXPECT_TRUE(entry3->GetString("args.arg2", &s)); |
| 1129 | EXPECT_EQ("val2", s); |
| 1130 | } |
| 1131 | |
jbates@chromium.org | 6a092d7 | 2011-10-25 01:34:08 +0900 | [diff] [blame] | 1132 | // Test that TraceResultBuffer outputs the correct result whether it is added |
| 1133 | // in chunks or added all at once. |
| 1134 | TEST_F(TraceEventTestFixture, TraceResultBuffer) { |
| 1135 | ManualTestSetUp(); |
| 1136 | |
| 1137 | Clear(); |
| 1138 | |
| 1139 | trace_buffer_.Start(); |
| 1140 | trace_buffer_.AddFragment("bla1"); |
| 1141 | trace_buffer_.AddFragment("bla2"); |
| 1142 | trace_buffer_.AddFragment("bla3,bla4"); |
| 1143 | trace_buffer_.Finish(); |
| 1144 | EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
| 1145 | |
| 1146 | Clear(); |
| 1147 | |
| 1148 | trace_buffer_.Start(); |
| 1149 | trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
| 1150 | trace_buffer_.Finish(); |
| 1151 | EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
| 1152 | } |
| 1153 | |
scheib@chromium.org | 603f46e | 2011-05-10 11:23:58 +0900 | [diff] [blame] | 1154 | } // namespace debug |
| 1155 | } // namespace base |