initial import
authorJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 28 Aug 2007 05:17:14 +0000 (05:17 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 28 Aug 2007 05:17:14 +0000 (05:17 +0000)
src/utils/flactimer/flactimer.dsp [new file with mode: 0644]
src/utils/flactimer/flactimer.vcproj [new file with mode: 0644]
src/utils/flactimer/main.cpp [new file with mode: 0644]

diff --git a/src/utils/flactimer/flactimer.dsp b/src/utils/flactimer/flactimer.dsp
new file mode 100644 (file)
index 0000000..897d945
--- /dev/null
@@ -0,0 +1,100 @@
+# Microsoft Developer Studio Project File - Name="flactimer" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=flactimer - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "flactimer.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "flactimer.mak" CFG="flactimer - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "flactimer - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "flactimer - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "flactimer - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\..\obj\release\bin"\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c\r
+# ADD CPP /nologo /MD /W3 /GR /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c\r
+# SUBTRACT CPP /YX /Yc /Yu\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "flactimer - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "..\..\..\obj\debug\bin"\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /D "_DEBUG" /D "DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c\r
+# SUBTRACT CPP /YX /Yc /Yu\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "flactimer - Win32 Release"\r
+# Name "flactimer - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\main.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/src/utils/flactimer/flactimer.vcproj b/src/utils/flactimer/flactimer.vcproj
new file mode 100644 (file)
index 0000000..63603bb
--- /dev/null
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="flactimer"\r
+       ProjectGUID="{4cefbc94-c215-11db-8314-0800200c9a66}"\r
+       RootNamespace="flactimer"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="..\..\..\obj\debug\bin"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="."\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;DEBUG"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                               DisableSpecificWarnings="4267;4996"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               IgnoreDefaultLibraryNames="uuid.lib"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="..\..\..\obj\release\bin"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               EnableIntrinsicFunctions="true"\r
+                               FavorSizeOrSpeed="1"\r
+                               OmitFramePointers="true"\r
+                               WholeProgramOptimization="true"\r
+                               AdditionalIncludeDirectories="."\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               RuntimeLibrary="0"\r
+                               BufferSecurityCheck="false"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                               DisableSpecificWarnings="4267;4996"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               IgnoreDefaultLibraryNames="uuid.lib"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               LinkTimeCodeGeneration="1"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93993580-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+               </Filter>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4CF737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\main.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/src/utils/flactimer/main.cpp b/src/utils/flactimer/main.cpp
new file mode 100644 (file)
index 0000000..a8cd9ca
--- /dev/null
@@ -0,0 +1,171 @@
+/* flactimer - Runs a command and prints timing information
+ * Copyright (C) 2007  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <windows.h>
+
+#define int64_t __int64
+#define uint64_t unsigned int64_t
+
+static inline uint64_t time2nsec(const FILETIME &t)
+{
+       uint64_t n = t.dwHighDateTime;
+       n <<= 32;
+       n |= (uint64_t)t.dwLowDateTime;
+       return n * 100;
+}
+
+static void printtime(FILE *fout, uint64_t nsec, uint64_t total)
+{
+       unsigned pct = (unsigned)(100.0 * ((double)(int64_t)nsec / (double)(int64_t)total));
+       uint64_t msec = nsec / 1000000; nsec -= msec * 1000000;
+       uint64_t sec = msec / 1000; msec -= sec * 1000;
+       uint64_t min = sec / 60; sec -= min * 60;
+       uint64_t hour = min / 60; min -= hour * 60;
+       fprintf(fout, " %5u.%03u = %02u:%02u:%02u.%03u = %3u%%\n",
+               (unsigned)((hour*60+min)*60+sec),
+               (unsigned)msec,
+               (unsigned)hour,
+               (unsigned)min,
+               (unsigned)sec,
+               (unsigned)msec,
+               pct
+       );
+}
+
+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)
+                       strcat(args, " ");
+               strcat(args, argv[i]);
+       }
+
+       //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)) {
+               fprintf(fout, "ERROR getting time info\n");
+               free(args); //@@@ ok to free here or have to wait to wait till process is reaped?
+               fclose(fout);
+               return 1;
+       }
+       uint64_t kernel_nsec = time2nsec(kernel_time);
+       uint64_t user_nsec = time2nsec(user_time);
+
+       fprintf(fout, "Kernel Time  = "); printtime(fout, kernel_nsec, (uint64_t)wallclock_msec * 1000000);
+       fprintf(fout, "User Time    = "); printtime(fout, user_nsec, (uint64_t)wallclock_msec * 1000000);
+       fprintf(fout, "Process Time = "); printtime(fout, kernel_nsec+user_nsec, (uint64_t)wallclock_msec * 1000000);
+       fprintf(fout, "Global Time  = "); printtime(fout, (uint64_t)wallclock_msec * 1000000, (uint64_t)wallclock_msec * 1000000);
+
+       CloseHandle(pi.hThread);
+       CloseHandle(pi.hProcess);
+
+       free(args); //@@@ always causes crash, maybe CreateProcess takes ownership?
+       fclose(fout);
+       return 0;
+}