diff -Nur a/trunk/source/ps/Profile.h b/trunk/source/ps/Profile.h
a
|
b
|
|
150 | 150 | { |
151 | 151 | public: |
152 | 152 | CProfileSample(const char* name) |
| 153 | : n(name) |
153 | 154 | { |
154 | 155 | if (CProfileManager::IsInitialised()) |
155 | 156 | { |
… |
… |
|
161 | 162 | } |
162 | 163 | ~CProfileSample() |
163 | 164 | { |
164 | | if (CProfileManager::IsInitialised()) |
165 | | g_Profiler.Stop(); |
| 165 | if (!CProfileManager::IsInitialised() || !ThreadUtil::IsMainThread()) |
| 166 | return; |
| 167 | if (n != g_Profiler.GetCurrent()->GetName()) |
| 168 | { |
| 169 | debug_printf(L"PROFILER: Current not right: Should be \"%s\" but is \"%s\"\n", n, g_Profiler.GetCurrent()->GetName()); |
| 170 | |
| 171 | do { |
| 172 | debug_printf(L"PROFILER: Skip \"%s\". This profiler was not stopped correctly!\n", g_Profiler.GetCurrent()->GetName()); |
| 173 | g_Profiler.Stop(); |
| 174 | } |
| 175 | while (n != g_Profiler.GetCurrent()->GetName() && g_Profiler.GetCurrent() != g_Profiler.GetRoot()); |
| 176 | |
| 177 | if (g_Profiler.GetCurrent() == g_Profiler.GetRoot() && n != g_Profiler.GetRoot()->GetName()) |
| 178 | { |
| 179 | // This should only happen when stop is called more often than start was called. |
| 180 | debug_printf(L"PROFILER: Did not find the right callee in the stack but reached root: Performing reset.\n"); |
| 181 | g_Profiler.StructuralReset(); |
| 182 | } |
| 183 | } |
| 184 | g_Profiler.Stop(); |
166 | 185 | } |
| 186 | private: |
| 187 | const char *n; |
167 | 188 | }; |
168 | 189 | |
169 | 190 | class CProfileSampleScript |
170 | 191 | { |
171 | 192 | public: |
172 | | CProfileSampleScript( const char* name ) |
| 193 | CProfileSampleScript(const char* name) |
| 194 | : n(name) |
173 | 195 | { |
174 | 196 | if (CProfileManager::IsInitialised()) |
175 | 197 | { |
… |
… |
|
184 | 206 | } |
185 | 207 | ~CProfileSampleScript() |
186 | 208 | { |
187 | | if (CProfileManager::IsInitialised()) |
188 | | if (ThreadUtil::IsMainThread()) |
| 209 | if (!CProfileManager::IsInitialised() || !ThreadUtil::IsMainThread()) |
| 210 | return; |
| 211 | if (n != g_Profiler.GetCurrent()->GetName()) |
| 212 | { |
| 213 | debug_printf(L"PROFILER: Current not right: Should be \"%s\" but is \"%s\"\n", n, g_Profiler.GetCurrent()->GetName()); |
| 214 | |
| 215 | do { |
| 216 | debug_printf(L"PROFILER: Skip \"%s\". This profiler was not stopped correctly!\n", g_Profiler.GetCurrent()->GetName()); |
189 | 217 | g_Profiler.Stop(); |
| 218 | } |
| 219 | while (n != g_Profiler.GetCurrent()->GetName() && g_Profiler.GetCurrent() != g_Profiler.GetRoot()); |
| 220 | |
| 221 | if (g_Profiler.GetCurrent() == g_Profiler.GetRoot() && n != g_Profiler.GetRoot()->GetName()) |
| 222 | { |
| 223 | // This should only happen when stop is called more often than start was called. |
| 224 | debug_printf(L"PROFILER: Did not find the right callee in the stack but reached root: Performing reset.\n"); |
| 225 | g_Profiler.StructuralReset(); |
| 226 | } |
| 227 | } |
| 228 | g_Profiler.Stop(); |
190 | 229 | } |
| 230 | private: |
| 231 | const char *n; |
| 232 | |
191 | 233 | }; |
192 | 234 | |
193 | 235 | // Put a PROFILE("xyz") block at the start of all code to be profiled. |