OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/files/file_util.h" |
7 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/profiler/stack_sampling_profiler.h" | 11 #include "base/profiler/stack_sampling_profiler.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 // STACK_SAMPLING_PROFILER_SUPPORTED is used to conditionally enable the tests | 19 // STACK_SAMPLING_PROFILER_SUPPORTED is used to conditionally enable the tests |
19 // below for supported platforms (currently Win x64). | 20 // below for supported platforms (currently Win x64 and Mac). |
20 #if defined(_WIN64) | 21 #if defined(_WIN64) || defined(OS_MACOSX) |
21 #define STACK_SAMPLING_PROFILER_SUPPORTED 1 | 22 #define STACK_SAMPLING_PROFILER_SUPPORTED 1 |
22 #endif | 23 #endif |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 | 26 |
26 using SamplingParams = StackSamplingProfiler::SamplingParams; | 27 using SamplingParams = StackSamplingProfiler::SamplingParams; |
27 using Frame = StackSamplingProfiler::Frame; | 28 using Frame = StackSamplingProfiler::Frame; |
28 using Module = StackSamplingProfiler::Module; | 29 using Module = StackSamplingProfiler::Module; |
29 using Sample = StackSamplingProfiler::Sample; | 30 using Sample = StackSamplingProfiler::Sample; |
30 using CallStackProfile = StackSamplingProfiler::CallStackProfile; | 31 using CallStackProfile = StackSamplingProfiler::CallStackProfile; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 100); | 251 100); |
251 ASSERT_TRUE(loc != sample.end()) | 252 ASSERT_TRUE(loc != sample.end()) |
252 << "Function at " | 253 << "Function at " |
253 << MaybeFixupFunctionAddressForILT( | 254 << MaybeFixupFunctionAddressForILT( |
254 reinterpret_cast<const void*>( | 255 reinterpret_cast<const void*>( |
255 &TargetThread::SignalAndWaitUntilSignaled)) | 256 &TargetThread::SignalAndWaitUntilSignaled)) |
256 << " was not found in stack:\n" | 257 << " was not found in stack:\n" |
257 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 258 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
258 FilePath executable_path; | 259 FilePath executable_path; |
259 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path)); | 260 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path)); |
260 EXPECT_EQ(executable_path, profile.modules[loc->module_index].filename); | 261 EXPECT_EQ(executable_path, |
| 262 MakeAbsoluteFilePath(profile.modules[loc->module_index].filename)); |
261 } | 263 } |
262 | 264 |
263 // Checks that the fire-and-forget interface works. | 265 // Checks that the fire-and-forget interface works. |
264 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 266 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
265 #define MAYBE_StartAndRunAsync StartAndRunAsync | 267 #define MAYBE_StartAndRunAsync StartAndRunAsync |
266 #else | 268 #else |
267 #define MAYBE_StartAndRunAsync DISABLED_StartAndRunAsync | 269 #define MAYBE_StartAndRunAsync DISABLED_StartAndRunAsync |
268 #endif | 270 #endif |
269 TEST(StackSamplingProfilerTest, MAYBE_StartAndRunAsync) { | 271 TEST(StackSamplingProfilerTest, MAYBE_StartAndRunAsync) { |
270 // StartAndRunAsync requires the caller to have a message loop. | 272 // StartAndRunAsync requires the caller to have a message loop. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 sampling_completed[1]->TimedWait(TimeDelta::FromMilliseconds(25))); | 454 sampling_completed[1]->TimedWait(TimeDelta::FromMilliseconds(25))); |
453 | 455 |
454 // Start the second profiler again and it should run. | 456 // Start the second profiler again and it should run. |
455 profiler[1]->Start(); | 457 profiler[1]->Start(); |
456 sampling_completed[1]->Wait(); | 458 sampling_completed[1]->Wait(); |
457 EXPECT_EQ(1u, profiles[1].size()); | 459 EXPECT_EQ(1u, profiles[1].size()); |
458 }); | 460 }); |
459 } | 461 } |
460 | 462 |
461 } // namespace base | 463 } // namespace base |
OLD | NEW |