您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ GetProcessTimes函数代码示例

51自学网 2021-06-01 21:13:37
  C++
这篇教程C++ GetProcessTimes函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中GetProcessTimes函数的典型用法代码示例。如果您正苦于以下问题:C++ GetProcessTimes函数的具体用法?C++ GetProcessTimes怎么用?C++ GetProcessTimes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了GetProcessTimes函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);}
开发者ID:CMU-CREATE-Lab,项目名称:timemachine-creator,代码行数:6,


示例2: getrusage

intgetrusage (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;    }}
开发者ID:ajnelson,项目名称:gnulib,代码行数:90,


示例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. */intgetrusage(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;}
开发者ID:Coshibu,项目名称:darktable,代码行数:93,


示例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));	}//.........这里部分代码省略.........
开发者ID:AntiRootkit,项目名称:TrueCrypt-7.1a,代码行数:101,


示例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)) {//.........这里部分代码省略.........
开发者ID:griha41,项目名称:PortAMP,代码行数:101,


示例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. */}
开发者ID:maxIsae,项目名称:polyorb-hi-c,代码行数:76,


示例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//.........这里部分代码省略.........
开发者ID:DaveMachine,项目名称:ArxLibertatis,代码行数:101,


示例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}
开发者ID:azalpy,项目名称:sdk,代码行数:75,


示例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();//.........这里部分代码省略.........
开发者ID:H7-25,项目名称:inspircd,代码行数:101,


示例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//.........这里部分代码省略.........
开发者ID:Greenchik,项目名称:libgcrypt,代码行数:101,


示例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();			}		}
开发者ID:aszrul,项目名称:inspircd,代码行数:92,


示例12: gpt

__int64 gpt() {	FILETIME a,b,c,d;	GetProcessTimes(GetCurrentProcess(), &a,&b,&c,&d);	return *(__int64*)&d;}
开发者ID:lmadhavan,项目名称:fotografix,代码行数:5,


示例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;	}
开发者ID:JeniaBR,项目名称:EX2,代码行数:80,


示例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//.........这里部分代码省略.........
开发者ID:alcz,项目名称:harbour,代码行数:101,


示例15: dtime_

doubledtime_ (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);//.........这里部分代码省略.........
开发者ID:manojxantony,项目名称:compiler,代码行数:101,


示例16: clock_gettime

extern "C" int clock_gettime(clockid_t clock_id, struct timespec* tp) {  if (!tp) {    errno = EFAULT;    return -1;  }  const auto unanosToTimespec = [](timespec* tp, unsigned_nanos t) -> int {    static constexpr unsigned_nanos one_sec(std::chrono::seconds(1));    tp->tv_sec =        time_t(std::chrono::duration_cast<std::chrono::seconds>(t).count());    tp->tv_nsec = long((t % one_sec).count());    return 0;  };  FILETIME createTime, exitTime, kernalTime, userTime;  switch (clock_id) {    case CLOCK_REALTIME: {      auto now = std::chrono::system_clock::now().time_since_epoch();      duration_to_ts(now, tp);      return 0;    }    case CLOCK_MONOTONIC: {      auto now = std::chrono::steady_clock::now().time_since_epoch();      duration_to_ts(now, tp);      return 0;    }    case CLOCK_PROCESS_CPUTIME_ID: {      if (!GetProcessTimes(              GetCurrentProcess(),              &createTime,              &exitTime,              &kernalTime,              &userTime)) {        errno = EINVAL;        return -1;      }      return unanosToTimespec(          tp,          filetimeToUnsignedNanos(kernalTime) +              filetimeToUnsignedNanos(userTime));    }    case CLOCK_THREAD_CPUTIME_ID: {      if (!GetThreadTimes(              GetCurrentThread(),              &createTime,              &exitTime,              &kernalTime,              &userTime)) {        errno = EINVAL;        return -1;      }      return unanosToTimespec(          tp,          filetimeToUnsignedNanos(kernalTime) +              filetimeToUnsignedNanos(userTime));    }    default:      errno = EINVAL;      return -1;  }}
开发者ID:charsyam,项目名称:folly,代码行数:64,


示例17: GetProcessorNumber

