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.

119 lines
3.2 KiB

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <memory.h>
  5. #include <windows.h>
  6. int
  7. __cdecl main(
  8. int argc,
  9. char *argv[],
  10. char *envp[]
  11. )
  12. {
  13. LPSTR s;
  14. LPSTR CommandLine;
  15. STARTUPINFO StartupInfo;
  16. PROCESS_INFORMATION ProcessInformation;
  17. BOOL b;
  18. HANDLE MappingHandle;
  19. PVOID SharedMemory;
  20. argv;
  21. envp;
  22. if ( argc < 2 ) {
  23. puts("Usage: profile [/a] [/innn] [/k] name-of-image [parameters]...\n"
  24. " /a All hits\n"
  25. " /bnnn Set profile bucket size to 2 to the nnn bytes\n"
  26. " /ffilename Output to filename\n"
  27. " /innn Set profile interval to nnn (in 100ns units)\n"
  28. " /k profile system modules\n"
  29. " /s[profilesource] Use profilesource instead of clock interrupt\n"
  30. " /S[profilesource] Use profilesource as secondary profile source\n\n"
  31. #if defined (_ALPHA_)
  32. "Currently supported profile sources are 'align', 'totalissues', 'pipelinedry'\n"
  33. " 'loadinstructions', 'pipelinefrozen', 'branchinstructions', 'totalnonissues',\n"
  34. " 'dcachemisses', 'icachemisses', 'branchmispredicts', 'storeinstructions'\n"
  35. #endif
  36. );
  37. ExitProcess(1);
  38. }
  39. s = CommandLine = GetCommandLine();
  40. //
  41. // skip blanks
  42. //
  43. while(*s>' ')s++;
  44. //
  45. // get to next token
  46. //
  47. while(*s<=' ')s++;
  48. while ((*s == '-') ||
  49. (*s == '/')) {
  50. s++;
  51. while (*s>' '){
  52. s++;
  53. }
  54. //
  55. // get to next token
  56. //
  57. while(*s<=' ')s++;
  58. }
  59. //
  60. // Create named shared memory to pass parameters to psapi
  61. //
  62. MappingHandle = CreateFileMapping((HANDLE)-1,
  63. NULL,
  64. PAGE_READWRITE,
  65. 0,
  66. 4096,
  67. "ProfileStartupParameters");
  68. if (MappingHandle != NULL) {
  69. SharedMemory = MapViewOfFile(MappingHandle,
  70. FILE_MAP_WRITE,
  71. 0,
  72. 0,
  73. 0);
  74. if (SharedMemory) {
  75. //
  76. // Copy command line parameters into shared memory
  77. //
  78. strncpy(SharedMemory, CommandLine, (size_t)(s-CommandLine));
  79. UnmapViewOfFile(SharedMemory);
  80. }
  81. }
  82. memset(&StartupInfo,0,sizeof(StartupInfo));
  83. StartupInfo.cb = sizeof(StartupInfo);
  84. b = CreateProcess(
  85. NULL,
  86. s,
  87. NULL,
  88. NULL,
  89. TRUE,
  90. PROFILE_USER,
  91. NULL,
  92. NULL,
  93. &StartupInfo,
  94. &ProcessInformation
  95. );
  96. if ( !b ) {
  97. printf("CreateProcess(%s) failed %lx\n",s,GetLastError());
  98. ExitProcess(GetLastError());
  99. }
  100. WaitForSingleObject(ProcessInformation.hProcess, (DWORD)-1);
  101. if (MappingHandle) {
  102. if (SharedMemory) {
  103. UnmapViewOfFile(SharedMemory);
  104. }
  105. CloseHandle(MappingHandle);
  106. }
  107. return 0;
  108. }