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

Side by Side Diff: base/trace_event/trace_event_unittest.cc

Issue 1923533004: Tracing pre-filtering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/trace_event/trace_event.h" 5 #include "base/trace_event/trace_event.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 trace_buffer_.Start(); 183 trace_buffer_.Start();
184 trace_buffer_.AddFragment(events_str->data()); 184 trace_buffer_.AddFragment(events_str->data());
185 trace_buffer_.Finish(); 185 trace_buffer_.Finish();
186 186
187 std::unique_ptr<Value> root = base::JSONReader::Read( 187 std::unique_ptr<Value> root = base::JSONReader::Read(
188 json_output_.json_output, JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN); 188 json_output_.json_output, JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN);
189 189
190 if (!root.get()) { 190 if (!root.get()) {
191 LOG(ERROR) << json_output_.json_output; 191 LOG(ERROR) << json_output_.json_output;
192 } 192 }
193
194 ListValue* root_list = NULL; 193 ListValue* root_list = NULL;
195 ASSERT_TRUE(root.get()); 194 ASSERT_TRUE(root.get());
196 ASSERT_TRUE(root->GetAsList(&root_list)); 195 ASSERT_TRUE(root->GetAsList(&root_list));
197 196
198 // Move items into our aggregate collection 197 // Move items into our aggregate collection
199 while (root_list->GetSize()) { 198 while (root_list->GetSize()) {
200 std::unique_ptr<Value> item; 199 std::unique_ptr<Value> item;
201 root_list->Remove(0, &item); 200 root_list->Remove(0, &item);
202 trace_parsed_.Append(item.release()); 201 trace_parsed_.Append(item.release());
203 } 202 }
(...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 config1.Merge(config2); 3091 config1.Merge(config2);
3093 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size()); 3092 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size());
3094 } 3093 }
3095 3094
3096 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 3095 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
3097 const char filter[] = "DELAY(test.Delay;16;oneshot)"; 3096 const char filter[] = "DELAY(test.Delay;16;oneshot)";
3098 TraceConfig config(filter, ""); 3097 TraceConfig config(filter, "");
3099 EXPECT_EQ(filter, config.ToCategoryFilterString()); 3098 EXPECT_EQ(filter, config.ToCategoryFilterString());
3100 } 3099 }
3101 3100
3101 TEST_F(TraceEventTestFixture, EventFiltering) {
3102 const char config_json[] =
3103 "{"
3104 " \"included_categories\": ["
3105 " \"filtered_cat\","
3106 " \"unfiltered_cat\"],"
3107 " \"category_event_filters\": ["
3108 " {"
3109 " \"predicate\": \"event_whitelist_predicate\", "
3110 " \"included_categories\": [\"*\"], "
3111 " \"excluded_categories\": [\"unfiltered_cat\"], "
3112 " \"args\": {\"event_name_whitelist\": [\"a snake\", \"a dog\"]}"
3113 " }"
3114 " "
3115 " ]"
3116 "}";
3117
3118 TraceConfig trace_config(config_json);
3119 // TODO(oysteine): Add TraceConfig tests.
3120 LOG(ERROR) << trace_config.ToString();
3121 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3122 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3123
3124 TRACE_EVENT0("filtered_cat", "a snake");
3125 TRACE_EVENT0("filtered_cat", "a mushroom");
3126 TRACE_EVENT0("unfiltered_cat", "a cat");
3127
3128 EndTraceAndFlush();
3129
3130 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3131 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3132 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3133 }
3134
3102 } // namespace trace_event 3135 } // namespace trace_event
3103 } // namespace base 3136 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698