Commit 96faef9c authored by nednguyen@google.com's avatar nednguyen@google.com

Add RECORD_AS_MUCH_AS_POSSIBLE mode to TraceOptions.

With current implementation of devtool_tracing_handler, it doesn't do 
anything with invalid options and just use RECORD_UNTIL_FULL by default. So
the change to telemetry's tracing backend will not break backward
compatibility for browsers that don't support "record-as-much-as-possible" option.

However, this is a hacky way to maintain backward compatibility, and we 
should fix devtool_tracing_handler so it can respond with error message on
Tracing.start if there is options parsing error.

BUG=396081

Review URL: https://codereview.chromium.org/440903003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288047 0039d316-1c4b-4281-b951-d872f2087c98
parent 17214644
...@@ -61,6 +61,7 @@ const int kOverheadReportThresholdInMicroseconds = 50; ...@@ -61,6 +61,7 @@ const int kOverheadReportThresholdInMicroseconds = 50;
// String options that can be used to initialize TraceOptions. // String options that can be used to initialize TraceOptions.
const char kRecordUntilFull[] = "record-until-full"; const char kRecordUntilFull[] = "record-until-full";
const char kRecordContinuously[] = "record-continuously"; const char kRecordContinuously[] = "record-continuously";
const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible";
const char kTraceToConsole[] = "trace-to-console"; const char kTraceToConsole[] = "trace-to-console";
const char kEnableSampling[] = "enable-sampling"; const char kEnableSampling[] = "enable-sampling";
const char kEnableSystrace[] = "enable-systrace"; const char kEnableSystrace[] = "enable-systrace";
...@@ -68,6 +69,8 @@ const char kEnableSystrace[] = "enable-systrace"; ...@@ -68,6 +69,8 @@ const char kEnableSystrace[] = "enable-systrace";
// Controls the number of trace events we will buffer in-memory // Controls the number of trace events we will buffer in-memory
// before throwing them away. // before throwing them away.
const size_t kTraceBufferChunkSize = TraceBufferChunk::kTraceBufferChunkSize; const size_t kTraceBufferChunkSize = TraceBufferChunk::kTraceBufferChunkSize;
const size_t kTraceEventVectorBigBufferChunks =
512000000 / kTraceBufferChunkSize;
const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize; const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize;
const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4; const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4;
const size_t kTraceEventBatchChunks = 1000 / kTraceBufferChunkSize; const size_t kTraceEventBatchChunks = 1000 / kTraceBufferChunkSize;
...@@ -996,6 +999,8 @@ TraceOptions::TraceOptions(const std::string& options_string) ...@@ -996,6 +999,8 @@ TraceOptions::TraceOptions(const std::string& options_string)
record_mode = RECORD_CONTINUOUSLY; record_mode = RECORD_CONTINUOUSLY;
} else if (*iter == kTraceToConsole) { } else if (*iter == kTraceToConsole) {
record_mode = ECHO_TO_CONSOLE; record_mode = ECHO_TO_CONSOLE;
} else if (*iter == kRecordAsMuchAsPossible) {
record_mode = RECORD_AS_MUCH_AS_POSSIBLE;
} else if (*iter == kEnableSampling) { } else if (*iter == kEnableSampling) {
enable_sampling = true; enable_sampling = true;
} else if (*iter == kEnableSystrace) { } else if (*iter == kEnableSystrace) {
...@@ -1018,6 +1023,9 @@ std::string TraceOptions::ToString() const { ...@@ -1018,6 +1023,9 @@ std::string TraceOptions::ToString() const {
case ECHO_TO_CONSOLE: case ECHO_TO_CONSOLE:
ret = kTraceToConsole; ret = kTraceToConsole;
break; break;
case RECORD_AS_MUCH_AS_POSSIBLE:
ret = kRecordAsMuchAsPossible;
break;
default: default:
NOTREACHED(); NOTREACHED();
} }
...@@ -1478,6 +1486,8 @@ TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions( ...@@ -1478,6 +1486,8 @@ TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions(
return ret | kInternalRecordContinuously; return ret | kInternalRecordContinuously;
case ECHO_TO_CONSOLE: case ECHO_TO_CONSOLE:
return ret | kInternalEchoToConsole; return ret | kInternalEchoToConsole;
case RECORD_AS_MUCH_AS_POSSIBLE:
return ret | kInternalRecordAsMuchAsPossible;
} }
NOTREACHED(); NOTREACHED();
return kInternalNone; return kInternalNone;
...@@ -1498,6 +1508,8 @@ TraceOptions TraceLog::GetCurrentTraceOptions() const { ...@@ -1498,6 +1508,8 @@ TraceOptions TraceLog::GetCurrentTraceOptions() const {
ret.record_mode = RECORD_CONTINUOUSLY; ret.record_mode = RECORD_CONTINUOUSLY;
else if (option & kInternalEchoToConsole) else if (option & kInternalEchoToConsole)
ret.record_mode = ECHO_TO_CONSOLE; ret.record_mode = ECHO_TO_CONSOLE;
else if (option & kInternalRecordAsMuchAsPossible)
ret.record_mode = RECORD_AS_MUCH_AS_POSSIBLE;
else else
NOTREACHED(); NOTREACHED();
return ret; return ret;
...@@ -1599,6 +1611,8 @@ TraceBuffer* TraceLog::CreateTraceBuffer() { ...@@ -1599,6 +1611,8 @@ TraceBuffer* TraceLog::CreateTraceBuffer() {
return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks); return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks);
else if (options & kInternalEchoToConsole) else if (options & kInternalEchoToConsole)
return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks); return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks);
else if (options & kInternalRecordAsMuchAsPossible)
return CreateTraceBufferVectorOfSize(kTraceEventVectorBigBufferChunks);
return CreateTraceBufferVectorOfSize(kTraceEventVectorBufferChunks); return CreateTraceBufferVectorOfSize(kTraceEventVectorBufferChunks);
} }
......
...@@ -384,6 +384,9 @@ enum TraceRecordMode { ...@@ -384,6 +384,9 @@ enum TraceRecordMode {
// Echo to console. Events are discarded. // Echo to console. Events are discarded.
ECHO_TO_CONSOLE, ECHO_TO_CONSOLE,
// Record until the trace buffer is full, but with a huge buffer size.
RECORD_AS_MUCH_AS_POSSIBLE
}; };
struct BASE_EXPORT TraceOptions { struct BASE_EXPORT TraceOptions {
...@@ -649,7 +652,8 @@ class BASE_EXPORT TraceLog { ...@@ -649,7 +652,8 @@ class BASE_EXPORT TraceLog {
TraceBufferVectorReportFull); TraceBufferVectorReportFull);
FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
ConvertTraceOptionsToInternalOptions); ConvertTraceOptionsToInternalOptions);
FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
TraceRecordAsMuchAsPossibleMode);
// This allows constructor and destructor to be private and usable only // This allows constructor and destructor to be private and usable only
// by the Singleton class. // by the Singleton class.
...@@ -729,6 +733,7 @@ class BASE_EXPORT TraceLog { ...@@ -729,6 +733,7 @@ class BASE_EXPORT TraceLog {
static const InternalTraceOptions kInternalRecordContinuously; static const InternalTraceOptions kInternalRecordContinuously;
static const InternalTraceOptions kInternalEchoToConsole; static const InternalTraceOptions kInternalEchoToConsole;
static const InternalTraceOptions kInternalEnableSampling; static const InternalTraceOptions kInternalEnableSampling;
static const InternalTraceOptions kInternalRecordAsMuchAsPossible;
// This lock protects TraceLog member accesses (except for members protected // This lock protects TraceLog member accesses (except for members protected
// by thread_info_lock_) from arbitrary threads. // by thread_info_lock_) from arbitrary threads.
......
...@@ -11,15 +11,18 @@ namespace debug { ...@@ -11,15 +11,18 @@ namespace debug {
const char* CategoryFilter::kDefaultCategoryFilterString = "-*Debug,-*Test"; const char* CategoryFilter::kDefaultCategoryFilterString = "-*Debug,-*Test";
// Constant used by TraceLog's internal implementation of trace_option. // Constant used by TraceLog's internal implementation of trace_option.
const TraceLog::InternalTraceOptions TraceLog::kInternalNone = 0; const TraceLog::InternalTraceOptions
const TraceLog::InternalTraceOptions TraceLog::kInternalRecordUntilFull = TraceLog::kInternalNone = 0;
1 << 0; const TraceLog::InternalTraceOptions
const TraceLog::InternalTraceOptions TraceLog::kInternalRecordContinuously = TraceLog::kInternalRecordUntilFull = 1 << 0;
1 << 1; const TraceLog::InternalTraceOptions
const TraceLog::InternalTraceOptions TraceLog::kInternalEnableSampling = 1 TraceLog::kInternalRecordContinuously = 1 << 1;
<< 2; const TraceLog::InternalTraceOptions
const TraceLog::InternalTraceOptions TraceLog::kInternalEchoToConsole = 1 TraceLog::kInternalEnableSampling = 1 << 2;
<< 3; const TraceLog::InternalTraceOptions
TraceLog::kInternalEchoToConsole = 1 << 3;
const TraceLog::InternalTraceOptions
TraceLog::kInternalRecordAsMuchAsPossible = 1 << 4;
} // namespace debug } // namespace debug
} // namespace base } // namespace base
...@@ -2602,6 +2602,15 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferFullIteration) { ...@@ -2602,6 +2602,15 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferFullIteration) {
TraceLog::GetInstance()->SetDisabled(); TraceLog::GetInstance()->SetDisabled();
} }
TEST_F(TraceEventTestFixture, TraceRecordAsMuchAsPossibleMode) {
TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
TraceLog::RECORDING_MODE,
TraceOptions(RECORD_AS_MUCH_AS_POSSIBLE));
TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer();
EXPECT_EQ(512000000UL, buffer->Capacity());
TraceLog::GetInstance()->SetDisabled();
}
// Test the category filter. // Test the category filter.
TEST_F(TraceEventTestFixture, CategoryFilter) { TEST_F(TraceEventTestFixture, CategoryFilter) {
// Using the default filter. // Using the default filter.
...@@ -3005,6 +3014,11 @@ TEST(TraceOptionsTest, DISABLED_TraceOptionsFromString) { ...@@ -3005,6 +3014,11 @@ TEST(TraceOptionsTest, DISABLED_TraceOptionsFromString) {
EXPECT_FALSE(options.enable_sampling); EXPECT_FALSE(options.enable_sampling);
EXPECT_FALSE(options.enable_systrace); EXPECT_FALSE(options.enable_systrace);
options = TraceOptions("record-as-much-as-possible");
EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, options.record_mode);
EXPECT_FALSE(options.enable_sampling);
EXPECT_FALSE(options.enable_systrace);
options = TraceOptions("record-until-full, enable-sampling"); options = TraceOptions("record-until-full, enable-sampling");
EXPECT_EQ(RECORD_UNTIL_FULL, options.record_mode); EXPECT_EQ(RECORD_UNTIL_FULL, options.record_mode);
EXPECT_TRUE(options.enable_sampling); EXPECT_TRUE(options.enable_sampling);
...@@ -3039,12 +3053,14 @@ TEST(TraceOptionsTest, DISABLED_TraceOptionsFromString) { ...@@ -3039,12 +3053,14 @@ TEST(TraceOptionsTest, DISABLED_TraceOptionsFromString) {
TEST(TraceOptionsTest, TraceOptionsToString) { TEST(TraceOptionsTest, TraceOptionsToString) {
// Test that we can intialize TraceOptions from a string got from // Test that we can intialize TraceOptions from a string got from
// TraceOptions.ToString() method to get a same TraceOptions. // TraceOptions.ToString() method to get a same TraceOptions.
TraceRecordMode modes[] = { TraceRecordMode modes[] = {RECORD_UNTIL_FULL,
RECORD_UNTIL_FULL, RECORD_CONTINUOUSLY, ECHO_TO_CONSOLE}; RECORD_CONTINUOUSLY,
ECHO_TO_CONSOLE,
RECORD_AS_MUCH_AS_POSSIBLE};
bool enable_sampling_options[] = {true, false}; bool enable_sampling_options[] = {true, false};
bool enable_systrace_options[] = {true, false}; bool enable_systrace_options[] = {true, false};
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 2; ++j) { for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) { for (int k = 0; k < 2; ++k) {
TraceOptions original_option = TraceOptions(modes[i]); TraceOptions original_option = TraceOptions(modes[i]);
......
...@@ -30,6 +30,7 @@ namespace { ...@@ -30,6 +30,7 @@ namespace {
const char kRecordUntilFull[] = "record-until-full"; const char kRecordUntilFull[] = "record-until-full";
const char kRecordContinuously[] = "record-continuously"; const char kRecordContinuously[] = "record-continuously";
const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible";
const char kEnableSampling[] = "enable-sampling"; const char kEnableSampling[] = "enable-sampling";
void ReadFile( void ReadFile(
...@@ -141,6 +142,8 @@ base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString( ...@@ -141,6 +142,8 @@ base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString(
ret.record_mode = base::debug::RECORD_UNTIL_FULL; ret.record_mode = base::debug::RECORD_UNTIL_FULL;
} else if (*iter == kRecordContinuously) { } else if (*iter == kRecordContinuously) {
ret.record_mode = base::debug::RECORD_CONTINUOUSLY; ret.record_mode = base::debug::RECORD_CONTINUOUSLY;
} else if (*iter == kRecordAsMuchAsPossible) {
ret.record_mode = base::debug::RECORD_AS_MUCH_AS_POSSIBLE;
} else if (*iter == kEnableSampling) { } else if (*iter == kEnableSampling) {
ret.enable_sampling = true; ret.enable_sampling = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment