00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_STOP_WATCH_H_
00014 #define _SUPPORT_STOP_WATCH_H_
00015
00021 #include <support/SupportDefs.h>
00022
00023 #ifndef _INCLUDES_PERFORMANCE_INSTRUMENTATION
00024 #define _INCLUDES_PERFORMANCE_INSTRUMENTATION 0
00025 #endif
00026
00027 #if _SUPPORTS_NAMESPACE
00028 namespace palmos {
00029 namespace support {
00030 #endif // _SUPPORTS_NAMESPACE
00031
00036
00037 enum {
00038 B_STOP_WATCH_SILENT = (1<<0),
00039 B_STOP_WATCH_NESTING = (1<<1),
00040 B_STOP_WATCH_CLEAR_CACHE = (1<<2),
00041 B_STOP_WATCH_RAW = (1<<3),
00042 B_STOP_WATCH_HIGH_PRIORITY = (1<<4),
00043 B_STOP_WATCH_QUANTIFY = (1<<5),
00044 B_STOP_WATCH_NO_TIME = (1<<6)
00045 };
00046
00047
00048 enum {
00049 B_PROFILE_KEEP_SAMPLES = (1<<0),
00050 B_PROFILE_UPLOAD_SAMPLES = (1<<1)
00051 };
00052
00053
00054
00055 enum perf_counter_t {
00056 B_COUNT_ICACHE_MISS = 0,
00057 B_COUNT_DATA_STALL = 2,
00058 B_COUNT_ITLB_MISS = 3,
00059 B_COUNT_DTLB_MISS = 4,
00060 B_COUNT_BRANCH_INSTRUCTION = 5,
00061 B_COUNT_BRANCH_MISPREDICTED = 6,
00062 B_COUNT_INSTRUCTION = 7,
00063 B_COUNT_DBUFFER_STALL_DURATION = 8,
00064 B_COUNT_DBUFFER_STALL = 9,
00065 B_COUNT_DCACHE_ACCESS = 10,
00066 B_COUNT_DCACHE_MISS = 11,
00067 B_COUNT_DCACHE_WRITEBACK = 12,
00068 B_COUNT_PC_CHANGE = 13
00069 };
00070
00071
00072 enum {
00073 B_COUNT_HIGH_PRECISION = (1<<0)
00074 };
00075
00076
00077 enum perf_counter_reg_t {
00078 B_COUNT_REGISTER_CYCLES = 0,
00079 B_COUNT_REGISTER_A = 1,
00080 B_COUNT_REGISTER_B = 2
00081 };
00082
00083
00084 enum {
00085 B_PERFORMANCE_WEIGHT_EMPTY = 100,
00086 B_PERFORMANCE_WEIGHT_LIGHT = 200,
00087 B_PERFORMANCE_WEIGHT_MEDIUM = 300,
00088 B_PERFORMANCE_WEIGHT_HEAVY = 400
00089 };
00090
00091
00092
00093 #if _INCLUDES_PERFORMANCE_INSTRUMENTATION
00094 #define B_PERFORMANCE_NODE(weight, name) SStopWatch __performance_node__(weight, name)
00095 #else
00096 #define B_PERFORMANCE_NODE(weight, name)
00097 #endif
00098
00099
00100
00101
00102 class SStopWatch
00103 {
00104 public:
00105
00106
00107
00108
00109
00110
00111 SStopWatch(const char *name, uint32_t flags = 0, int32_t minWeight = 0, size_t maxItems = 0);
00112
00113
00114 SStopWatch(int32_t weight, const char *name);
00115
00116 ~SStopWatch();
00117
00118 static void FlushICache();
00119
00120 const char* Name() const;
00121
00122
00123
00124
00125
00126
00127 void StartProfiling(uint32_t flags = 0);
00128
00129
00130
00131
00132 void AddPerformanceRatio(perf_counter_reg_t numerator, perf_counter_reg_t denominator);
00133 void StartPerformance(perf_counter_t cntA, perf_counter_t cntB, uint32_t flags = 0);
00134
00135
00136
00137
00138 void Restart();
00139
00140
00141
00142 void Mark();
00143
00144
00145
00146 void Suspend();
00147 void Resume();
00148
00149
00150
00151 nsecs_t ElapsedTime() const;
00152
00153
00154 void Stop();
00155 void StopFast();
00156
00157
00158
00159 nsecs_t TotalTime() const;
00160 int64_t TotalPerformance(perf_counter_reg_t reg) const;
00161
00162 struct Node;
00163 struct Root;
00164
00165
00166 private:
00167
00168 SStopWatch(const SStopWatch &);
00169 SStopWatch &operator=(const SStopWatch &);
00170
00171 void InitChild(Root* root, const char* name);
00172 void MarkInternal(Root* root);
00173 void RestartInternal(Root* root);
00174 void StopInternal(Root* root);
00175
00176 Root* m_root;
00177 Node* m_node;
00178 Node* m_parent;
00179 int32_t m_type;
00180 };
00181
00182
00183
00184
00185 class SPerformanceSample
00186 {
00187 public:
00188 SPerformanceSample();
00189 ~SPerformanceSample();
00190
00191 private:
00192 uint32_t m_counters[3];
00193 };
00194
00195
00196
00197
00198 #if _SUPPORTS_NAMESPACE
00199 } }
00200 #endif
00201
00204 #endif