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