Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: runtime/vm/os_thread_win.cc

Issue 1960483002: Include thread CPU time in Timeline (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" // NOLINT 5 #include "platform/globals.h" // NOLINT
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/lockers.h" 9 #include "vm/lockers.h"
10 #include "vm/os_thread.h" 10 #include "vm/os_thread.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { 166 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) {
167 return static_cast<ThreadId>(id); 167 return static_cast<ThreadId>(id);
168 } 168 }
169 169
170 170
171 bool OSThread::Compare(ThreadId a, ThreadId b) { 171 bool OSThread::Compare(ThreadId a, ThreadId b) {
172 return a == b; 172 return a == b;
173 } 173 }
174 174
175 175
176 void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) {
177 static const int64_t kTimeEpoc = 116444736000000000LL;
178 static const int64_t kTimeScaler = 10; // 100 ns to us.
179 // Although win32 uses 64-bit integers for representing timestamps,
180 // these are packed into a FILETIME structure. The FILETIME
181 // structure is just a struct representing a 64-bit integer. The
182 // TimeStamp union allows access to both a FILETIME and an integer
183 // representation of the timestamp. The Windows timestamp is in
184 // 100-nanosecond intervals since January 1, 1601.
185 union TimeStamp {
186 FILETIME ft_;
187 int64_t t_;
188 };
189 ASSERT(cpu_usage != NULL);
190 TimeStamp created;
191 TimeStamp exited;
192 TimeStamp kernel;
193 TimeStamp user;
194 HANDLE handle = OpenThread(THREAD_QUERY_INFORMATION, false, thread_id);
195 BOOL result = GetThreadTimes(handle,
196 &created.ft_,
197 &exited.ft_,
198 &kernel.ft_,
199 &user.ft_);
200 CloseHandle(handle);
201 if (!result) {
202 FATAL1("GetThreadCpuUsage failed %d\n", GetLastError());
203 }
204 *cpu_usage = (user.t_ - kTimeEpoc) / kTimeScaler;
205 }
206
207
208 void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) { 176 void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) {
209 ASSERT(key != kUnsetThreadLocalKey); 177 ASSERT(key != kUnsetThreadLocalKey);
210 BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value)); 178 BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value));
211 if (!result) { 179 if (!result) {
212 FATAL1("TlsSetValue failed %d", GetLastError()); 180 FATAL1("TlsSetValue failed %d", GetLastError());
213 } 181 }
214 } 182 }
215 183
216 184
217 Mutex::Mutex() { 185 Mutex::Mutex() {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 #pragma data_seg(".CRT$XLB") 679 #pragma data_seg(".CRT$XLB")
712 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; 680 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit;
713 681
714 // Reset the default section. 682 // Reset the default section.
715 #pragma data_seg() 683 #pragma data_seg()
716 684
717 #endif // _WIN64 685 #endif // _WIN64
718 } // extern "C" 686 } // extern "C"
719 687
720 #endif // defined(TARGET_OS_WINDOWS) 688 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698