Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
9.0 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. tracerpt.c
  5. Abstract:
  6. Event Trace Reporting Tool
  7. Author:
  8. 08-Apr-1998 Melur Raghuraman
  9. Revision History:
  10. --*/
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <tchar.h>
  14. #include "tracectr.h"
  15. #include "resource.h"
  16. #include "varg.c"
  17. #define GROUP_SRC 0x01
  18. VARG_DECLARE_COMMANDS
  19. VARG_DEBUG ( VARG_FLAG_OPTIONAL|VARG_FLAG_HIDDEN )
  20. VARG_HELP ( VARG_FLAG_OPTIONAL )
  21. VARG_MSZ ( IDS_PARAM_LOGFILE, VARG_FLAG_NOFLAG|VARG_FLAG_EXPANDFILES|VARG_FLAG_ARG_FILENAME, NULL )
  22. VARG_STR ( IDS_PARAM_DUMPFILE, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_DEFAULTABLE|VARG_FLAG_RCDEFAULT, IDS_DEFAULT_DUMP )
  23. VARG_STR ( IDS_PARAM_SUMMARY, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_DEFAULTABLE|VARG_FLAG_RCDEFAULT, IDS_DEFAULT_SUMMARY )
  24. VARG_STR ( IDS_PARAM_MOFFILE, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_HIDDEN|VARG_FLAG_DEFAULTABLE, NULL )
  25. VARG_STR ( IDS_PARAM_REPORTFILE, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_DEFAULTABLE|VARG_FLAG_RCDEFAULT, IDS_DEFAULT_REPORT )
  26. VARG_MSZ ( IDS_PARAM_LOGGERNAME, 0, NULL )
  27. VARG_INI ( IDS_PARAM_SETTINGS, VARG_FLAG_OPTIONAL, NULL )
  28. VARG_BOOL ( IDS_PARAM_EXFMT, VARG_FLAG_OPTIONAL|VARG_FLAG_HIDDEN, FALSE )
  29. VARG_STR ( IDS_PARAM_MERGE, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_DEFAULTABLE|VARG_FLAG_RCDEFAULT|VARG_FLAG_HIDDEN, IDS_DEFAULT_MERGED )
  30. VARG_STR ( IDS_PARAM_COMP, VARG_FLAG_OPTIONAL|VARG_FLAG_ARG_FILENAME|VARG_FLAG_HIDDEN|VARG_FLAG_RCDEFAULT|VARG_FLAG_DEFAULTABLE, IDS_DEFAULT_COMP )
  31. VARG_BOOL ( IDS_PARAM_YES, VARG_FLAG_OPTIONAL, FALSE )
  32. VARG_DECLARE_NAMES
  33. eDebug,
  34. eHelp,
  35. eLogFile,
  36. eDump,
  37. eSummary,
  38. eMofFile,
  39. eReport,
  40. eRealTime,
  41. eConfig,
  42. eExFormat,
  43. eMerge,
  44. eInterpret,
  45. eYes,
  46. VARG_DECLARE_FORMAT
  47. VARG_GROUP( eLogFile, VARG_EXCL(GROUP_SRC)|VARG_COND(GROUP_SRC) )
  48. VARG_GROUP( eRealTime, VARG_EXCL(GROUP_SRC)|VARG_COND(GROUP_SRC) )
  49. VARG_EXHELP( eDump, IDS_EXAMPLE_DUMPFILE)
  50. VARG_EXHELP( eSummary, IDS_EXAMPLE_SUMMARY )
  51. VARG_EXHELP( eRealTime, IDS_EXAMPLE_REALTIME)
  52. VARG_DECLARE_END
  53. #define MAXLOGFILES 32
  54. #define MAX_BUFFER_SIZE 1048576
  55. #define CHECK_HR( hr ) if( ERROR_SUCCESS != hr ){ goto cleanup; }
  56. int __cdecl _tmain (int argc, LPTSTR* argv)
  57. {
  58. LPTSTR* EvmFile = NULL; // List Of LogFiles To Process
  59. LPTSTR* Loggers = NULL; // List of Loggers to process
  60. ULONG LogFileCount = 0;
  61. ULONG LoggerCount = 0;
  62. TCHAR strEventDef[MAXSTR];
  63. TCHAR strDefinitionFile[MAXSTR] = _T("");
  64. DWORD dwCheckFileFlag = 0;
  65. HRESULT hr = ERROR_SUCCESS;
  66. TRACE_BASIC_INFO TraceBasicInfo;
  67. //
  68. // Parse the Command line arguments
  69. //
  70. ParseCmd( argc, argv );
  71. EvmFile = (LPTSTR*)VARG_ALLOC( GetMaxLoggers() * sizeof(LPTSTR) );
  72. if( NULL == EvmFile ){
  73. hr = ERROR_OUTOFMEMORY;
  74. goto cleanup;
  75. }
  76. Loggers = (LPTSTR*)VARG_ALLOC( GetMaxLoggers() * sizeof(LPTSTR) );
  77. if( NULL == Loggers ){
  78. hr = ERROR_OUTOFMEMORY;
  79. goto cleanup;
  80. }
  81. memset(&TraceBasicInfo, 0, sizeof(TRACE_BASIC_INFO));
  82. PrintMessage( g_normal, IDS_MESSAGE_INPUT );
  83. if( Commands[eRealTime].bDefined && Commands[eRealTime].strValue != NULL ) {
  84. LPTSTR strLogger = Commands[eRealTime].strValue;
  85. PrintMessage( g_normal, IDS_MESSAGE_LOGGERS );
  86. while( *strLogger != _T('\0') ){
  87. Loggers[LoggerCount] = strLogger;
  88. LoggerCount++;
  89. varg_printf( g_normal, _T(" %1!s!\n"), strLogger );
  90. strLogger += (_tcslen(strLogger)+1);
  91. }
  92. varg_printf( g_normal, _T("\n") );
  93. }
  94. if( Commands[eLogFile].bDefined && Commands[eLogFile].strValue != NULL ) {
  95. LPTSTR strLogger = Commands[eLogFile].strValue;
  96. PrintMessage( g_normal, IDS_MESSAGE_FILES );
  97. while( *strLogger != '\0' ){
  98. EvmFile[LogFileCount] = strLogger;
  99. LogFileCount++;
  100. hr = CheckFile(strLogger, VARG_CF_EXISTS);
  101. CHECK_HR( hr );
  102. varg_printf( g_normal, _T(" %1!s!\n"), strLogger );
  103. strLogger += (_tcslen(strLogger)+1);
  104. }
  105. varg_printf( g_normal, _T("\n") );
  106. }
  107. if( Commands[eMofFile].bDefined && Commands[eMofFile].strValue != NULL ) {
  108. TraceBasicInfo.MofFileName = Commands[eMofFile].strValue;
  109. _tcscpy( strEventDef, Commands[eMofFile].strValue );
  110. }else if( Commands[eMofFile].bDefined && Commands[eMofFile].strValue == NULL ){
  111. FILE* f;
  112. hr = GetTempName( strDefinitionFile, MAXSTR );
  113. CHECK_HR( hr );
  114. LoadString( NULL, IDS_MESSAGE_DFLTSRC, strEventDef, MAXSTR );
  115. TraceBasicInfo.MofFileName = strDefinitionFile;
  116. f = _tfopen( strDefinitionFile, _T("w") );
  117. if( f ){
  118. HRSRC hRes;
  119. HGLOBAL hResData;
  120. LPSTR buffer = NULL;
  121. hRes = FindResource( NULL, _T("MOFFILE"), RT_HTML );
  122. if( hRes != NULL ){
  123. hResData = LoadResource( NULL, hRes );
  124. buffer = (LPSTR)LockResource(hResData);
  125. if( buffer != NULL ){
  126. fprintf( f, "\n%s\n", buffer );
  127. }
  128. }
  129. fclose(f);
  130. }else{
  131. hr = GetLastError();
  132. goto cleanup;
  133. }
  134. }else{
  135. TraceBasicInfo.Flags |= TRACE_USE_WBEM;
  136. *strEventDef = _T('\0');
  137. }
  138. dwCheckFileFlag = Commands[eYes].bValue ? VARG_CF_OVERWRITE : (VARG_CF_PROMPT|VARG_CF_OVERWRITE);
  139. if( Commands[eMerge].bDefined ){
  140. TraceBasicInfo.Flags |= TRACE_MERGE_ETL;
  141. TraceBasicInfo.MergeFileName = Commands[eMerge].strValue;
  142. }else if ( _tcslen( strEventDef ) ){
  143. PrintMessage( g_normal, IDS_MESSAGE_DEFINE, strEventDef );
  144. }
  145. if( Commands[eInterpret].bDefined ) {
  146. TraceBasicInfo.Flags |= TRACE_INTERPRET;
  147. TraceBasicInfo.CompFileName = Commands[eInterpret].strValue;
  148. hr = CheckFile( Commands[eInterpret].strValue, dwCheckFileFlag );
  149. CHECK_HR(hr);
  150. }
  151. if( Commands[eReport].bDefined ) {
  152. TraceBasicInfo.Flags |= TRACE_REDUCE;
  153. TraceBasicInfo.ProcFileName = Commands[eReport].strValue;
  154. hr = CheckFile( Commands[eReport].strValue, dwCheckFileFlag );
  155. CHECK_HR(hr);
  156. }
  157. if( Commands[eExFormat].bValue ){
  158. TraceBasicInfo.Flags |= TRACE_EXTENDED_FMT;
  159. }
  160. if( Commands[eDump].bDefined ){
  161. TraceBasicInfo.Flags |= TRACE_DUMP;
  162. TraceBasicInfo.DumpFileName = Commands[eDump].strValue;
  163. hr = CheckFile( Commands[eDump].strValue, dwCheckFileFlag );
  164. CHECK_HR(hr);
  165. }
  166. if( Commands[eSummary].bDefined ) {
  167. TraceBasicInfo.Flags |= TRACE_SUMMARY;
  168. TraceBasicInfo.SummaryFileName = Commands[eSummary].strValue;
  169. hr = CheckFile( Commands[eSummary].strValue, dwCheckFileFlag );
  170. CHECK_HR(hr);
  171. }
  172. //
  173. // Make dump & summary the default
  174. //
  175. if( !(TraceBasicInfo.Flags & (TRACE_DUMP|TRACE_REDUCE|TRACE_MERGE_ETL|TRACE_SUMMARY) ) ) {
  176. TraceBasicInfo.Flags |= (TRACE_DUMP|TRACE_SUMMARY);
  177. TraceBasicInfo.DumpFileName = Commands[eDump].strValue;
  178. TraceBasicInfo.SummaryFileName = Commands[eSummary].strValue;
  179. hr = CheckFile( Commands[eDump].strValue, dwCheckFileFlag );
  180. CHECK_HR(hr);
  181. hr = CheckFile( Commands[eSummary].strValue, dwCheckFileFlag );
  182. CHECK_HR(hr);
  183. }
  184. TraceBasicInfo.LogFileName = EvmFile;
  185. TraceBasicInfo.LogFileCount = LogFileCount;
  186. TraceBasicInfo.LoggerName = Loggers;
  187. TraceBasicInfo.LoggerCount = LoggerCount;
  188. hr = InitTraceContext(&TraceBasicInfo);
  189. CHECK_HR( hr );
  190. PrintMessage( g_normal, IDS_MESSAGE_OUTPUT );
  191. if( TraceBasicInfo.Flags & TRACE_DUMP ){
  192. PrintMessage( g_normal, IDS_MESSAGE_CSVFILE, TraceBasicInfo.DumpFileName );
  193. }
  194. if( TraceBasicInfo.Flags & TRACE_SUMMARY ){
  195. PrintMessage( g_normal, IDS_MESSAGE_SUMMARY, TraceBasicInfo.SummaryFileName );
  196. }
  197. if( TraceBasicInfo.Flags & TRACE_REDUCE ){
  198. PrintMessage( g_normal, IDS_MESSAGE_REPORT, TraceBasicInfo.ProcFileName );
  199. }
  200. if( TraceBasicInfo.Flags & TRACE_MERGE_ETL ){
  201. PrintMessage( g_normal, IDS_MESSAGE_MERGED, TraceBasicInfo.MergeFileName );
  202. }
  203. if( TraceBasicInfo.Flags & TRACE_INTERPRET ){
  204. PrintMessage( g_normal, IDS_MESSAGE_COMP, TraceBasicInfo.CompFileName );
  205. }
  206. hr = DeinitTraceContext(&TraceBasicInfo);
  207. CHECK_HR( hr );
  208. cleanup:
  209. VARG_FREE( Loggers );
  210. VARG_FREE( EvmFile );
  211. if( _tcslen( strDefinitionFile ) ){
  212. DeleteFile( strDefinitionFile );
  213. }
  214. varg_printf( g_normal, _T("\n") );
  215. switch( hr ){
  216. case ERROR_SUCCESS:
  217. PrintMessage( g_normal, IDS_MESSAGE_SUCCESS );
  218. break;
  219. case ERROR_INVALID_HANDLE:
  220. PrintMessage( g_debug, IDS_MESSAGE_BADFILE );
  221. break;
  222. default:
  223. PrintError( hr );
  224. }
  225. return hr;
  226. }