|
1 // sampler.h |
|
2 // |
|
3 // Copyright (c) 1999 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #ifndef __SAMPLER_H__ |
|
14 #define __SAMPLER_H__ |
|
15 |
|
16 #include <e32cmn.h> |
|
17 #ifndef __KERNEL_MODE__ |
|
18 #include <e32std.h> |
|
19 #endif |
|
20 |
|
21 //Uncomment this line to generate debug logging of the profiler and sampler. |
|
22 //#define DEBUG_PROFILER(f) f |
|
23 #define DEBUG_PROFILER(f) |
|
24 |
|
25 /** |
|
26 * The user device driver class for controlling the sampler. |
|
27 */ |
|
28 class RSampler : public RBusLogicalChannel |
|
29 { |
|
30 friend class DProfile; |
|
31 private: |
|
32 enum TControl |
|
33 { |
|
34 EControlGetSegments, |
|
35 EControlStartProfile, |
|
36 EControlStopProfile, |
|
37 EControlResetProfile, |
|
38 EControlResetSegments, |
|
39 EControlDrain, |
|
40 EControlGetErrors |
|
41 }; |
|
42 enum TRequest |
|
43 { |
|
44 ERequestRead |
|
45 }; |
|
46 static inline TInt CancelRequest(TRequest aRequest); |
|
47 public: |
|
48 #ifndef __KERNEL_MODE__ |
|
49 /** Open a channel to the sampling device */ |
|
50 inline TInt Open(); |
|
51 /** Get the current non-XIP Code Segments*/ |
|
52 inline void GetSegments(TDes8& aData); |
|
53 /** Start sampling */ |
|
54 inline void Start(TInt aRate); |
|
55 /** Stop sampling */ |
|
56 inline void Stop(); |
|
57 /** Extract the sample data */ |
|
58 inline void Read(TDes8& aData,TRequestStatus& aStatus); |
|
59 /** Cancel a read request */ |
|
60 inline void ReadCancel(); |
|
61 /** Extract any remaining sample data */ |
|
62 inline void Drain(TDes8& aData); |
|
63 /** Get error report */ |
|
64 inline void GetErrors(TDes8& aData); |
|
65 /** Reset the sampler for a new run */ |
|
66 inline void Reset(TBool aXIPOnly); |
|
67 /** Initialise non-XIP segments for a new run */ |
|
68 inline void ResetSegments(); |
|
69 #endif |
|
70 }; |
|
71 |
|
72 _LIT(KSamplerName,"topsampler"); |
|
73 |
|
74 #ifndef __KERNEL_MODE__ |
|
75 inline TInt RSampler::CancelRequest(TRequest aRequest) |
|
76 {return 1<<aRequest;} |
|
77 |
|
78 inline TInt RSampler::Open() |
|
79 {return DoCreate(KSamplerName,TVersion(1,0,0),KNullUnit,NULL,NULL);} |
|
80 |
|
81 /** |
|
82 * Get the existing non-XIP Code Segments. |
|
83 * |
|
84 * @param aData A descriptor to receive data. Returns as zero-length if all data |
|
85 * records are already transfered. |
|
86 */ |
|
87 inline void RSampler::GetSegments(TDes8& aData) |
|
88 {DoControl(EControlGetSegments, &aData);} |
|
89 |
|
90 /** |
|
91 * Start sampling at the requested rate. If currently sampling, this will just |
|
92 * change the sample rate. |
|
93 * |
|
94 * @param aRate The sample rate in samples/second |
|
95 */ |
|
96 inline void RSampler::Start(TInt aRate) |
|
97 {DoControl(EControlStartProfile, reinterpret_cast<TAny*>(aRate));} |
|
98 |
|
99 /** |
|
100 * Stop sampling. If currently sampling, any outstanding read request will be completed |
|
101 * with data remaining in the buffer. |
|
102 */ |
|
103 inline void RSampler::Stop() |
|
104 {DoControl(EControlStopProfile);} |
|
105 |
|
106 /** |
|
107 * Reset the sampler. All sample data is discarded and history is removed, preparing the |
|
108 * sampler for a new run. The sampler must be stopped before it can be reset. |
|
109 * |
|
110 * @param aXIPOnly True if the profiler runs in XIPOnly mode. |
|
111 */ |
|
112 inline void RSampler::Reset(TBool aXIPOnly) |
|
113 {DoControl(EControlResetProfile,(TAny*)aXIPOnly);} |
|
114 |
|
115 /** |
|
116 * Reset non-XIP code segments, preparing the sampler for a new run |
|
117 */ |
|
118 inline void RSampler::ResetSegments() |
|
119 {DoControl(EControlResetSegments);} |
|
120 |
|
121 /** |
|
122 * Extract the sample data from the device. This will complete when the device's buffer is |
|
123 * full, when the provided descriptor is full, or when the sampler is stopped. |
|
124 * |
|
125 * @param aData A descriptor to receive the sample data |
|
126 * @param aStatus A request status used to signal when this request is completed |
|
127 */ |
|
128 inline void RSampler::Read(TDes8& aData,TRequestStatus& aStatus) |
|
129 {DoRequest(ERequestRead,aStatus,&aData);} |
|
130 |
|
131 /** |
|
132 * Cancel the outstanding read request |
|
133 */ |
|
134 inline void RSampler::ReadCancel() |
|
135 {DoCancel(CancelRequest(ERequestRead));} |
|
136 |
|
137 /** |
|
138 * Extract any remaining sample data from the device buffer. When the buffer is |
|
139 * empty, the descriptor will be empty on return. |
|
140 * |
|
141 * @param aData A descriptor to receive the sample data |
|
142 */ |
|
143 inline void RSampler::Drain(TDes8& aData) |
|
144 {DoControl(EControlDrain,&aData);} |
|
145 |
|
146 /** |
|
147 * Get error report from the sampler. |
|
148 * |
|
149 * @param aData A descriptor to receive error report |
|
150 */ |
|
151 inline void RSampler::GetErrors(TDes8& aData) |
|
152 {DoControl(EControlGetErrors,&aData);} |
|
153 |
|
154 #endif |
|
155 |
|
156 #endif |