| 40 | public: |
| 41 | |
| 42 | Telemetry(StackContext *inStack, bool profiler_en, bool allocs_en) |
| 43 | : mT0(0) |
| 44 | { |
| 45 | stack = inStack; |
| 46 | names.push_back("1-indexed"); |
| 47 | namesStashed = 1; |
| 48 | ignoreAllocs = allocs_en ? 0 : 1; |
| 49 | allocStacksStashed = 0; |
| 50 | allocStackIdNext = 0; |
| 51 | allocStackIdMapRoot.terminationStackId = 0; |
| 52 | gcTimer = 0; |
| 53 | gcTimerTemp = 0; |
| 54 | gcOverhead = 0; |
| 55 | _last_obj = 0; |
| 56 | |
| 57 | profiler_enabled = profiler_en; |
| 58 | allocations_enabled = profiler_en && allocs_en; |
| 59 | |
| 60 | samples = 0; |
| 61 | allocation_data = 0; |
| 62 | |
| 63 | // Push a blank (destroyed on first Dump) |
| 64 | Stash(); |
| 65 | |
| 66 | // When a profiler exists, the profiler thread needs to exist |
| 67 | std::lock_guard<std::recursive_mutex> lock(gThreadMutex); |
| 68 | |
| 69 | gThreadRefCount += 1; |
| 70 | if (gThreadRefCount == 1) { |
| 71 | std::thread thread(ProfileMainLoop); |
| 72 | |
| 73 | thread.detach(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | ~Telemetry() |
| 78 | { |