@@ -77,7 +77,7 @@ std::unique_ptr<StackFramesCollectorBase> CreateNewStackFramesCollectorInstance(
77
77
#endif
78
78
}
79
79
80
- uint64_t GetThreadCpuTime (IThreadInfo* pThreadInfo)
80
+ std::chrono::milliseconds GetThreadCpuTime (IThreadInfo* pThreadInfo)
81
81
{
82
82
FILETIME creationTime, exitTime = {}; // not used here
83
83
FILETIME kernelTime = {};
@@ -87,7 +87,7 @@ uint64_t GetThreadCpuTime(IThreadInfo* pThreadInfo)
87
87
if (::GetThreadTimes (pThreadInfo->GetOsThreadHandle (), &creationTime, &exitTime, &kernelTime, &userTime))
88
88
{
89
89
uint64_t milliseconds = GetTotalMilliseconds (userTime) + GetTotalMilliseconds (kernelTime);
90
- return milliseconds;
90
+ return std::chrono:: milliseconds(milliseconds) ;
91
91
}
92
92
else
93
93
{
@@ -106,7 +106,7 @@ uint64_t GetThreadCpuTime(IThreadInfo* pThreadInfo)
106
106
}
107
107
}
108
108
}
109
- return 0 ;
109
+ return 0ms ;
110
110
}
111
111
112
112
typedef LONG KPRIORITY;
@@ -193,16 +193,14 @@ bool IsRunning(ULONG threadState)
193
193
// If some callstacks show non cpu-bound frames at the top, return true only for Running state
194
194
}
195
195
196
- bool IsRunning (IThreadInfo* pThreadInfo, uint64_t & cpuTime, bool & failed)
196
+ // isRunning, cpu time , failed
197
+ std::tuple<bool , std::chrono::milliseconds, bool > IsRunning (IThreadInfo* pThreadInfo)
197
198
{
198
- failed = true ;
199
- cpuTime = 0 ;
200
-
201
199
if (NtQueryInformationThread == nullptr )
202
200
{
203
201
if (!InitializeNtQueryInformationThreadCallback ())
204
202
{
205
- return false ;
203
+ return { false , 0ms, true } ;
206
204
}
207
205
}
208
206
@@ -230,14 +228,12 @@ bool IsRunning(IThreadInfo* pThreadInfo, uint64_t& cpuTime, bool& failed)
230
228
}
231
229
#endif
232
230
// This always happens in 32 bit so uses another API to at least get the CPU consumption
233
- cpuTime = GetThreadCpuTime (pThreadInfo);
234
- return false ;
231
+ return {false , GetThreadCpuTime (pThreadInfo), true };
235
232
}
236
233
237
- failed = false ;
238
- cpuTime = GetTotalMilliseconds (sti.UserTime ) + GetTotalMilliseconds (sti.KernelTime );
234
+ auto cpuTime = std::chrono::milliseconds (GetTotalMilliseconds (sti.UserTime ) + GetTotalMilliseconds (sti.KernelTime ));
239
235
240
- return IsRunning (sti.ThreadState );
236
+ return { IsRunning (sti.ThreadState ), cpuTime, false } ;
241
237
}
242
238
243
239
// https://devblogs.microsoft.com/oldnewthing/20200824-00/?p=104116
0 commit comments