#include "tcpu_exe.h" #include /********************************************************* ****************/ /* Input parameters - 1st parameter - how many times to repeat in the loop */ /* Subroutine simulating the process */ /* If you specify a NEGATIVE number, */ /* the process will be launched in a NEW console */ /* 2nd parameter - the full file name and parameters */ /* of the process being launched (command line to start the process) */ /* Autor Borue Sergey */ /*************************************************************************/ int main(int argc, char *argv[]) /*************************************************************************/ { int kmax; char proc[512]; int flag_consol=0; STARTUPINFO si; PROCESS_INFORMATION pi; //printf("argc=%d \n", argc); if (argc < 3 ) { printf("Error starting the meter...\nuse: %s times Process_file_name\n", argv[0]); printf("\n The utility measures the CPU time of the specified process.\n"); printf("Input parameters - 1st parameter - how many times to repeat the process in a loop\n"); printf(" ( If you specify a NEGATIVE number, the process will start in a NEW console.)\n"); printf("2nd parameter - the full file name of the process being launched\n"); printf(" (command line to start the process)\n"); return 4; }; sscanf(argv[1], "%d" , &kmax); if ( kmax < 0 ) { kmax=-kmax; flag_consol=CREATE_NEW_CONSOLE; }; proc[0]='\0'; for(int n=2; n < argc; n++ ) { //printf("%d %s\n", n, argv[n]); strcat(proc, argv[n]); strcat(proc, " "); }; printf("Repetition coefficient %d\n", kmax); printf("Process name %s\n\n", proc); __int64 sum_time; __int64 Tcpu, timeX; double temp; sys_time("Beginning of the experiment"); sum_time=0.0l; for(int k=1; k<=kmax; k++) { printf("Experiment ü %d\n", k); /************************************************************************/ ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) proc, //argv[1], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE flag_consol, //CREATE_NEW_CONSOLE, //0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "***** CreateProcess %s failed %d *****\n", proc, GetLastError() ); return 666; }; TimeCpu pti(pi.hProcess); // .hThread pti.StartTimer(); printf("##### process started.....waiting for completion...\n"); // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); pti.StopTimer(); Tcpu=pti.GetTime(); printf("##### the process has finished...\n"); sum_time+=Tcpu; temp=(double) round_msec(Tcpu) / 1000000l; //printf("Process ***** cpuTime = %10I64d (¢ 100 ­á)\n", Tcpu); printf("Process cpuTime = %10I64d microSec (%lf Sec)\n", round_msec(Tcpu), temp); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); // *** */ /************************************************************************/ }; sys_time("The experiment is complete"); timeX = round_msec(sum_time); temp = (double) timeX / 1000000l; printf("\nTotal processor time of all processors = %10I64d microSec (%lf Sec)\n", timeX, temp); timeX /= (__int64) kmax; temp = (double) timeX / 1000000l; printf("Average processor time of one processor = %10I64d microSec (%lf Sec)\n", timeX, temp); //sys_time("The experiment is complete"); return 0; }