Changeset 61464 in vbox
- Timestamp:
- Jun 4, 2016 2:37:02 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 107791
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r61172 r61464 46 46 47 47 if sys.platform == 'win32': 48 import ctypes; 48 49 import win32api; # pylint: disable=F0401 49 50 import win32con; # pylint: disable=F0401 … … 330 331 Returns process exit code (see subprocess.poll). 331 332 """ 332 assert dKeywordArgs.get('stdout') ==None;333 assert dKeywordArgs.get('stderr') ==None;333 assert dKeywordArgs.get('stdout') is None; 334 assert dKeywordArgs.get('stderr') is None; 334 335 _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs); 335 336 oProcess = subprocess.Popen(*aPositionalArgs, **dKeywordArgs); … … 451 452 if sys.platform == 'win32': 452 453 try: 453 win32console.GenerateConsoleCtrlEvent(win32con.CTRL_BREAK_EVENT, uPid); # pylint454 win32console.GenerateConsoleCtrlEvent(win32con.CTRL_BREAK_EVENT, uPid); # pylint: disable=no-member 454 455 fRc = True; 455 456 except: … … 490 491 if sys.platform == 'win32': 491 492 try: 492 hProcess = win32api.OpenProcess(win32con.PROCESS_TERMINATE, False, uPid); 493 hProcess = win32api.OpenProcess(win32con.PROCESS_TERMINATE, False, uPid); # pylint: disable=no-member 493 494 except: 494 495 pass; 495 496 else: 496 497 try: 497 win32process.TerminateProcess(hProcess, 0x40010004); # DBG_TERMINATE_PROCESS 498 win32process.TerminateProcess(hProcess, 0x40010004); # DBG_TERMINATE_PROCESS # pylint: disable=no-member 498 499 fRc = True; 499 500 except: 500 501 pass; 501 win32api.CloseHandle(hProcess) 502 win32api.CloseHandle(hProcess) # pylint: disable=no-member 502 503 else: 503 504 try: … … 546 547 fRc = False; 547 548 try: 548 hProcess = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, False, uPid); 549 hProcess = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, False, uPid); # pylint: disable=no-member 549 550 except: 550 551 pass; 551 552 else: 552 win32api.CloseHandle(hProcess) 553 win32api.CloseHandle(hProcess); # pylint: disable=no-member 553 554 fRc = True; 554 555 else: … … 888 889 # 889 890 891 # 892 # The following test case shows how time.time() only have ~ms resolution 893 # on Windows (tested W10) and why it therefore makes sense to try use 894 # performance counters. 895 # 896 # Note! We cannot use time.clock() as the timestamp must be portable across 897 # processes. See timeout testcase problem on win hosts (no logs). 898 # 899 #import sys; 900 #import time; 901 #from common import utils; 902 # 903 #atSeries = []; 904 #for i in xrange(1,160): 905 # if i == 159: time.sleep(10); 906 # atSeries.append((utils.timestampNano(), long(time.clock() * 1000000000), long(time.time() * 1000000000))); 907 # 908 #tPrev = atSeries[0] 909 #for tCur in atSeries: 910 # print 't1=%+22u, %u' % (tCur[0], tCur[0] - tPrev[0]); 911 # print 't2=%+22u, %u' % (tCur[1], tCur[1] - tPrev[1]); 912 # print 't3=%+22u, %u' % (tCur[2], tCur[2] - tPrev[2]); 913 # print ''; 914 # tPrev = tCur 915 # 916 #print 't1=%u' % (atSeries[-1][0] - atSeries[0][0]); 917 #print 't2=%u' % (atSeries[-1][1] - atSeries[0][1]); 918 #print 't3=%u' % (atSeries[-1][2] - atSeries[0][2]); 919 920 g_fWinUseWinPerfCounter = sys.platform == 'win32'; 921 g_fpWinPerfCounterFreq = None; 922 g_oFuncwinQueryPerformanceCounter = None; 923 924 def _winInitPerfCounter(): 925 """ Initializes the use of performance counters. """ 926 global g_fWinUseWinPerfCounter, g_fpWinPerfCounterFreq, g_oFuncwinQueryPerformanceCounter 927 928 uFrequency = ctypes.c_ulonglong(0); 929 if ctypes.windll.kernel32.QueryPerformanceFrequency(ctypes.byref(uFrequency)): 930 if uFrequency.value >= 1000: 931 print 'uFrequency = %s' % (uFrequency,); 932 print 'type(uFrequency) = %s' % (type(uFrequency),); 933 g_fpWinPerfCounterFreq = float(uFrequency.value); 934 935 # Check that querying the counter works too. 936 global g_oFuncwinQueryPerformanceCounter 937 g_oFuncwinQueryPerformanceCounter = ctypes.windll.kernel32.QueryPerformanceCounter; 938 uCurValue = ctypes.c_ulonglong(0); 939 if g_oFuncwinQueryPerformanceCounter(ctypes.byref(uCurValue)): 940 if uCurValue.value > 0: 941 return True; 942 g_fWinUseWinPerfCounter = False; 943 return False; 944 945 def _winFloatTime(): 946 """ Gets floating point time on windows. """ 947 if g_fpWinPerfCounterFreq is not None or _winInitPerfCounter(): 948 uCurValue = ctypes.c_ulonglong(0); 949 if g_oFuncwinQueryPerformanceCounter(ctypes.byref(uCurValue)): 950 return float(uCurValue.value) / g_fpWinPerfCounterFreq; 951 return time.time(); 952 953 890 954 def timestampNano(): 891 955 """ 892 956 Gets a nanosecond timestamp. 893 957 """ 894 if sys.platform == 'win32':895 return long( time.clock() * 1000000000);958 if g_fWinUseWinPerfCounter is True: 959 return long(_winFloatTime() * 1000000000); 896 960 return long(time.time() * 1000000000); 897 961 … … 900 964 Gets a millisecond timestamp. 901 965 """ 902 if sys.platform == 'win32':903 return long( time.clock() * 1000);966 if g_fWinUseWinPerfCounter is True: 967 return long(_winFloatTime() * 1000); 904 968 return long(time.time() * 1000); 905 969 … … 908 972 Gets a second timestamp. 909 973 """ 910 if sys.platform == 'win32':911 return long( time.clock());974 if g_fWinUseWinPerfCounter is True: 975 return long(_winFloatTime()); 912 976 return long(time.time()); 913 977 … … 1438 1502 """ 1439 1503 if platform.system() == 'Windows': 1440 import ctypes1441 1504 oCTypeFreeSpace = ctypes.c_ulonglong(0); 1442 1505 ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(sPath), None, None,
Note:
See TracChangeset
for help on using the changeset viewer.