OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_WIN_SAMPLING_PROFILER_H_ | |
6 #define BASE_WIN_SAMPLING_PROFILER_H_ | |
7 #pragma once | |
8 | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/time.h" | |
13 #include "base/win/scoped_handle.h" | |
14 | |
15 namespace base { | |
16 namespace win { | |
17 | |
18 // This class exposes the functionality of Window's built-in sampling profiler. | |
19 // Each profiler instance covers a range of memory, and while the profiler is | |
20 // running, its buckets will count the number of times the instruction counter | |
21 // lands in the associated range of memory on a sample. | |
22 // The sampling interval is settable, but the setting is system-wide. | |
23 class BASE_EXPORT SamplingProfiler { | |
24 public: | |
25 // Create an uninitialized sampling profiler. | |
26 SamplingProfiler(); | |
27 ~SamplingProfiler(); | |
28 | |
29 // Initializes the profiler to cover the memory range |start| through | |
30 // |start| + |size|, in the process |process_handle| with bucket size | |
31 // |2^log2_bucket_size|, |log2_bucket_size| must be in the range 2-31, | |
32 // for bucket sizes of 4 bytes to 2 gigabytes. | |
33 // The process handle must grant at least PROCESS_QUERY_INFORMATION. | |
34 // The memory range should be exectuable code, like e.g. the text segment | |
35 // of an exectuable (whether DLL or EXE). | |
36 // Returns true on success. | |
37 bool Initialize(HANDLE process_handle, | |
38 void* start, | |
39 size_t size, | |
40 size_t log2_bucket_size); | |
41 | |
42 // Start this profiler, which must be initialized and not started. | |
43 bool Start(); | |
M-A Ruel
2011/12/06 15:02:50
For functions like that, I always ask myself: is t
Sigurður Ásgeirsson
2011/12/06 16:12:08
That's good comment. I started changing the interf
| |
44 // Stop this profiler, which must be started. | |
45 bool Stop(); | |
46 | |
47 // Get and set the sampling interval. | |
48 // Note that this is a system-wide setting. | |
49 static bool SetSamplingInterval(base::TimeDelta sampling_interval); | |
50 static bool GetSamplingInterval(base::TimeDelta* sampling_interval); | |
51 | |
52 // Accessors. | |
53 bool is_started() const { return is_started_; } | |
54 | |
55 // It is safe to read the counts in the sampling buckets at any time. | |
56 // Note however that there's no guarantee that you'll read consistent counts | |
57 // until the profiler has been stopped, as the counts may be updating on other | |
58 // CPU cores. | |
59 const std::vector<ULONG>& buckets() const { return buckets_; } | |
60 | |
61 private: | |
62 // Handle to the corresponding kernel object. | |
63 ScopedHandle profile_handle_; | |
64 // True iff this profiler is started. | |
65 bool is_started_; | |
66 std::vector<ULONG> buckets_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(SamplingProfiler); | |
69 }; | |
70 | |
71 } // namespace win | |
72 } // namespace base | |
73 | |
74 #endif // BASE_WIN_SAMPLING_PROFILER_H_ | |
OLD | NEW |