本文整理汇总了C++中GetProcessTimes函数的典型用法代码示例。如果您正苦于以下问题:C++ GetProcessTimes函数的具体用法?C++ GetProcessTimes怎么用?C++ GetProcessTimes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetProcessTimes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_cpu_usage
void get_cpu_usage(double &user, double &system) {
struct _FILETIME creation_time, exit_time, kernel_time, user_time;
GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);
user = filetime_to_double(user_time);
system = filetime_to_double(kernel_time);
}
示例2: getrusage
int
getrusage (int who, struct rusage *usage_p)
{
if (who == RUSAGE_SELF || who == RUSAGE_CHILDREN)
{
/* Clear all unsupported members of 'struct rusage'. */
memset (usage_p, '\0', sizeof (struct rusage));
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
if (who == RUSAGE_SELF)
{
/* Fill in the ru_utime and ru_stime members. */
FILETIME creation_time;
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
if (GetProcessTimes (GetCurrentProcess (),
&creation_time, &exit_time,
&kernel_time, &user_time))
{
/* Convert to microseconds, rounding. */
uint64_t kernel_usec =
((((uint64_t) kernel_time.dwHighDateTime << 32)
| (uint64_t) kernel_time.dwLowDateTime)
+ 5) / 10;
uint64_t user_usec =
((((uint64_t) user_time.dwHighDateTime << 32)
| (uint64_t) user_time.dwLowDateTime)
+ 5) / 10;
usage_p->ru_utime.tv_sec = user_usec / 1000000U;
usage_p->ru_utime.tv_usec = user_usec % 1000000U;
usage_p->ru_stime.tv_sec = kernel_usec / 1000000U;
usage_p->ru_stime.tv_usec = kernel_usec % 1000000U;
}
}
#else
/* Fill in the ru_utime and ru_stime members. */
{
struct tms time;
if (times (&time) != (clock_t) -1)
{
/* Number of clock ticks per second. */
unsigned int clocks_per_second = sysconf (_SC_CLK_TCK);
if (clocks_per_second > 0)
{
clock_t user_ticks;
clock_t system_ticks;
uint64_t user_usec;
uint64_t system_usec;
if (who == RUSAGE_CHILDREN)
{
user_ticks = time.tms_cutime;
system_ticks = time.tms_cstime;
}
else
{
user_ticks = time.tms_utime;
system_ticks = time.tms_stime;
}
user_usec =
(((uint64_t) user_ticks * (uint64_t) 1000000U)
+ clocks_per_second / 2) / clocks_per_second;
system_usec =
(((uint64_t) system_ticks * (uint64_t) 1000000U)
+ clocks_per_second / 2) / clocks_per_second;
usage_p->ru_utime.tv_sec = user_usec / 1000000U;
usage_p->ru_utime.tv_usec = user_usec % 1000000U;
usage_p->ru_stime.tv_sec = system_usec / 1000000U;
usage_p->ru_stime.tv_usec = system_usec % 1000000U;
}
}
}
#endif
return 0;
}
else
{
errno = EINVAL;
return -1;
}
}
示例3: getrusage
/* This code works on:
* univel
* solaris_i386
* sco
* solaris_sparc
* svr4
* hpux 9.*
* win32
* which currently is all the supported platforms that don't have a
* native version of getrusage(). So, if configure decides to compile
* this file at all, we just use this version unconditionally.
*/
int
getrusage(int who, struct rusage * rusage)
{
#ifdef __WIN32__
FILETIME starttime;
FILETIME exittime;
FILETIME kerneltime;
FILETIME usertime;
ULARGE_INTEGER li;
if (who != RUSAGE_SELF)
{
/* Only RUSAGE_SELF is supported in this implementation for now */
errno = EINVAL;
return -1;
}
if (rusage == (struct rusage *) NULL)
{
errno = EFAULT;
return -1;
}
memset(rusage, 0, sizeof(struct rusage));
if (GetProcessTimes(GetCurrentProcess(),
&starttime, &exittime, &kerneltime, &usertime) == 0)
{
_dosmaperr(GetLastError());
return -1;
}
/* Convert FILETIMEs (0.1 us) to struct timeval */
memcpy(&li, &kerneltime, sizeof(FILETIME));
li.QuadPart /= 10L; /* Convert to microseconds */
rusage->ru_stime.tv_sec = li.QuadPart / 1000000L;
rusage->ru_stime.tv_usec = li.QuadPart % 1000000L;
memcpy(&li, &usertime, sizeof(FILETIME));
li.QuadPart /= 10L; /* Convert to microseconds */
rusage->ru_utime.tv_sec = li.QuadPart / 1000000L;
rusage->ru_utime.tv_usec = li.QuadPart % 1000000L;
#else /* all but __WIN32__ */
struct tms tms;
int tick_rate = CLK_TCK; /* ticks per second */
clock_t u, s;
if (rusage == (struct rusage *) NULL)
{
errno = EFAULT;
return -1;
}
if (times(&tms) < 0)
{
/* errno set by times */
return -1;
}
switch (who)
{
case RUSAGE_SELF:
u = tms.tms_utime;
s = tms.tms_stime;
break;
case RUSAGE_CHILDREN:
u = tms.tms_cutime;
s = tms.tms_cstime;
break;
default:
errno = EINVAL;
return -1;
}
#define TICK_TO_SEC(T, RATE) ((T)/(RATE))
#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE)
rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
#endif /* __WIN32__ */
return 0;
}
示例4: FastPoll
/* This is the fastpoll function which gathers up info by calling various api's */
BOOL FastPoll (void)
{
int nOriginalRandIndex = nRandIndex;
static BOOL addedFixedItems = FALSE;
FILETIME creationTime, exitTime, kernelTime, userTime;
DWORD minimumWorkingSetSize, maximumWorkingSetSize;
LARGE_INTEGER performanceCount;
MEMORYSTATUS memoryStatus;
HANDLE handle;
POINT point;
/* Get various basic pieces of system information */
RandaddInt32 (GetActiveWindow ()); /* Handle of active window */
RandaddInt32 (GetCapture ()); /* Handle of window with mouse
capture */
RandaddInt32 (GetClipboardOwner ()); /* Handle of clipboard owner */
RandaddInt32 (GetClipboardViewer ()); /* Handle of start of
clpbd.viewer list */
RandaddInt32 (GetCurrentProcess ()); /* Pseudohandle of current
process */
RandaddInt32 (GetCurrentProcessId ()); /* Current process ID */
RandaddInt32 (GetCurrentThread ()); /* Pseudohandle of current
thread */
RandaddInt32 (GetCurrentThreadId ()); /* Current thread ID */
RandaddInt32 (GetCurrentTime ()); /* Milliseconds since Windows
started */
RandaddInt32 (GetDesktopWindow ()); /* Handle of desktop window */
RandaddInt32 (GetFocus ()); /* Handle of window with kb.focus */
RandaddInt32 (GetInputState ()); /* Whether sys.queue has any events */
RandaddInt32 (GetMessagePos ()); /* Cursor pos.for last message */
RandaddInt32 (GetMessageTime ()); /* 1 ms time for last message */
RandaddInt32 (GetOpenClipboardWindow ()); /* Handle of window with
clpbd.open */
RandaddInt32 (GetProcessHeap ()); /* Handle of process heap */
RandaddInt32 (GetProcessWindowStation ()); /* Handle of procs
window station */
RandaddInt32 (GetQueueStatus (QS_ALLEVENTS)); /* Types of events in
input queue */
/* Get multiword system information */
GetCaretPos (&point); /* Current caret position */
RandaddBuf ((unsigned char *) &point, sizeof (POINT));
GetCursorPos (&point); /* Current mouse cursor position */
RandaddBuf ((unsigned char *) &point, sizeof (POINT));
/* Get percent of memory in use, bytes of physical memory, bytes of
free physical memory, bytes in paging file, free bytes in paging
file, user bytes of address space, and free user bytes */
memoryStatus.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus (&memoryStatus);
RandaddBuf ((unsigned char *) &memoryStatus, sizeof (MEMORYSTATUS));
/* Get thread and process creation time, exit time, time in kernel
mode, and time in user mode in 100ns intervals */
handle = GetCurrentThread ();
GetThreadTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime);
RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME));
handle = GetCurrentProcess ();
GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime);
RandaddBuf ((unsigned char *) &creationTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &exitTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &kernelTime, sizeof (FILETIME));
RandaddBuf ((unsigned char *) &userTime, sizeof (FILETIME));
/* Get the minimum and maximum working set size for the current
process */
GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
&maximumWorkingSetSize);
RandaddInt32 (minimumWorkingSetSize);
RandaddInt32 (maximumWorkingSetSize);
/* The following are fixed for the lifetime of the process so we only
add them once */
if (addedFixedItems == 0)
{
STARTUPINFO startupInfo;
/* Get name of desktop, console window title, new window
position and size, window flags, and handles for stdin,
stdout, and stderr */
startupInfo.cb = sizeof (STARTUPINFO);
GetStartupInfo (&startupInfo);
RandaddBuf ((unsigned char *) &startupInfo, sizeof (STARTUPINFO));
addedFixedItems = TRUE;
}
/* The docs say QPC can fail if appropriate hardware is not
available. It works on 486 & Pentium boxes, but hasn't been tested
for 386 or RISC boxes */
if (QueryPerformanceCounter (&performanceCount))
RandaddBuf ((unsigned char *) &performanceCount, sizeof (LARGE_INTEGER));
else
{
/* Millisecond accuracy at best... */
DWORD dwTicks = GetTickCount ();
RandaddBuf ((unsigned char *) &dwTicks, sizeof (dwTicks));
}
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[])
{
const char *usage = "usage: flactimer [-1 | -2 | -o outputfile] command\n";
FILE *fout = stderr;
if(argc == 1 || (argc > 1 && 0 == strcmp(argv[1], "-h"))) {
fprintf(stderr, usage);
return 0;
}
argv++;
argc--;
if(0 == strcmp(argv[0], "-1") || 0 == strcmp(argv[0], "/1")) {
fout = stdout;
argv++;
argc--;
}
else if(0 == strcmp(argv[0], "-2") || 0 == strcmp(argv[0], "/2")) {
fout = stdout;
argv++;
argc--;
}
else if(0 == strcmp(argv[0], "-o")) {
if(argc < 2) {
fprintf(stderr, usage);
return 1;
}
fout = fopen(argv[1], "w");
if(!fout) {
fprintf(fout, "ERROR opening file %s for writing\n", argv[1]);
return 1;
}
argv += 2;
argc -= 2;
}
if(argc <= 0) {
fprintf(fout, "ERROR, no command!\n\n");
fprintf(fout, usage);
fclose(fout);
return 1;
}
// improvement: double-quote all args
int i, n = 0;
for(i = 0; i < argc; i++) {
if(i > 0)
n++;
n += strlen(argv[i]);
}
char *args = (char*)malloc(n+1);
if(!args) {
fprintf(fout, "ERROR, no memory\n");
fclose(fout);
return 1;
}
args[0] = '\0';
for(i = 0; i < argc; i++) {
if(i > 0)
safe_strncat(args, " ", sizeof(args));
safe_strncat(args, argv[i], sizeof(args));
}
//fprintf(stderr, "@@@ cmd=[%s] args=[%s]\n", argv[0], args);
STARTUPINFO si;
GetStartupInfo(&si);
DWORD wallclock_msec = GetTickCount();
PROCESS_INFORMATION pi;
BOOL ok = CreateProcess(
argv[0], // lpApplicationName
args, // lpCommandLine
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
FALSE, // bInheritHandles
0, // dwCreationFlags
NULL, // lpEnvironment
NULL, // lpCurrentDirectory
&si, // lpStartupInfo (inherit from this proc?)
&pi // lpProcessInformation
);
if(!ok) {
fprintf(fout, "ERROR running command\n");
free(args); //@@@ ok to free here or have to wait to wait till process is reaped?
fclose(fout);
return 1;
}
//fprintf(stderr, "@@@ waiting...\n");
WaitForSingleObject(pi.hProcess, INFINITE);
//fprintf(stderr, "@@@ done\n");
wallclock_msec = GetTickCount() - wallclock_msec;
FILETIME creation_time;
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
if(!GetProcessTimes(pi.hProcess, &creation_time, &exit_time, &kernel_time, &user_time)) {
//.........这里部分代码省略.........
示例6: __po_hi_get_CPU_time
double __po_hi_get_CPU_time( )
{
#if defined(_WIN32)
/* Windows -------------------------------------------------- */
FILETIME createTime;
FILETIME exitTime;
FILETIME kernelTime;
FILETIME userTime;
if ( GetProcessTimes( GetCurrentProcess( ),
&createTime, &exitTime, &kernelTime, &userTime ) != -1 )
{
SYSTEMTIME userSystemTime;
if ( FileTimeToSystemTime( &userTime, &userSystemTime ) != -1 )
return (double)userSystemTime.wHour * 3600.0 +
(double)userSystemTime.wMinute * 60.0 +
(double)userSystemTime.wSecond +
(double)userSystemTime.wMilliseconds / 1000.0;
}
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
/* AIX, BSD, Cygwin, HP-UX, Linux, OSX, and Solaris --------- */
#if _POSIX_TIMERS > 0
/* Prefer high-res POSIX timers, when available. */
{
clockid_t id;
struct timespec ts;
#if _POSIX_CPUTIME > 0
/* Clock ids vary by OS. Query the id, if possible. */
if ( clock_getcpuclockid( 0, &id ) == -1 )
#endif
#if defined(CLOCK_PROCESS_CPUTIME_ID)
/* Use known clock id for AIX, Linux, or Solaris. */
id = CLOCK_PROCESS_CPUTIME_ID;
#elif defined(CLOCK_VIRTUAL)
/* Use known clock id for BSD or HP-UX. */
id = CLOCK_VIRTUAL;
#else
id = (clockid_t)-1;
#endif
if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 )
return (double)ts.tv_sec +
(double)ts.tv_nsec / 1000000000.0;
}
#endif
#if defined(RUSAGE_SELF)
{
struct rusage rusage;
if ( getrusage( RUSAGE_SELF, &rusage ) != -1 )
return (double)rusage.ru_utime.tv_sec +
(double)rusage.ru_utime.tv_usec / 1000000.0;
}
#endif
#if defined(_SC_CLK_TCK)
{
const double ticks = (double)sysconf( _SC_CLK_TCK );
struct tms tms;
if ( times( &tms ) != (clock_t)-1 )
return (double)tms.tms_utime / ticks;
}
#endif
#if defined(CLOCKS_PER_SEC)
{
clock_t cl = clock( );
if ( cl != (clock_t)-1 )
return (double)cl / (double)CLOCKS_PER_SEC;
}
#endif
#endif
return -1.0; /* Failed. */
}
示例7: OpenProcess
bool ErrorReport::GetMiscCrashInfo() {
// Get crash time
m_CrashDateTime = QDateTime::currentDateTime();
m_ProcessArchitecture = ARX_ARCH_NAME;
#ifdef HAVE_WINAPI
// Open parent process handle
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, m_pCrashInfo->processId);
if(hProcess != NULL)
{
// Get memory usage info
PROCESS_MEMORY_COUNTERS meminfo;
BOOL bGetMemInfo = GetProcessMemoryInfo(hProcess, &meminfo, sizeof(PROCESS_MEMORY_COUNTERS));
if(bGetMemInfo)
m_ProcessMemoryUsage = meminfo.WorkingSetSize;
// Determine the period of time the process is working.
FILETIME CreationTime, ExitTime, KernelTime, UserTime;
BOOL bGetTimes = GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime);
if(bGetTimes)
{
SYSTEMTIME AppStartTime;
FileTimeToSystemTime(&CreationTime, &AppStartTime);
SYSTEMTIME CurTime;
GetSystemTime(&CurTime);
ULONG64 uCurTime = ConvertSystemTimeToULONG64(CurTime);
ULONG64 uStartTime = ConvertSystemTimeToULONG64(AppStartTime);
// Check that the application works for at least one minute before crash.
// This might help to avoid cyclic error report generation when the applciation
// crashes on startup.
m_RunningTimeSec = (double)(uCurTime-uStartTime)*10E-08;
}
}
else
{
m_DetailedError = QString("Unable to obtain an handle to the crashed process (Error %1).").arg(QString::number(GetLastError()));
return false;
}
// Get operating system friendly name from registry.
char OSNameBuf[256];
if(!GetWindowsVersionName(OSNameBuf, 256))
{
m_DetailedError = QString("A failure occured when obtaining Windows version name (Error %1).").arg(QString::number(GetLastError()));
return false;
}
m_OSName = OSNameBuf;
// Determine if Windows is 64-bit.
m_OSArchitecture = Is64BitWindows() ? ARX_ARCH_NAME_X86_64 : ARX_ARCH_NAME_X86;
if(m_pCrashInfo->exceptionCode != 0)
{
QString exceptionStr = GetExceptionString(m_pCrashInfo->exceptionCode).c_str();
if(!exceptionStr.isEmpty())
{
m_ReportDescription += "\nException code:\n ";
m_ReportDescription += exceptionStr;
m_ReportDescription += "\n";
}
}
std::string callStack, callstackTop;
u32 callstackCrc;
bool bCallstack = GetCallStackInfo(hProcess, m_pCrashInfo->threadHandle, &m_pCrashInfo->contextRecord, callStack, callstackTop, callstackCrc);
if(!bCallstack)
{
m_DetailedError = "A failure occured when obtaining information regarding the callstack.";
return false;
}
m_ReportUniqueID = QString("[%1]").arg(QString::number(callstackCrc, 16).toUpper());
m_ReportDescription = m_pCrashInfo->detailedCrashInfo;
m_ReportDescription += "\nCallstack:\n";
m_ReportDescription += callStack.c_str();
m_ReportTitle = QString("%1 %2").arg(m_ReportUniqueID, callstackTop.c_str());
QString registers(GetRegisters(&m_pCrashInfo->contextRecord).c_str());
if(!registers.isEmpty())
{
m_ReportDescription += "\nRegisters:\n";
m_ReportDescription += registers;
}
CloseHandle(hProcess);
m_ReportDescriptionText = m_ReportDescription;
#else // !HAVE_WINAPI
getResourceUsage(m_pCrashInfo->processId, m_ProcessMemoryUsage, m_RunningTimeSec);
#ifdef HAVE_UNAME
//.........这里部分代码省略.........
示例8: process_time
int process_time(pid_t pid, time64_t* createTime, time64_t* kernelTime, time64_t* userTime)
{
#if defined(_WIN32)
HANDLE handle;
FILETIME ftCreateTime, ftExitTime, ftKernelTime, ftUserTime;
SYSTEMTIME stime;
FILETIME ftime;
ULONGLONG rt;
ULARGE_INTEGER kt, ut;
memset(&ftUserTime, 0xCC, sizeof(ftUserTime));
handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
if(!handle)
return (int)GetLastError();
if(!GetProcessTimes(handle, &ftCreateTime, &ftExitTime, &ftKernelTime, &ftUserTime))
{
CloseHandle(handle);
return (int)GetLastError();
}
CloseHandle(handle);
GetSystemTime(&stime);
SystemTimeToFileTime(&stime, &ftime);
kt = FILETIME2UINT64(&ftime);
ut = FILETIME2UINT64(&ftCreateTime);
rt = kt.QuadPart > ut.QuadPart ? kt.QuadPart-ut.QuadPart : 0; // for resolution problem
kt = FILETIME2UINT64(&ftKernelTime);
ut = FILETIME2UINT64(&ftUserTime);
*createTime = rt/10000; // nanosecond -> millisecond
*userTime = ut.QuadPart/10000;
*kernelTime = kt.QuadPart/10000;
return 0;
#else
char content[2*1024] = {0};
int r;
unsigned long int utime, stime;
unsigned long long starttime;
float uptime = 0.0f;
sprintf(content, "/proc/%d/stat", pid);
r = tools_cat(content, content, sizeof(content));
if(r < 0)
return r;
// linux: man proc
// cat proc/self/stat
// (1-pid-%d, 2-filename-%s, 3-state-%c, 4-ppid-%d, 5-pgrp-%d,
// 6-session-%d, 7-tty_nr-%d, 8-tpgid-%d, 9-flags-%u, 10-minflt-%lu,
// 11-cminflt-%lu, 12-majflt-%lu, 13-cmajflt-%lu, 14-utime-%lu, 15-stime-%lu,
// 16-cutime-%ld, 17-cstime-%ld, 18-priority-%ld, 19-nice-%ld, 20-num_threads-%ld,
// 21-itrealvalue-%ld, 22-starttime-%llu, 23-vsize-%lu, 24-rss-%ld, 25-rsslim-%lu,
// 26-startcode-%lu, 27-endcode-%lu, 28-startstack-%lu, 29-kstkesp-%lu, 30-kstkeip-%lu,
// 31-signal-%lu, 32-blocked-%lu, 33-sigignore-%lu, 34-sigcatch-%lu, 35-wchan-%lu,
// 36-nswap-%lu, 37-cnswap-%lu, 38-exit_signal-%d, 39-processor-%d, 40-rt_priority-%u,
// 41-policy-%u, 42-delayacct_blkio_ticks-%llu, 43-guest_time-%lu, 44-cguest_time-%ld)
if(3 != sscanf(content,
// warning: use of assignment suppression and length modifier together in gnu_scanf format [-Wformat]
//"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %lu %*ld %*ld %*ld %*ld %*ld %*ld %llu",
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu %*d %*d %*d %*d %*d %*d %llu",
&utime, &stime, &starttime))
return -(int)EINVAL;
assert(sysconf(_SC_CLK_TCK) == HZ);
system_uptime(&uptime);
*createTime = (time64_t)uptime*1000 - starttime*1000/HZ; // jiffies -> millisecond
*userTime = utime * 1000 / HZ;
*kernelTime = stime * 1000 / HZ;
return 0;
#endif
}
示例9: Exit
int InspIRCd::Run()
{
/* See if we're supposed to be running the test suite rather than entering the mainloop */
if (Config->cmdline.TestSuite)
{
TestSuite* ts = new TestSuite;
delete ts;
Exit(0);
}
UpdateTime();
time_t OLDTIME = TIME.tv_sec;
while (true)
{
#ifndef _WIN32
static rusage ru;
#endif
/* Check if there is a config thread which has finished executing but has not yet been freed */
if (this->ConfigThread && this->ConfigThread->IsDone())
{
/* Rehash has completed */
this->Logs->Log("CONFIG",LOG_DEBUG,"Detected ConfigThread exiting, tidying up...");
this->ConfigThread->Finish();
ConfigThread->join();
delete ConfigThread;
ConfigThread = NULL;
}
UpdateTime();
/* Run background module timers every few seconds
* (the docs say modules shouldnt rely on accurate
* timing using this event, so we dont have to
* time this exactly).
*/
if (TIME.tv_sec != OLDTIME)
{
#ifndef _WIN32
getrusage(RUSAGE_SELF, &ru);
stats->LastSampled = TIME;
stats->LastCPU = ru.ru_utime;
#else
if(QueryPerformanceCounter(&stats->LastSampled))
{
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
stats->LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
stats->LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
}
#endif
/* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */
if (TIME.tv_sec < OLDTIME - 2)
{
SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %lu secs.", (unsigned long)OLDTIME-TIME.tv_sec);
}
else if (TIME.tv_sec > OLDTIME + 2)
{
SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)TIME.tv_sec - OLDTIME);
}
OLDTIME = TIME.tv_sec;
if ((TIME.tv_sec % 3600) == 0)
{
Users->GarbageCollect();
FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
}
Timers->TickTimers(TIME.tv_sec);
this->DoBackgroundUserStuff();
if ((TIME.tv_sec % 5) == 0)
{
FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME.tv_sec));
SNO->FlushSnotices();
}
}
/* Call the socket engine to wait on the active
* file descriptors. The socket engine has everything's
* descriptors in its list... dns, modules, users,
* servers... so its nice and easy, just one call.
* This will cause any read or write events to be
* dispatched to their handlers.
*/
this->SE->DispatchTrialWrites();
this->SE->DispatchEvents();
/* if any users were quit, take them out */
GlobalCulls.Apply();
AtomicActions.Run();
//.........这里部分代码省略.........
示例10: _gcry_rndw32_gather_random_fast
void
_gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t,
enum random_origins),
enum random_origins origin)
{
static int addedFixedItems = 0;
if ( debug_me )
log_debug ("rndw32#gather_random_fast: ori=%d\n", origin );
/* Get various basic pieces of system information: Handle of active
window, handle of window with mouse capture, handle of clipboard
owner handle of start of clpboard viewer list, pseudohandle of
current process, current process ID, pseudohandle of current
thread, current thread ID, handle of desktop window, handle of
window with keyboard focus, whether system queue has any events,
cursor position for last message, 1 ms time for last message,
handle of window with clipboard open, handle of process heap,
handle of procs window station, types of events in input queue,
and milliseconds since Windows was started. */
{
byte buffer[20*sizeof(ulong)], *bufptr;
bufptr = buffer;
#define ADD(f) do { ulong along = (ulong)(f); \
memcpy (bufptr, &along, sizeof (along) ); \
bufptr += sizeof (along); \
} while (0)
ADD ( GetActiveWindow ());
ADD ( GetCapture ());
ADD ( GetClipboardOwner ());
ADD ( GetClipboardViewer ());
ADD ( GetCurrentProcess ());
ADD ( GetCurrentProcessId ());
ADD ( GetCurrentThread ());
ADD ( GetCurrentThreadId ());
ADD ( GetDesktopWindow ());
ADD ( GetFocus ());
ADD ( GetInputState ());
ADD ( GetMessagePos ());
ADD ( GetMessageTime ());
ADD ( GetOpenClipboardWindow ());
ADD ( GetProcessHeap ());
ADD ( GetProcessWindowStation ());
ADD ( GetQueueStatus (QS_ALLEVENTS));
ADD ( GetTickCount ());
gcry_assert ( bufptr-buffer < sizeof (buffer) );
(*add) ( buffer, bufptr-buffer, origin );
#undef ADD
}
/* Get multiword system information: Current caret position, current
mouse cursor position. */
{
POINT point;
GetCaretPos (&point);
(*add) ( &point, sizeof (point), origin );
GetCursorPos (&point);
(*add) ( &point, sizeof (point), origin );
}
/* Get percent of memory in use, bytes of physical memory, bytes of
free physical memory, bytes in paging file, free bytes in paging
file, user bytes of address space, and free user bytes. */
{
MEMORYSTATUS memoryStatus;
memoryStatus.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus (&memoryStatus);
(*add) ( &memoryStatus, sizeof (memoryStatus), origin );
}
/* Get thread and process creation time, exit time, time in kernel
mode, and time in user mode in 100ns intervals. */
{
HANDLE handle;
FILETIME creationTime, exitTime, kernelTime, userTime;
DWORD minimumWorkingSetSize, maximumWorkingSetSize;
handle = GetCurrentThread ();
GetThreadTimes (handle, &creationTime, &exitTime,
&kernelTime, &userTime);
(*add) ( &creationTime, sizeof (creationTime), origin );
(*add) ( &exitTime, sizeof (exitTime), origin );
(*add) ( &kernelTime, sizeof (kernelTime), origin );
(*add) ( &userTime, sizeof (userTime), origin );
handle = GetCurrentProcess ();
GetProcessTimes (handle, &creationTime, &exitTime,
&kernelTime, &userTime);
(*add) ( &creationTime, sizeof (creationTime), origin );
(*add) ( &exitTime, sizeof (exitTime), origin );
(*add) ( &kernelTime, sizeof (kernelTime), origin );
(*add) ( &userTime, sizeof (userTime), origin );
/* Get the minimum and maximum working set size for the current
//.........这里部分代码省略.........
示例11: UpdateTime
void InspIRCd::Run()
{
#ifdef INSPIRCD_ENABLE_TESTSUITE
/* See if we're supposed to be running the test suite rather than entering the mainloop */
if (do_testsuite)
{
TestSuite* ts = new TestSuite;
delete ts;
return;
}
#endif
UpdateTime();
time_t OLDTIME = TIME.tv_sec;
while (true)
{
#ifndef _WIN32
static rusage ru;
#endif
/* Check if there is a config thread which has finished executing but has not yet been freed */
if (this->ConfigThread && this->ConfigThread->IsDone())
{
/* Rehash has completed */
this->Logs.Log("CONFIG", LOG_DEBUG, "Detected ConfigThread exiting, tidying up...");
this->ConfigThread->Finish();
ConfigThread->join();
delete ConfigThread;
ConfigThread = NULL;
}
UpdateTime();
/* Run background module timers every few seconds
* (the docs say modules shouldnt rely on accurate
* timing using this event, so we dont have to
* time this exactly).
*/
if (TIME.tv_sec != OLDTIME)
{
#ifndef _WIN32
getrusage(RUSAGE_SELF, &ru);
stats.LastSampled = TIME;
stats.LastCPU = ru.ru_utime;
#else
if(QueryPerformanceCounter(&stats.LastSampled))
{
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
stats.LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
stats.LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
}
#endif
if (Config->TimeSkipWarn)
{
time_t timediff = TIME.tv_sec - OLDTIME;
if (timediff > Config->TimeSkipWarn)
SNO.WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped forwards by %lu seconds!", timediff);
else if (timediff < -Config->TimeSkipWarn)
SNO.WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped backwards by %lu seconds!", labs(timediff));
}
OLDTIME = TIME.tv_sec;
if ((TIME.tv_sec % 3600) == 0)
{
FOREACH_MOD(OnGarbageCollect, ());
// HACK: ELines are not expired properly at the moment but it can't be fixed as
// the 2.0 XLine system is a spaghetti nightmare. Instead we skip over expired
// ELines in XLineManager::CheckELines() and expire them here instead.
XLines->GetAll("E");
}
Timers.TickTimers(TIME.tv_sec);
Users.DoBackgroundUserStuff();
if ((TIME.tv_sec % 5) == 0)
{
FOREACH_MOD(OnBackgroundTimer, (TIME.tv_sec));
SNO.FlushSnotices();
}
}
示例12: gpt
__int64 gpt() {
FILETIME a,b,c,d;
GetProcessTimes(GetCurrentProcess(), &a,&b,&c,&d);
return *(__int64*)&d;
}
示例13: FillRunTimeLog
/*
* FillRunTimeLog fill the global Result array with runtime timing parameters.
*
* Accepts:
* -------
* hProcess - handle to the process.
* test_id - test id.
*/
void FillRunTimeLog(HANDLE hProcess,int test_id)
{
SYSTEMTIME UTC_Time, LocalTime;
FILETIME CreationTime, ExitTime, KernelTime, UserTime, TotalTime;
int time_in_ms,kernel_time,user_time;
int len1,len2,len3,len4;
char test_id_str[MAX_INT_TO_STRING];
char time_in_ms_str[MAX_INT_TO_STRING];
char kernel_time_str[MAX_INT_TO_STRING];
char user_time_str[MAX_INT_TO_STRING];
char start_time_str[HH_MM_SS_MMM];
GetProcessTimes(
hProcess,
&CreationTime,
&ExitTime,
&KernelTime,
&UserTime
);
itoa(test_id,test_id_str,10);
len1 = strlen(test_id_str);
FileTimeToSystemTime(&CreationTime, /* input */
&UTC_Time);
SystemTimeToTzSpecificLocalTime(NULL, /* use default time zone */
&UTC_Time, /* input */
&LocalTime); /* output */
sprintf(start_time_str,"%02d:%02d:%02d:%02d",LocalTime.wHour,LocalTime.wMinute, LocalTime.wSecond,LocalTime.wMilliseconds);
TotalTime = SubtractFiletimes(ExitTime, CreationTime);
time_in_ms = TotalTime.dwLowDateTime / FILETIME_UNITS_PER_MILLISECOND;
itoa(time_in_ms,time_in_ms_str,10);
len2 = strlen(time_in_ms_str);
FileTimeToSystemTime(&TotalTime, /* input */
&UTC_Time); /* output */
if ((KernelTime.dwHighDateTime == 0) &&
(UserTime.dwHighDateTime == 0))
{
kernel_time = KernelTime.dwLowDateTime / FILETIME_UNITS_PER_MILLISECOND;
itoa(kernel_time,kernel_time_str,10);
len3 = strlen(kernel_time_str);
user_time = UserTime.dwLowDateTime / FILETIME_UNITS_PER_MILLISECOND;
itoa(user_time,user_time_str,10);
len4 = strlen(user_time_str);
}
else
{
printf("This function can only print the Kernel Time and User Time "
"if they are small enough to be held in a single DWORD each. "
"That is not true, so they will not be printed. ");
}
shared_result[test_id-1].runtime_log_line = (char*)malloc(sizeof(char)*(HH_MM_SS_MMM + LOG_RUNTIME_LINE + len1 + len2 + len3 + len4) + 1);
if(shared_result[test_id-1].runtime_log_line == NULL)
{
printf("Failed to allocate memory for FillRunTimeLog function \n");
exit(1);
}
sprintf(shared_result[test_id-1].runtime_log_line,"Test #%s : start_time=%s total_time=%s user_time=%s kernel_time=%s",test_id_str,start_time_str,time_in_ms_str,user_time_str,kernel_time_str);
shared_result[test_id-1].result_id = test_id;
}
示例14: hb_secondsCPU
double hb_secondsCPU( int n )
{
double d = 0.0;
#if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_UNIX )
FILETIME Create, Exit, Kernel, User;
#endif
#if defined( HB_OS_OS2 )
static ULONG s_timer_interval = 0;
QSGREC ** pBuf;
#endif
if( ( n < 1 || n > 3 ) && ( n < 11 || n > 13 ) )
n = 3;
#if defined( HB_OS_UNIX ) && ! defined( HB_OS_VXWORKS )
{
struct tms tm;
times( &tm );
if( n > 10 )
{
n -= 10;
if( n & 1 )
d += tm.tms_cutime;
if( n & 2 )
d += tm.tms_cstime;
}
if( n & 1 )
d += tm.tms_utime;
if( n & 2 )
d += tm.tms_stime;
/* In POSIX-1996 the CLK_TCK symbol is mentioned as obsolescent */
#if 0
d /= CLK_TCK;
#endif
d /= ( double ) sysconf( _SC_CLK_TCK );
}
#else
if( n > 10 )
n -= 10;
#if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE )
if( hb_iswinnt() &&
GetProcessTimes( GetCurrentProcess(), &Create, &Exit, &Kernel, &User ) )
{
if( n & 1 )
{
d += ( double ) ( ( ( HB_MAXINT ) User.dwHighDateTime << 32 ) +
( HB_MAXINT ) User.dwLowDateTime );
}
if( n & 2 )
{
d += ( double ) ( ( ( HB_MAXINT ) Kernel.dwHighDateTime << 32 ) +
( HB_MAXINT ) Kernel.dwLowDateTime );
}
d /= 10000000.0;
}
else
#elif defined( HB_OS_OS2 )
if( s_timer_interval == 0 )
DosQuerySysInfo( QSV_TIMER_INTERVAL, QSV_TIMER_INTERVAL, ( PVOID ) &s_timer_interval, sizeof( ULONG ) );
pBuf = ( QSGREC ** ) hb_xalloc( BUFSIZE );
if( pBuf )
{
#if defined( __GNUC__ )
APIRET rc = DosQuerySysState( QS_PROCESS, 0L, _getpid(), 0L, pBuf, BUFSIZE );
#else
APIRET rc = DosQuerySysState( QS_PROCESS, 0L, getpid(), 0L, pBuf, BUFSIZE );
#endif
if( rc == NO_ERROR )
{
QSGREC * pGrec = *pBuf;
QSPREC * pPrec = ( QSPREC * ) ( ( ULONG ) pGrec + sizeof( QSGREC ) );
QSTREC * pTrec = pPrec->pThrdRec;
int i;
for( i = 0; i < pPrec->cTCB; i++, pTrec++ )
{
if( n & 1 )
d += pTrec->usertime;
if( n & 2 )
d += pTrec->systime;
}
d = d * 10.0 / s_timer_interval;
}
hb_xfree( pBuf );
}
else
//.........这里部分代码省略.........
示例15: dtime_
double
dtime_ (real tarray[2])
{
#if defined (_WIN32)
static int win32_platform = -1;
if (win32_platform == -1)
{
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof (osv);
GetVersionEx (&osv);
win32_platform = osv.dwPlatformId;
}
/* We need to use this hack on non-NT platforms, where the first call
returns 0.0 and subsequent ones return the correct value. */
if (win32_platform != VER_PLATFORM_WIN32_NT)
{
static unsigned long long clock_freq;
static unsigned long long old_count;
unsigned long long count;
double delta;
LARGE_INTEGER counter_val;
if (clock_freq == 0)
{
LARGE_INTEGER freq;
if (!QueryPerformanceFrequency (&freq))
{
errno = ENOSYS;
return 0.0;
}
else
{
clock_freq = ((unsigned long long) freq.HighPart << 32)
+ ((unsigned) freq.LowPart);
}
}
if (!QueryPerformanceCounter (&counter_val))
return -1.0;
count = ((unsigned long long) counter_val.HighPart << 32)
+ (unsigned) counter_val.LowPart;
delta = ((double) (count - old_count)) / clock_freq;
tarray[0] = (float) delta;
tarray[1] = 0.0;
old_count = count;
}
else
{
static unsigned long long old_utime, old_stime;
unsigned long long utime, stime;
FILETIME creation_time, exit_time, kernel_time, user_time;
GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time,
&kernel_time, &user_time);
utime = ((unsigned long long) user_time.dwHighDateTime << 32)
+ (unsigned) user_time.dwLowDateTime;
stime = ((unsigned long long) kernel_time.dwHighDateTime << 32)
+ (unsigned) kernel_time.dwLowDateTime;
tarray[0] = (utime - old_utime) / 1.0e7;
tarray[1] = (stime - old_stime) / 1.0e7;
old_utime = utime;
old_stime = stime;
}
return tarray[0] + tarray[1];
#elif defined (HAVE_GETRUSAGE) || defined (HAVE_TIMES)
/* The getrusage version is only the default for convenience. */
#ifdef HAVE_GETRUSAGE
float utime, stime;
static float old_utime = 0.0, old_stime = 0.0;
struct rusage rbuff;
if (getrusage (RUSAGE_SELF, &rbuff) != 0)
abort ();
utime = (float) (rbuff.ru_utime).tv_sec +
(float) (rbuff.ru_utime).tv_usec / 1000000.0;
tarray[0] = utime - (float) old_utime;
stime = (float) (rbuff.ru_stime).tv_sec +
(float) (rbuff.ru_stime).tv_usec / 1000000.0;
tarray[1] = stime - old_stime;
#else /* HAVE_GETRUSAGE */
/* For dtime, etime we store the clock tick parameter (clk_tck) the
first time either of them is invoked rather than each time. This
approach probably speeds up each invocation by avoiding a system
call each time, but means that the overhead of the first call is
different to all others. */
static long clk_tck = 0;
time_t utime, stime;
static time_t old_utime = 0, old_stime = 0;
struct tms buffer;
/* NeXTStep seems to define _SC_CLK_TCK but not to have sysconf;
fixme: does using _POSIX_VERSION help? */
# if defined _SC_CLK_TCK && defined _POSIX_VERSION
if (!clk_tck)
clk_tck = sysconf (_SC_CLK_TCK);
//.........这里部分代码省略.........