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

Unified Diff: base/debug/trace_event_unittest.cc

Issue 7767014: Added support to trace_event for passing static string arguments without copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added tests Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« base/debug/trace_event.h ('K') | « base/debug/trace_event.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event_unittest.cc
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index 7217b1dee839010667d3580ff752ad0ad99ff1e9..9e934c939baa1d1653e162909fb1a0c1db8f3791 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
@@ -462,6 +463,41 @@ TEST_F(TraceEventTestFixture, DataCapturedThreshold) {
EXPECT_NOT_FIND_BE_("4thresholdlong2");
}
+// Test that static strings are not copied.
+TEST_F(TraceEventTestFixture, StaticStringVsString) {
+ ManualTestSetUp();
+ TraceLog* tracer = TraceLog::GetInstance();
+ // Make sure old events are flushed:
+ tracer->SetEnabled(false);
+ EXPECT_EQ(0u, tracer->GetEventsSize());
+
+ {
+ // Test that normal string arguments are copied.
+ tracer->SetEnabled(true);
+ TRACE_EVENT2("cat", "name1", "arg1", "argval", "arg2", "argval");
+ size_t num_events = tracer->GetEventsSize();
+ EXPECT_GT(num_events, 0u);
+ const TraceEvent& event = tracer->GetEventAt(num_events - 1);
+ EXPECT_STREQ("name1", event.name());
+ EXPECT_TRUE(event.parameter_copy_storage() != NULL);
+ EXPECT_GT(event.parameter_copy_storage()->size(), 0u);
+ tracer->SetEnabled(false);
+ }
+
+ {
+ // Test that static string arguments are not copied.
+ tracer->SetEnabled(true);
+ TRACE_EVENT2("cat", "name2", "arg1", TRACE_STATIC_STR("argval"),
+ "arg2", TRACE_STATIC_STR("argval"));
+ size_t num_events = tracer->GetEventsSize();
+ EXPECT_GT(num_events, 0u);
+ const TraceEvent& event = tracer->GetEventAt(num_events - 1);
+ EXPECT_STREQ("name2", event.name());
+ EXPECT_TRUE(event.parameter_copy_storage() == NULL);
+ tracer->SetEnabled(false);
+ }
+}
+
// Test that data sent from other threads is gathered
TEST_F(TraceEventTestFixture, DataCapturedOnThread) {
ManualTestSetUp();
« base/debug/trace_event.h ('K') | « base/debug/trace_event.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698