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.

335 lines
9.1 KiB

  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include "perfmon.h"
  5. #include "utils.h"
  6. #include "log.h"
  7. #include "pmemory.h" // for MemoryXXX (malloc-like) routines
  8. #include "perfdata.h"
  9. #include "perfmops.h"
  10. #include "system.h" // for SystemGet
  11. #include "playback.h" // for PlayingBackLog & DataFromIndexPosition
  12. #include "pmhelpid.h" // Help IDs
  13. //==========================================================================//
  14. // External Data //
  15. //==========================================================================//
  16. extern HWND hWndLogEntries ;
  17. BOOL ComputerChange ;
  18. static PPERFDATA pPerfData ;
  19. //==========================================================================//
  20. // Local Functions //
  21. //==========================================================================//
  22. BOOL
  23. /* static */
  24. LogComputerChanged (
  25. HDLG hDlg
  26. )
  27. {
  28. PLOG pLog ;
  29. HWND hWndObjects ;
  30. PPERFSYSTEM pSysInfo;
  31. DWORD iObjectType ;
  32. DWORD iObjectNum ;
  33. pLog = LogData (hDlg) ;
  34. hWndObjects = DialogControl (hDlg, IDD_ADDLOGOBJECT) ;
  35. if (!pPerfData) {
  36. LBReset (hWndObjects) ;
  37. return FALSE ;
  38. }
  39. SetHourglassCursor() ;
  40. pSysInfo = GetComputer (hDlg,
  41. IDD_ADDLOGCOMPUTER,
  42. TRUE,
  43. &pPerfData,
  44. &pLog->pSystemFirst) ;
  45. if (!pPerfData || !pSysInfo) {
  46. LBReset (hWndObjects) ;
  47. SetArrowCursor() ;
  48. return FALSE ;
  49. } else {
  50. LBLoadObjects (hWndObjects,
  51. pPerfData,
  52. pSysInfo,
  53. pLog->dwDetailLevel,
  54. NULL,
  55. FALSE) ;
  56. iObjectNum = (DWORD) LBNumItems (hWndObjects) ;
  57. for (iObjectType = 0 ;
  58. iObjectType < iObjectNum ;
  59. iObjectType++) { // for
  60. LBSetSelection (hWndObjects, iObjectType) ;
  61. } // for
  62. }
  63. ComputerChange = FALSE ;
  64. SetArrowCursor() ;
  65. return TRUE ;
  66. }
  67. void
  68. /*static*/
  69. OnLogDestroy (
  70. HDLG hDlg
  71. )
  72. {
  73. dwCurrentDlgID = 0 ;
  74. if (!PlayingBackLog ())
  75. MemoryFree ((LPMEMORY)pPerfData) ;
  76. bAddLineInProgress = FALSE ;
  77. }
  78. //==========================================================================//
  79. // Message Handlers //
  80. //==========================================================================//
  81. void
  82. /* static */
  83. OnInitAddLogDialog (
  84. HDLG hDlg
  85. )
  86. {
  87. TCHAR szRemoteComputerName[MAX_PATH + 3] ;
  88. INT_PTR iIndex ;
  89. PLOGENTRY pLogEntry ;
  90. LPTSTR pComputerName ;
  91. bAddLineInProgress = TRUE ;
  92. if (PlayingBackLog()) {
  93. pPerfData = DataFromIndexPosition (&(PlaybackLog.StartIndexPos), NULL) ;
  94. GetPerfComputerName(pPerfData, szRemoteComputerName);
  95. DialogSetString (hDlg, IDD_ADDLOGCOMPUTER, szRemoteComputerName);
  96. } else {
  97. pPerfData = MemoryAllocate (STARTING_SYSINFO_SIZE) ;
  98. //Try to use computer specified on command line (if any), otherwise local computer
  99. pComputerName = CmdLineComputerName[0] ?
  100. CmdLineComputerName :
  101. LocalComputerName ;
  102. iIndex = LBSelection (hWndLogEntries) ;
  103. if (iIndex != LB_ERR) {
  104. pLogEntry = (PLOGENTRY) LBData(hWndLogEntries, iIndex) ;
  105. if (pLogEntry && pLogEntry != (PLOGENTRY)LB_ERR) {
  106. pComputerName = pLogEntry->szComputer ;
  107. }
  108. }
  109. DialogSetString (hDlg, IDD_ADDLOGCOMPUTER, pComputerName) ;
  110. }
  111. LogComputerChanged (hDlg) ;
  112. DialogEnable (hDlg, IDD_ADDLOGOBJECTTEXT, TRUE) ;
  113. DialogEnable (hDlg, IDD_ADDLOGOBJECT, TRUE) ;
  114. WindowCenter (hDlg) ;
  115. dwCurrentDlgID = HC_PM_idDlgEditAddToLog ;
  116. }
  117. void
  118. /* static */
  119. OnLogComputer (
  120. HDLG hDlg
  121. )
  122. /*
  123. Effect: Put up the select Domain/Computer dialog. Allow the user
  124. to select the computer. Check for user entering a domain
  125. instead. Place the selected computer in the readonly
  126. edit box.
  127. */
  128. {
  129. TCHAR szComputer [MAX_SYSTEM_NAME_LENGTH + 1] ;
  130. if (ChooseComputer (hDlg, szComputer)) {
  131. DialogSetString (hDlg, IDD_ADDLOGCOMPUTER, szComputer) ;
  132. LogComputerChanged (hDlg) ;
  133. }
  134. }
  135. void
  136. /* static */
  137. OnAddToLog (
  138. HDLG hDlg
  139. )
  140. /*
  141. Effect: Perform all actions needed when the user clicks on
  142. the add button. In particular, determine if the required
  143. fields of the dialog have valid values. If so, go ahead
  144. and add a LOGENTRY record in the log. If the computer
  145. being logged is not already logged, add a LOGSYSTEMENTRY
  146. as well.
  147. Assert: We have valid values for computer and object, since we
  148. always control these fields.
  149. */
  150. {
  151. TCHAR szComputer [MAX_SYSTEM_NAME_LENGTH + 1] ;
  152. TCHAR szObjectType [PerfObjectLen + 1] ;
  153. DWORD iObjectType ;
  154. DWORD iObjectNum ;
  155. HWND hWndObjectTypes ;
  156. PPERFOBJECT pObject ;
  157. PLOG pLog ;
  158. pLog = LogData (hWndLog) ;
  159. DialogText (hDlg, IDD_ADDLOGCOMPUTER, szComputer) ;
  160. hWndObjectTypes = DialogControl(hDlg, IDD_ADDLOGOBJECT) ;
  161. iObjectNum = (DWORD) LBNumItems (hWndObjectTypes) ;
  162. LBSetRedraw (hWndLogEntries, FALSE) ;
  163. for (iObjectType = 0; iObjectType < iObjectNum; iObjectType++) {
  164. // NOTE: for now, we don't check for duplicate lines
  165. if (LBSelected (hWndObjectTypes, iObjectType)) { // if
  166. LBString (hWndObjectTypes, iObjectType, szObjectType) ;
  167. pObject = (PPERFOBJECT) LBData (hWndObjectTypes, iObjectType) ;
  168. // eliminate duplicates here
  169. if (LogFindEntry(szComputer, pObject->ObjectNameTitleIndex) ==
  170. LOG_ENTRY_NOT_FOUND) {
  171. LogAddEntry (hWndLogEntries,
  172. szComputer,
  173. szObjectType,
  174. pObject->ObjectNameTitleIndex,
  175. FALSE) ;
  176. }
  177. }
  178. }
  179. LBSetRedraw (hWndLogEntries, TRUE) ;
  180. DialogSetText (hDlg, IDD_ADDLOGDONE, IDS_DONE) ;
  181. if (pLog->iStatus == iPMStatusCollecting) {
  182. LogWriteSystemCounterNames (hWndLog, pLog) ;
  183. }
  184. }
  185. INT_PTR
  186. FAR
  187. WINAPI
  188. AddLogDlgProc (
  189. HWND hDlg,
  190. UINT msg,
  191. WPARAM wParam,
  192. LPARAM lParam
  193. )
  194. {
  195. switch (msg) {
  196. case WM_INITDIALOG:
  197. OnInitAddLogDialog (hDlg) ;
  198. SetFocus (DialogControl (hDlg, IDD_ADDLOGADD)) ;
  199. return(FALSE);
  200. case WM_COMMAND:
  201. switch (LOWORD(wParam)) {
  202. case IDD_CANCEL:
  203. EndDialog(hDlg,0);
  204. return(TRUE);
  205. case IDD_OK:
  206. case IDD_ADDLOGADD:
  207. if (ComputerChange) {
  208. TCHAR szComputer [MAX_SYSTEM_NAME_LENGTH + 3] ;
  209. DialogText (hDlg, IDD_ADDLOGCOMPUTER, szComputer) ;
  210. LogComputerChanged (hDlg) ;
  211. } else {
  212. SetHourglassCursor() ;
  213. OnAddToLog (hDlg) ;
  214. SetArrowCursor() ;
  215. }
  216. break ;
  217. case IDD_ADDLOGDONE:
  218. EndDialog (hDlg, 0) ;
  219. break ;
  220. case IDD_ADDLOGELLIPSES:
  221. SetHourglassCursor() ;
  222. OnLogComputer (hDlg) ;
  223. SetArrowCursor() ;
  224. break ;
  225. case IDD_ADDLOGCOMPUTER:
  226. if (HIWORD (wParam) == EN_UPDATE) {
  227. ComputerChange = TRUE ;
  228. }
  229. break ;
  230. case IDD_ADDLOGHELP:
  231. CallWinHelp (dwCurrentDlgID, hDlg) ;
  232. break ;
  233. case IDD_ADDLOGOBJECT:
  234. if (ComputerChange) {
  235. TCHAR szComputer [MAX_SYSTEM_NAME_LENGTH + 3] ;
  236. DialogText (hDlg, IDD_ADDLOGCOMPUTER, szComputer) ;
  237. LogComputerChanged (hDlg) ;
  238. }
  239. break ;
  240. default:
  241. break ;
  242. }
  243. break;
  244. case WM_DESTROY:
  245. OnLogDestroy (hDlg) ;
  246. break ;
  247. default:
  248. break;
  249. }
  250. return (FALSE);
  251. }
  252. BOOL AddLog (HWND hWndParent)
  253. {
  254. if (DialogBox (hInstance, idDlgAddLog, hWndParent, AddLogDlgProc)) {
  255. return (TRUE) ;
  256. }
  257. return (FALSE) ;
  258. }