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

Unified Diff: runtime/vm/malloc_hooks_test.cc

Issue 2990173002: Revert "[vm] Don't enable the profiler by default. Enable the profiler at startup with --observe, o… (Closed)
Patch Set: Created 3 years, 5 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 b9bb73e8c89ca262731d85521d1a3b9bac5ac733..e9d0e33f4fe5906458e6b8ba5cecaad10c7dc8d5 100644
--- a/runtime/vm/malloc_hooks_test.cc
+++ b/runtime/vm/malloc_hooks_test.cc
@@ -25,47 +25,13 @@ 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) {
- EnableMallocHooksScope scope;
+ bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
+ FLAG_profiler_native_memory = true;
+ Profiler::InitAllocationSampleBuffer();
+ 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;
@@ -79,11 +45,17 @@ 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) {
- EnableMallocHooksScope scope;
+ bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
+ FLAG_profiler_native_memory = true;
+ Profiler::InitAllocationSampleBuffer();
+ 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);
@@ -108,10 +80,22 @@ 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) {
- EnableMallocHooksAndStacksScope scope;
+ 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);
char* var = static_cast<char*>(malloc(16 * sizeof(char)));
Sample* sample = MallocHooks::GetSample(var);
@@ -120,6 +104,9 @@ 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) {
@@ -129,7 +116,9 @@ static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) {
}
VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
- EnableMallocHooksAndStacksScope scope;
+ bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
+ FLAG_profiler_native_memory = true;
+ Profiler::InitAllocationSampleBuffer();
uintptr_t test_start_address =
reinterpret_cast<uintptr_t>(Dart_TestStackTraceMallocHookLengthTest);
@@ -137,6 +126,13 @@ 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);
@@ -168,10 +164,22 @@ 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) {
- EnableMallocHooksAndStacksScope scope;
+ 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);
ClearProfileVisitor cpv(Isolate::Current());
Profiler::sample_buffer()->VisitSamples(&cpv);
@@ -192,6 +200,9 @@ 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