int ProcessWatch::GetProcessCpuUsage(int pid){  	static int processor_count_ = -1;	static __int64 last_time_ = 0;	static __int64 last_system_time_ = 0;	FILETIME now;	FILETIME creation_time;	FILETIME exit_time;	FILETIME kernel_time;	FILETIME user_time;	__int64 system_time;	__int64 time;	// 	__int64 system_time_delta;	// 	__int64 time_delta;	double cpu = -1;	if(processor_count_ == -1)	{		processor_count_ = GetProcessorNumber();	}	GetSystemTimeAsFileTime(&now);	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION/*PROCESS_ALL_ACCESS*/, false, pid);	if (!hProcess)	{		return -1;	}	if (!GetProcessTimes(hProcess, &creation_time, &exit_time, &kernel_time, &user_time))	{		return -1;	}	system_time = (FileTimeToInt64(kernel_time) + FileTimeToInt64(user_time)) / processor_count_;  	time = FileTimeToInt64(now);			last_system_time_ = system_time;	last_time_ = time;	CloseHandle( hProcess );	Sleep(30);	hProcess = OpenProcess(PROCESS_QUERY_INFORMATION/*PROCESS_ALL_ACCESS*/, false, pid);	if (!hProcess)	{		return -1;	}	if (!GetProcessTimes(hProcess, &creation_time, &exit_time, &kernel_time, &user_time))	{		return -1;	}	GetSystemTimeAsFileTime(&now);	system_time = (FileTimeToInt64(kernel_time) + FileTimeToInt64(user_time)) / processor_count_; 	time = FileTimeToInt64(now);			CloseHandle( hProcess );	cpu = ((double)(system_time - last_system_time_) / (double)(time - last_time_)) * 100;	return (int)cpu;}
开发者ID:yellowbigbird,项目名称:bird-self-lib,代码行数:61,


示例18: IS_REMOTE

//.........这里部分代码省略.........				results.push_back("249 "+user->nick+" :Swaps:            "+ConvToStr(R.ru_nswap));				results.push_back("249 "+user->nick+" :Context Switches: Voluntary; "+ConvToStr(R.ru_nvcsw)+" Involuntary; "+ConvToStr(R.ru_nivcsw));				char percent[30];				float n_elapsed = (ServerInstance->Time() - ServerInstance->stats->LastSampled.tv_sec) * 1000000					+ (ServerInstance->Time_ns() - ServerInstance->stats->LastSampled.tv_nsec) / 1000;				float n_eaten = ((R.ru_utime.tv_sec - ServerInstance->stats->LastCPU.tv_sec) * 1000000 + R.ru_utime.tv_usec - ServerInstance->stats->LastCPU.tv_usec);				float per = (n_eaten / n_elapsed) * 100;				snprintf(percent, 30, "%03.5f%%", per);				results.push_back("249 "+user->nick+" :CPU Use (now):    "+percent);				n_elapsed = ServerInstance->Time() - ServerInstance->startup_time;				n_eaten = (float)R.ru_utime.tv_sec + R.ru_utime.tv_usec / 100000.0;				per = (n_eaten / n_elapsed) * 100;				snprintf(percent, 30, "%03.5f%%", per);				results.push_back("249 "+user->nick+" :CPU Use (total):  "+percent);			}#else			PROCESS_MEMORY_COUNTERS MemCounters;			if (GetProcessMemoryInfo(GetCurrentProcess(), &MemCounters, sizeof(MemCounters)))			{				results.push_back("249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K");				results.push_back("249 "+user->nick+" :Pagefile usage:   "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K");				results.push_back("249 "+user->nick+" :Page faults:      "+ConvToStr(MemCounters.PageFaultCount));			}			FILETIME CreationTime;			FILETIME ExitTime;			FILETIME KernelTime;			FILETIME UserTime;			LARGE_INTEGER ThisSample;			if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) &&				QueryPerformanceCounter(&ThisSample))			{				KernelTime.dwHighDateTime += UserTime.dwHighDateTime;				KernelTime.dwLowDateTime += UserTime.dwLowDateTime;				double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;				double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;				double per = (n_eaten/n_elapsed);				char percent[30];				snprintf(percent, 30, "%03.5f%%", per);				results.push_back("249 "+user->nick+" :CPU Use (now):    "+percent);				n_elapsed = ServerInstance->Time() - ServerInstance->startup_time;				n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000;				per = (n_eaten / n_elapsed);				snprintf(percent, 30, "%03.5f%%", per);				results.push_back("249 "+user->nick+" :CPU Use (total):  "+percent);			}#endif		}		break;		case 'T':		{			results.push_back("249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused));			results.push_back("249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown));			results.push_back("249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions));			results.push_back("249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad));			results.push_back("249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects));			results.push_back(InspIRCd::Format("249 %s :bytes sent %5.2fK recv %5.2fK", user->nick.c_str(),				ServerInstance->stats->statsSent / 1024.0, ServerInstance->stats->statsRecv / 1024.0));
开发者ID:danparsons,项目名称:inspircd,代码行数:67,


示例19: KillProcessTreeWinHelper

//---------------------------------------------------------------------------// KillProcessTreeWinHelper////  Terminates all the processes started by the specified process and then//  terminates the process itself. When determining which processes were//  started by the specified process, the following criteria are taken into//  consideration://  - The PPID of the process//  - The creation time of the process////  Because Windows processes do not reparent (changing their PPID when their//  real parent process terminates before they do), the PPID of a process is//  not enough to safely kill a hierarchy. PID reuse can result in a process//  appearing to be the parent of processes it didn't actually start. To try//  and guard against this, the creation time (start time) for the process to//  terminate is compared to the creation time of any process that appears to//  be in its hierarchy. If the creation time of the child is before that of//  its parent, it is assumed that the parent "inherited" the child and did//  not actually start it. Such "inherited" children are not killed.////  Parameters://	  dwProcessId - identifier of the process to terminate////  Returns://	  Win32 error code.//DWORD WINAPI KillProcessTreeWinHelper(DWORD dwProcessId) {	// first, open a handle to the process with sufficient access to query for	// its times. those are needed in order to filter "children" because Windows	// processes, unlike Unix/Linux processes, do not reparent when the process	// that created them exits. as a result, any process could reuse a PID and	// end up looking like it spawned many processes it didn't actually spawn	auto_handle hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);	if (!hProcess) {		return GetLastError();	}	// note: processCreated will be retained as the creation time for the root	// process. the other variables only exist because GetProcessTimes requires	// all 4 pointers	FILETIME processCreated;	FILETIME exitTime;   // unused	FILETIME kernelTime; // unused	FILETIME userTime;   // unused	if (!GetProcessTimes(hProcess, &processCreated, &exitTime, &kernelTime, &userTime)) {		// if unable to check the creation time for the process, it is impossible		// to safely kill any children processes; just kill the root process and		// leave it at that		return KillProcess(dwProcessId);	}	// next, create a snapshot of all the running processes. this will be used	// build a graph of processes which:	// 1. have a parent related to the root process	// 2. were started after the root process	auto_handle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);	if (!hSnapshot) {		// if unable to open a snapshot of the currently-running processes, just		// kill the root process and leave it at that		return KillProcess(dwProcessId);	}	PROCESSENTRY32 pEntry;	pEntry.dwSize = sizeof(PROCESSENTRY32);	HANDLE hHeap = GetProcessHeap();	if (!hHeap) {		return KillProcess(dwProcessId);	}	PTREE_PROCESS root = (PTREE_PROCESS) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(TREE_PROCESS));	if (!root) {		// couldn't allocate memory for the TREE_PROCESS, which means we won't be able		// to build the list; just kill the root process and leave it at that		return KillProcess(dwProcessId);	}	root->processId = dwProcessId;	PTREE_PROCESS current = root;	PTREE_PROCESS last = root;	FILETIME creationTime; // used when getting a child's creation time	DWORD processId;       // holds the ID of the process being processed	while (current) {		// extract the process ID for processing, but do not move the current pointer;		// since children have not been processed yet, current->next may not have been		// set at this time. move it after the loop instead		processId = current->processId;		if (!Process32First(hSnapshot, &pEntry)) {			return FreeProcessList(hHeap, root);		}		// find the children for the current process		do {			DWORD pid = pEntry.th32ProcessID;			DWORD ppid = pEntry.th32ParentProcessID;			// first checks are the simplest; we can perform them with the data from			// the PROCESSENTRY32 structure://.........这里部分代码省略.........
开发者ID:fabioz,项目名称:winp,代码行数:101,


示例20: main

int main(int argc, char** argv){#if !defined(_WIN32) && !defined(_WIN64)    printf("Only Windows OS is supported./n");#else    if(argc < 3)    {        printf("usage: %s <dir> <command>/n", argv[0]);        return -1;    }    char path[512];    sprintf_s(path, 511, "%s//%s.pid", argv[1], argv[2]);    DWORD pid = 0;    FILE* f = NULL;    fopen_s(&f, path, "r");    if(!f)    {        fprintf(stderr, "Can't open file %s/n", path);    }    else    {           char* pidbuf[32];        int numread = fread(pidbuf, sizeof(char), 31, f);        if(numread > 0)        {            pidbuf[numread] = '/0';            pid = atoi((const char*)pidbuf);        }    }    if(pid > 0)    {        printf("ProcessID: %d/n", pid);        HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);        if(h <= 0)        {            fprintf(stderr, "Process %d can't be opened./n", pid);            printf("ProcessUpTime: /n");        }        else        {            //Process elapsed time.            BIGTIME CreateTime, ExitTime, ElapsedTime, Now;            FILETIME KernelTime, UserTime;            GetProcessTimes(h, &CreateTime.ft, &ExitTime.ft, &KernelTime, &UserTime);            if(ExitTime.li > CreateTime.li)                ElapsedTime.li = ExitTime.li - CreateTime.li;            else            {                GetSystemTimeAsFileTime(&Now.ft);                ElapsedTime.li = Now.li - CreateTime.li;            }            unsigned elapsedsecs = (unsigned)(ElapsedTime.li/10000000);            TSpan span(elapsedsecs);            printf("ProcessUpTime: %d-%02d:%02d:%02d/n", span.d, span.h, span.m, span.s);        }    }    else    {        printf("ProcessID: /nProcessUpTime: /n");    }    //CPU usage    BIGTIME idle1, kernel1, user1, idle2, kernel2, user2;    GetSystemTimes(&idle1.ft, &kernel1.ft, &user1.ft);    Sleep(1000);    GetSystemTimes(&idle2.ft, &kernel2.ft, &user2.ft);    int IdleTime = (int)(idle2.li - idle1.li);    int TotalTime = (int)((kernel2.li + user2.li) - (kernel1.li + user1.li));    int idleRate = (int)(100.0 * IdleTime / TotalTime);    printf("CPU-Idle: %d%%/n", idleRate);    //Computer uptime    LARGE_INTEGER ticks, unit;    QueryPerformanceCounter(&ticks);    QueryPerformanceFrequency(&unit);    int secs = (int)(ticks.QuadPart/unit.QuadPart);    TSpan u((int)secs);    printf("ComputerUpTime: %d days, %d:%d/n", u.d, u.h, u.m);    printf("---SpaceUsedAndFree---/n");    //Physical and virtual memory usage.    MEMORYSTATUS memstatus;    GlobalMemoryStatus(&memstatus);    printf("Physical Memory: %d %d/nVirtual Memory: %d %d/n",         (memstatus.dwTotalPhys - memstatus.dwAvailPhys)/1024, memstatus.dwAvailPhys/1024,        (memstatus.dwTotalVirtual - memstatus.dwAvailVirtual)/1024, memstatus.dwAvailVirtual/1024);    // Disk Usage    char        drivePath[] = "?://";    char        driveName;    for( driveName = 'A'; driveName <= 'Z'; driveName++ )     {        drivePath[0] = driveName;        int dtype = GetDriveTypeA(drivePath);        if(dtype == DRIVE_FIXED || dtype == DRIVE_RAMDISK || dtype == DRIVE_REMOVABLE || dtype == DRIVE_CDROM)         {            ULARGE_INTEGER diskAvailStruct;//.........这里部分代码省略.........
开发者ID:AlexLuya,项目名称:HPCC-Platform,代码行数:101,


示例21: 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			/* 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(OnGarbageCollect, ());			}			Timers.TickTimers(TIME.tv_sec);			Users->DoBackgroundUserStuff();			if ((TIME.tv_sec % 5) == 0)			{				FOREACH_MOD(OnBackgroundTimer, (TIME.tv_sec));				SNO->FlushSnotices();			}		}
开发者ID:WindowsUser,项目名称:inspircd,代码行数:87,


示例22: GetCurrentProcess

/*	The following block is copied from the Java source code. It documents the counters array.	 * @param counters the results are returned in this array.	 * <ol>	 * <li>working set in bytes for this process	 * <li>peak working set in bytes for this process	 * <li>elapsed time in milliseconds	 * <li>user time in milliseconds	 * <li>kernel time in milliseconds	 * <li>page faults for the process	 * <li>commit charge total in bytes (working set for the entire machine). On some 	 * machines we have problems getting this value so we return -1 in that case.	 * <li>number of GDI objects in the process	 * <li>number of USER objects in the process	 * <li>number of open handles in the process. returns -1 if this information is not available	 * <li>Number of read operations	 * <li>Number of write operations	 * <li>Number of bytes read	 * <li>Number of bytes written	 * </ol>*/JNIEXPORT jboolean JNICALL Java_org_eclipse_perfmsr_core_PerformanceMonitor_nativeGetPerformanceCounters  (JNIEnv * jniEnv, jclass jniClass, jlongArray counters){	FILETIME creationTime, exitTime, kernelTime, userTime, systemTime;	ULARGE_INTEGER uliCreation, uliSystem, uliKernel, uliUser;	ULONGLONG diff;	IO_COUNTERS ioCounters;	jboolean result = TRUE;	jsize len = (*jniEnv)->GetArrayLength(jniEnv, counters);	jlong *body = (*jniEnv)->GetLongArrayElements(jniEnv, counters, 0);	HANDLE me = GetCurrentProcess();	PROCESS_MEMORY_COUNTERS memCounters;	DWORD cb = sizeof(PROCESS_MEMORY_COUNTERS);	BOOL rc = GetProcessMemoryInfo(me, &memCounters, cb);	if (rc != 0)	{		body[0] = memCounters.WorkingSetSize;		body[1] = memCounters.PeakWorkingSetSize;		body[5] = memCounters.PageFaultCount;	}	else	{		handleSystemError(jniEnv);		return FALSE;	}	if (!GetProcessTimes(me, &creationTime, &exitTime, &kernelTime, &userTime))	{		handleSystemError(jniEnv);		return FALSE;	}	GetSystemTimeAsFileTime(&systemTime);	memcpy(&uliCreation, &creationTime, sizeof(uliCreation));  	memcpy(&uliSystem, &systemTime, sizeof(uliSystem));	memcpy(&uliKernel, &kernelTime, sizeof(uliSystem));	memcpy(&uliUser, &userTime, sizeof(ULARGE_INTEGER));	diff = uliSystem.QuadPart - uliCreation.QuadPart;	body[2] = diff / 10000;	body[3] = uliUser.QuadPart / 10000;	body[4] = uliKernel.QuadPart / 10000;	body[6] = getTotalCommitted(jniEnv);	body[7] = GetGuiResources(me, GR_GDIOBJECTS);	body[8] = GetGuiResources(me, GR_USEROBJECTS);	body[9] = getHandleCount(jniEnv, me);	if (!GetProcessIoCounters(me, &ioCounters))	{		handleSystemError(jniEnv);		return FALSE;	}	body[10] = ioCounters.ReadOperationCount;	body[11] = ioCounters.WriteOperationCount;	body[12] = ioCounters.ReadTransferCount;	body[13] = ioCounters.WriteTransferCount;	(*jniEnv)->ReleaseLongArrayElements(jniEnv, counters, body, 0);	return result;}
开发者ID:Overruler,项目名称:eclipse.platform.releng,代码行数:85,


示例23: GetProcessAttribute

static int	GetProcessAttribute(HANDLE hProcess,int attr,int type,int count,double *lastValue){   double value;   PROCESS_MEMORY_COUNTERS mc;   IO_COUNTERS ioCounters;   FILETIME ftCreate,ftExit,ftKernel,ftUser;   /* Get value for current process instance */   switch(attr)   {      case 0:        /* vmsize */         GetProcessMemoryInfo(hProcess,&mc,sizeof(PROCESS_MEMORY_COUNTERS));         value=(double)mc.PagefileUsage/1024;   /* Convert to Kbytes */         break;      case 1:        /* wkset */         GetProcessMemoryInfo(hProcess,&mc,sizeof(PROCESS_MEMORY_COUNTERS));         value=(double)mc.WorkingSetSize/1024;   /* Convert to Kbytes */         break;      case 2:        /* pf */         GetProcessMemoryInfo(hProcess,&mc,sizeof(PROCESS_MEMORY_COUNTERS));         value=(double)mc.PageFaultCount;         break;      case 3:        /* ktime */      case 4:        /* utime */         GetProcessTimes(hProcess,&ftCreate,&ftExit,&ftKernel,&ftUser);         value = ConvertProcessTime(attr==3 ? &ftKernel : &ftUser);         break;      case 5:        /* gdiobj */      case 6:        /* userobj */         if(NULL == zbx_GetGuiResources)	     return SYSINFO_RET_FAIL;         value = (double)zbx_GetGuiResources(hProcess,attr==5 ? 0 : 1);         break;      case 7:        /* io_read_b */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.ReadTransferCount);         break;      case 8:        /* io_read_op */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.ReadOperationCount);         break;      case 9:        /* io_write_b */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.WriteTransferCount);         break;      case 10:       /* io_write_op */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.WriteOperationCount);         break;      case 11:       /* io_other_b */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.OtherTransferCount);         break;      case 12:       /* io_other_op */         if(NULL == zbx_GetProcessIoCounters)	     return SYSINFO_RET_FAIL;         zbx_GetProcessIoCounters(hProcess,&ioCounters);         value=(double)((__int64)ioCounters.OtherOperationCount);         break;      default:       /* Unknown attribute */         return SYSINFO_RET_FAIL;   }	/* Recalculate final value according to selected type */	switch (type) {	case 0:	/* min */		if (count == 0 || value < *lastValue)			*lastValue = value;		break;	case 1:	/* max */		if (count == 0 || value > *lastValue)			*lastValue = value;		break;	case 2:	/* avg */		*lastValue = (*lastValue * count + value) / (count + 1);		break;	case 3:	/* sum */		*lastValue += value;		break;	default://.........这里部分代码省略.........
开发者ID:aries4,项目名称:MIRACLE-ZBX-2.0.3-NoSQL,代码行数:101,


示例24: main

int __cdecl main( int argc, char **argv ) {    int i, j, k;    int *total;        HANDLE hProcess;        FILETIME createTime;    FILETIME exitTime;    FILETIME kernelTime1;    FILETIME userTime1;    FILETIME kernelTime2;    FILETIME userTime2;    DWORD dwError;        /* initialize the PAL */    if( PAL_Initialize(argc, argv) != 0 )    {	    return( FAIL );    }    /* get our own process handle */    hProcess = GetCurrentProcess();    if( hProcess == NULL )    {        Fail(   "GetCurrentProcess() returned a NULL handle./n" );    }        /* zero our time structures */    ZeroMemory( &createTime, sizeof(createTime) );    ZeroMemory( &exitTime, sizeof(exitTime) );    ZeroMemory( &kernelTime1, sizeof(kernelTime1) );    ZeroMemory( &userTime1, sizeof(userTime1) );    ZeroMemory( &kernelTime2, sizeof(kernelTime2) );    ZeroMemory( &userTime2, sizeof(userTime2) );    /* check the process times for the child process */    if( ! GetProcessTimes(  hProcess,                            &createTime,                            &exitTime,                            &kernelTime1,                            &userTime1 ) )    {        dwError = GetLastError();        Fail( "GetProcessTimes() call failed with error code %d/n",              dwError );     }    /* simulate some activity */    for( i=0; i<1000; i++ )    {        for( j=0; j<1000; j++ )        {            /* do kernel work to increase system usage counters */            total = malloc(1024 * 1024);            *total = j * i;            for( k=0; k<1000; k++ )            {                *total += k + i;            }            free(total);        }    }    /* check the process times for the child process */    if( ! GetProcessTimes(  hProcess,                            &createTime,                            &exitTime,                            &kernelTime2,                            &userTime2 ) )    {        dwError = GetLastError();        Fail( "GetProcessTimes() call failed with error code %d/n",              dwError );     }    /* very simple logical checking of the results */    if( CompareFileTime( &kernelTime1, &kernelTime2 ) > 0 )    {        Fail( "Unexpected kernel time value reported./n" );    }        if( CompareFileTime( &userTime1, &userTime2 ) > 0 )    {        Fail( "Unexpected user time value reported./n" );    }            /* terminate the PAL */    PAL_Terminate();        /* return success */    return PASS; }
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:99,


示例25: _process_id

process::process(DWORD pid) : _process_id(pid){	// NT API Support:	//   5.0  GetModuleFileNameEx	//   5.1  GetProcessImageFileName	//   5.0  GetProcessTimes	//   5.0  GetTokenInformation	//   5.0  LookupAccountSid	//   5.0  OpenProcess	//   5.0  OpenProcessToken	//   6.0  QueryFullProcessImageName#if _WIN32_WINNT < 0x0600	//HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);#else	//HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);#endif	HANDLE hProcess = OpenProcess(MAXIMUM_ALLOWED, FALSE, pid);	if (NULL != hProcess) {		FILETIME ctime = { 0, 0 };		FILETIME etime = { 0, 0 };		FILETIME ktime = { 0, 0 };		FILETIME utime = { 0, 0 };		if (GetProcessTimes(hProcess, &ctime, &etime, &ktime, &utime)) {			_creation_time = ctime;		} else {			std::tcerr << std::dec << pid << ": GetProcessTimes failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;		}#if _WIN32_WINNT < 0x0600		std::tstring image(MAX_PATH, '/0');		// This needs PROCESS_VM_READ.		DWORD image_length = GetModuleFileNameEx(hProcess, NULL, &image[0], image.size());		if (image_length > 0) {			image.resize(image_length);		} else {			std::tcerr << std::dec << pid << ": GetModuleFileNameEx failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;		}#else		std::tstring image(MAX_PATH, '/0');		DWORD image_length = image.size();		// This needs PROCESS_QUERY_LIMITED_INFORMATION.		if (QueryFullProcessImageName(hProcess, 0, &image[0], &image_length)) {			image.resize(image_length);		} else {			std::tcerr << std::dec << pid << ": QueryFullProcessImageName failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;		}#endif		_image_filepath.assign(image);		std::tstring::size_type last_slash = _image_filepath.rfind('//'); 		if (last_slash != std::tstring::npos) {			_image_filename = _image_filepath.substr(++last_slash, _image_filepath.size());		}		HANDLE hProcessToken;		if (OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken)) {			DWORD data_length = 0;			if (!GetTokenInformation(hProcessToken, TokenUser, NULL, 0, &data_length) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {				void* data = new byte[data_length];				if (GetTokenInformation(hProcessToken, TokenUser, data, data_length, &data_length)) {					TOKEN_USER* user = static_cast<TOKEN_USER*>(data);					std::tstring name(MAX_NAME, '/0');					DWORD name_length = name.size();					std::tstring domain(MAX_NAME, '/0');					DWORD domain_length = domain.size();					SID_NAME_USE type;					if (LookupAccountSid(NULL, user->User.Sid, &name[0], &name_length, &domain[0], &domain_length, &type)) {						name.resize(name_length);						domain.resize(domain_length);						_username = _T("");						if (domain.size()) {							_username += domain;							_username += _T("//");						}						_username += name;					} else {						std::tcerr << std::dec << pid << ": LookupAccountSid failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;					}				} else {					std::tcerr << std::dec << pid << ": GetTokenInformation(2) failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;				}				delete data;			} else {				std::tcerr << std::dec << pid << ": GetTokenInformation failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;			}			CloseHandle(hProcessToken);		} else {			std::tcerr << std::dec << pid << ": OpenProcessToken failed: " << std::hex << std::setw(8) << std::setfill(_T('0')) << GetLastError() << std::endl;		}		CloseHandle(hProcess);	}}
开发者ID:ISergey256,项目名称:vmmap,代码行数:93,


示例26: py_process_time

static PyObject*py_process_time(_Py_clock_info_t *info){#if defined(MS_WINDOWS)    HANDLE process;    FILETIME creation_time, exit_time, kernel_time, user_time;    ULARGE_INTEGER large;    double total;    BOOL ok;    process = GetCurrentProcess();    ok = GetProcessTimes(process, &creation_time, &exit_time, &kernel_time, &user_time);    if (!ok)        return PyErr_SetFromWindowsErr(0);    large.u.LowPart = kernel_time.dwLowDateTime;    large.u.HighPart = kernel_time.dwHighDateTime;    total = (double)large.QuadPart;    large.u.LowPart = user_time.dwLowDateTime;    large.u.HighPart = user_time.dwHighDateTime;    total += (double)large.QuadPart;    if (info) {        info->implementation = "GetProcessTimes()";        info->resolution = 1e-7;        info->monotonic = 1;        info->adjustable = 0;    }    return PyFloat_FromDouble(total * 1e-7);#else#if defined(HAVE_SYS_RESOURCE_H)    struct rusage ru;#endif#ifdef HAVE_TIMES    struct tms t;    static long ticks_per_second = -1;#endif#if defined(HAVE_CLOCK_GETTIME) /    && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF))    struct timespec tp;#ifdef CLOCK_PROF    const clockid_t clk_id = CLOCK_PROF;    const char *function = "clock_gettime(CLOCK_PROF)";#else    const clockid_t clk_id = CLOCK_PROCESS_CPUTIME_ID;    const char *function = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)";#endif    if (clock_gettime(clk_id, &tp) == 0) {        if (info) {            struct timespec res;            info->implementation = function;            info->monotonic = 1;            info->adjustable = 0;            if (clock_getres(clk_id, &res) == 0)                info->resolution = res.tv_sec + res.tv_nsec * 1e-9;            else                info->resolution = 1e-9;        }        return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9);    }#endif#if defined(HAVE_SYS_RESOURCE_H)    if (getrusage(RUSAGE_SELF, &ru) == 0) {        double total;        total = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * 1e-6;        total += ru.ru_stime.tv_sec + ru.ru_stime.tv_usec * 1e-6;        if (info) {            info->implementation = "getrusage(RUSAGE_SELF)";            info->monotonic = 1;            info->adjustable = 0;            info->resolution = 1e-6;        }        return PyFloat_FromDouble(total);    }#endif#ifdef HAVE_TIMES    if (times(&t) != (clock_t)-1) {        double total;        if (ticks_per_second == -1) {#if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)            ticks_per_second = sysconf(_SC_CLK_TCK);            if (ticks_per_second < 1)                ticks_per_second = -1;#elif defined(HZ)            ticks_per_second = HZ;#else            ticks_per_second = 60; /* magic fallback value; may be bogus */#endif        }        if (ticks_per_second != -1) {            total = (double)t.tms_utime / ticks_per_second;            total += (double)t.tms_stime / ticks_per_second;            if (info) {                info->implementation = "times()";//.........这里部分代码省略.........
开发者ID:krallin,项目名称:cpython,代码行数:101,


示例27: GetProcessTimes

u64 OS::cpuTime( void ) noexcept{  FILETIME ct, et, kt, ut;  GetProcessTimes( GetCurrentProcess(), &ct, &et, &kt, &ut );  return ( u64( ut.dwHighDateTime ) << 32 ) + ut.dwLowDateTime +    ( u64( kt.dwHighDateTime ) << 32 ) + kt.dwLowDateTime;}
开发者ID:BanditCat,项目名称:LNZ,代码行数:6,


示例28: switch

		Chrono::Chrono(Type type)		{#ifdef __linux__			switch (type)			{			case Type::REAL_TIME:				m_clockId = CLOCK_MONOTONIC_RAW;				break;			case Type::PROCESS_TIME:				m_clockId = CLOCK_PROCESS_CPUTIME_ID;				break;			case Type::THREAD_TIME:				m_clockId = CLOCK_THREAD_CPUTIME_ID;				break;			}			timespec now = {};			if (clock_gettime(m_clockId, &now))			{				m_clockId = CLOCK_MONOTONIC;				if (clock_gettime(m_clockId, &now))				{					m_clockId = CLOCK_REALTIME;					if (clock_gettime(m_clockId, &now))					{						m_clockId = -1;						m_timestamp = 0;						return;					}				}			}			m_timestamp = now.tv_sec * 1000000000 + now.tv_nsec;#elif defined(_WIN32)			m_type = type;			switch (m_type)			{			case Type::REAL_TIME:				if (QueryPerformanceFrequency(&m_counterFreq))				{					LARGE_INTEGER counter;					if (QueryPerformanceCounter(&counter))					{						m_timestamp = counter.QuadPart;						return;					}				}				break;			case Type::PROCESS_TIME:				{					FILETIME time[4];					if (GetProcessTimes(GetCurrentProcess(), time, time + 1, time + 2, time + 3))					{						m_timestamp = static_cast<long long>(time[2].dwHighDateTime) << 32 | time[2].dwLowDateTime;						m_timestamp += static_cast<long long>(time[3].dwHighDateTime) << 32 | time[3].dwLowDateTime;						return;					}				}				break;			case Type::THREAD_TIME:				{					FILETIME time[4];					if (GetThreadTimes(GetCurrentThread(), time, time + 1, time + 2, time + 3))					{						m_timestamp = static_cast<long long>(time[2].dwHighDateTime) << 32 | time[2].dwLowDateTime;						m_timestamp += static_cast<long long>(time[3].dwHighDateTime) << 32 | time[3].dwLowDateTime;						return;					}				}				break;			}			m_counterFreq.QuadPart = 0;			m_timestamp = 0;#endif //__linux__		}
开发者ID:neodesys,项目名称:EasyTest,代码行数:82,



注:本文中的GetProcessTimes函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ GetProfile函数代码示例
C++ GetProcessId函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。