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

Unified Diff: runtime/vm/malloc_hooks_test.cc

Issue 2992893002: Reapply "[vm] Don't enable the profiler by default. Enable the profiler at startup with --observe, … (Closed)
Patch Set: native symbol resolver Created 3 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
« no previous file with comments | « runtime/vm/flow_graph_compiler.cc ('k') | runtime/vm/profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/malloc_hooks_test.cc
diff --git a/runtime/vm/malloc_hooks_test.cc b/runtime/vm/malloc_hooks_test.cc
index e9d0e33f4fe5906458e6b8ba5cecaad10c7dc8d5..b9bb73e8c89ca262731d85521d1a3b9bac5ac733 100644
--- a/runtime/vm/malloc_hooks_test.cc
+++ b/runtime/vm/malloc_hooks_test.cc
@@ -25,13 +25,47 @@ static void MallocHookTestBufferInitializer(volatile char* buffer,
}
}
+class EnableMallocHooksScope : public ValueObject {
+ public:
+ EnableMallocHooksScope() {
+ saved_enable_malloc_hooks_ = FLAG_profiler_native_memory;
+ FLAG_profiler_native_memory = true;
+ Profiler::InitAllocationSampleBuffer();
+ MallocHooks::InitOnce();
+ MallocHooks::ResetStats();
+ }
+
+ ~EnableMallocHooksScope() {
+ MallocHooks::TearDown();
+ FLAG_profiler_native_memory = saved_enable_malloc_hooks_;
+ }
+
+ private:
+ bool saved_enable_malloc_hooks_;
+};
+
+class EnableMallocHooksAndStacksScope : public EnableMallocHooksScope {
+ public:
+ EnableMallocHooksAndStacksScope() {
+ saved_enable_stack_traces_ = MallocHooks::stack_trace_collection_enabled();
+ MallocHooks::set_stack_trace_collection_enabled(true);
+ if (!FLAG_profiler) {
+ FLAG_profiler = true;
+ Profiler::InitOnce();
+ }
+ }
+
+ ~EnableMallocHooksAndStacksScope() {
+ MallocHooks::set_stack_trace_collection_enabled(saved_enable_stack_traces_);
+ }
+
+ private:
+ bool saved_enable_stack_traces_;
+};
+
UNIT_TEST_CASE(BasicMallocHookTest) {
- bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
- FLAG_profiler_native_memory = true;
- Profiler::InitAllocationSampleBuffer();
+ EnableMallocHooksScope scope;
- MallocHooks::InitOnce();
- MallocHooks::ResetStats();
EXPECT_EQ(0L, MallocHooks::allocation_count());
EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes());
const intptr_t buffer_size = 10;
@@ -45,17 +79,11 @@ UNIT_TEST_CASE(BasicMallocHookTest) {
delete[] buffer;
EXPECT_EQ(0L, MallocHooks::allocation_count());
EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes());
- MallocHooks::TearDown();
-
- FLAG_profiler_native_memory = enable_malloc_hooks_saved;
}
UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) {
- bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
- FLAG_profiler_native_memory = true;
- Profiler::InitAllocationSampleBuffer();
+ EnableMallocHooksScope scope;
- MallocHooks::InitOnce();
const intptr_t pre_hook_buffer_size = 3;
char* pre_hook_buffer = new char[pre_hook_buffer_size];
MallocHookTestBufferInitializer(pre_hook_buffer, pre_hook_buffer_size);
@@ -80,22 +108,10 @@ UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) {
delete[] buffer;
EXPECT_EQ(0L, MallocHooks::allocation_count());
EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes());
- MallocHooks::TearDown();
-
- FLAG_profiler_native_memory = enable_malloc_hooks_saved;
}
VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) {
- bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
- FLAG_profiler_native_memory = true;
- Profiler::InitAllocationSampleBuffer();
-
- MallocHooks::InitOnce();
- MallocHooks::ResetStats();
-
- bool enable_stack_traces_saved =
- MallocHooks::stack_trace_collection_enabled();
- MallocHooks::set_stack_trace_collection_enabled(true);
+ EnableMallocHooksAndStacksScope scope;
char* var = static_cast<char*>(malloc(16 * sizeof(char)));
Sample* sample = MallocHooks::GetSample(var);
@@ -104,9 +120,6 @@ VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) {
free(var);
sample = MallocHooks::GetSample(var);
EXPECT(sample == NULL);
- MallocHooks::TearDown();
- MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
- FLAG_profiler_native_memory = enable_malloc_hooks_saved;
}
static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) {
@@ -116,9 +129,7 @@ static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) {
}
VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
- bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
- FLAG_profiler_native_memory = true;
- Profiler::InitAllocationSampleBuffer();
+ EnableMallocHooksAndStacksScope scope;
uintptr_t test_start_address =
reinterpret_cast<uintptr_t>(Dart_TestStackTraceMallocHookLengthTest);
@@ -126,13 +137,6 @@ VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
reinterpret_cast<uintptr_t>(StackTraceLengthHelper);
uintptr_t helper_end_address = 0;
- MallocHooks::InitOnce();
- MallocHooks::ResetStats();
-
- bool enable_stack_traces_saved =
- MallocHooks::stack_trace_collection_enabled();
- MallocHooks::set_stack_trace_collection_enabled(true);
-
char* var = StackTraceLengthHelper(&helper_end_address);
Sample* sample = MallocHooks::GetSample(var);
EXPECT(sample != NULL);
@@ -164,22 +168,10 @@ VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
}
free(var);
- MallocHooks::TearDown();
- MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
- FLAG_profiler_native_memory = enable_malloc_hooks_saved;
}
ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) {
- bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
- FLAG_profiler_native_memory = true;
- Profiler::InitAllocationSampleBuffer();
-
- MallocHooks::InitOnce();
- MallocHooks::ResetStats();
-
- bool enable_stack_traces_saved =
- MallocHooks::stack_trace_collection_enabled();
- MallocHooks::set_stack_trace_collection_enabled(true);
+ EnableMallocHooksAndStacksScope scope;
ClearProfileVisitor cpv(Isolate::Current());
Profiler::sample_buffer()->VisitSamples(&cpv);
@@ -200,9 +192,6 @@ ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) {
EXPECT_SUBSTRING("\"main\"", json);
free(var);
- MallocHooks::TearDown();
- MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
- FLAG_profiler_native_memory = enable_malloc_hooks_saved;
}
}; // namespace dart
« no previous file with comments | « runtime/vm/flow_graph_compiler.cc ('k') | runtime/vm/profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698