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.

619 lines
17 KiB

  1. // PCntPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "drvvctrl.hxx"
  5. #include "PCntPage.hxx"
  6. #include "DrvCSht.hxx"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. // timer ID
  13. #define REFRESH_TIMER_ID 0x1243
  14. // manual, high, normal, low speed
  15. #define REFRESH_SPEED_VARS 4
  16. // timer intervals in millisec for manual, high, normal, low speed
  17. static UINT uTimerIntervals[ REFRESH_SPEED_VARS ] =
  18. {
  19. 0, // Manual
  20. 1000, // High Speed
  21. 5000, // Normal Speed
  22. 10000 // Low Speed
  23. };
  24. //
  25. // help IDs
  26. //
  27. static DWORD MyHelpIds[] =
  28. {
  29. IDC_POOLCNT_CRT_PPOOL_ALLOC_EDIT, IDH_DV_PoolTab_paged_allocations_current,
  30. IDC_POOLCNT_CRT_NPPOOL_ALLOC_EDIT, IDH_DV_PoolTab_nonpaged_allocations_current,
  31. IDC_POOLCNT_PEAK_PPOOL_ALLOC_EDIT, IDH_DV_PoolTab_paged_allocations_peak,
  32. IDC_POOLCNT_PEAK_NPPOOL_ALLOC_EDIT, IDH_DV_PoolTab_nonpaged_allocations_peak,
  33. IDC_POOLCNT_UNTRACK_ALLOC_EDIT, IDH_DV_PoolTab_globalcounters,
  34. IDC_POOLCNT_CRT_PPOOL_BYTES_EDIT, IDH_DV_PoolTab_paged_currentbytes,
  35. IDC_POOLCNT_CRT_NPPOOL_BYTES_EDIT, IDH_DV_PoolTab_nonpaged_currentbytes,
  36. IDC_POOLCNT_PEAK_PPOOL_BYTES_EDIT, IDH_DV_PoolTab_paged_peakbytes,
  37. IDC_POOLCNT_PEAK_NPPOOL_BYTES_EDIT, IDH_DV_PoolTab_nonpaged_peakbytes,
  38. IDC_POOLCNT_DRVNAME_COMBO, IDH_DV_PoolTab_indivcounters,
  39. IDC_POOLCNT_REFRESH_BUTTON, IDH_DV_common_refresh_nowbutton,
  40. IDC_POOLCNT_MANUAL_RADIO, IDH_DV_common_refresh_manual,
  41. IDC_POOLCNT_HSPEED_RADIO, IDH_DV_common_refresh_high,
  42. IDC_POOLCNT_NORM_RADIO, IDH_DV_common_refresh_normal,
  43. IDC_POOLCNT_LOW_RADIO, IDH_DV_common_refresh_low,
  44. 0, 0
  45. };
  46. /////////////////////////////////////////////////////////////////////
  47. static void GetStringFromULONG( CString &strValue, ULONG_PTR uValue )
  48. {
  49. LPTSTR lptstrValue = strValue.GetBuffer( 64 );
  50. if( lptstrValue != NULL )
  51. {
  52. _stprintf( lptstrValue, _T( "%lu" ), uValue );
  53. strValue.ReleaseBuffer();
  54. }
  55. else
  56. {
  57. ASSERT( FALSE );
  58. strValue.Empty();
  59. }
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CPoolCntPage property page
  63. IMPLEMENT_DYNCREATE(CPoolCntPage, CPropertyPage)
  64. CPoolCntPage::CPoolCntPage()
  65. : CPropertyPage(CPoolCntPage::IDD)
  66. {
  67. //{{AFX_DATA_INIT(CPoolCntPage)
  68. m_nUpdateIntervalIndex = 2;
  69. m_strCrtNPAlloc = _T("");
  70. m_strCrtNPBytes = _T("");
  71. m_strCrtPPAlloc = _T("");
  72. m_strCrtPPBytes = _T("");
  73. m_strPeakNPPAlloc = _T("");
  74. m_strPeakNPPBytes = _T("");
  75. m_strPeakPPAlloc = _T("");
  76. m_strPeakPPBytes = _T("");
  77. m_strUnTrackedAlloc = _T("");
  78. //}}AFX_DATA_INIT
  79. m_uTimerHandler = 0;
  80. }
  81. void CPoolCntPage::DoDataExchange(CDataExchange* pDX)
  82. {
  83. TCHAR szCrtDriverName [ _MAX_PATH ];
  84. BOOL bComboEnabled;
  85. CPropertyPage::DoDataExchange(pDX);
  86. //
  87. // subclass the combo-box
  88. //
  89. DDX_Control(pDX, IDC_POOLCNT_DRVNAME_COMBO, m_DrvNamesCombo);
  90. //
  91. // get the date from the kernel
  92. //
  93. bComboEnabled = TRUE;
  94. if( ! pDX->m_bSaveAndValidate )
  95. {
  96. //
  97. // get the currently selected driver name
  98. //
  99. GetCurrentSelDriverName( szCrtDriverName, ARRAY_LENGTH( szCrtDriverName ) );
  100. //
  101. // query the kernel
  102. //
  103. if( KrnGetSystemVerifierState( &m_KrnVerifState ) &&
  104. m_KrnVerifState.DriverCount > 0 )
  105. {
  106. //
  107. // UnTrackedPool - global counter
  108. //
  109. GetStringFromULONG( m_strUnTrackedAlloc,
  110. m_KrnVerifState.UnTrackedPool );
  111. //
  112. // update combo content
  113. //
  114. FillDriversNameCombo( szCrtDriverName );
  115. }
  116. else
  117. {
  118. //
  119. // UnTrackedPool - global counter
  120. //
  121. VERIFY( m_strUnTrackedAlloc.LoadString( IDS_ZERO ) );
  122. //
  123. // disable the drivers name list
  124. //
  125. bComboEnabled = FALSE;
  126. m_DrvNamesCombo.ResetContent();
  127. //
  128. // this is used by OnDriversNameSelChanged
  129. //
  130. m_KrnVerifState.DriverCount = 0;
  131. }
  132. //
  133. // update per driver counters
  134. //
  135. OnDriversNameSelChanged();
  136. }
  137. //{{AFX_DATA_MAP(CPoolCntPage)
  138. DDX_Radio(pDX, IDC_POOLCNT_MANUAL_RADIO, m_nUpdateIntervalIndex);
  139. DDX_Text(pDX, IDC_POOLCNT_UNTRACK_ALLOC_EDIT, m_strUnTrackedAlloc);
  140. //}}AFX_DATA_MAP
  141. if( ! pDX->m_bSaveAndValidate )
  142. {
  143. m_DrvNamesCombo.EnableWindow( bComboEnabled );
  144. }
  145. }
  146. BEGIN_MESSAGE_MAP(CPoolCntPage, CPropertyPage)
  147. //{{AFX_MSG_MAP(CPoolCntPage)
  148. ON_BN_CLICKED(IDC_POOLCNT_REFRESH_BUTTON, OnCountRefreshButton)
  149. ON_WM_TIMER()
  150. ON_BN_CLICKED(IDC_POOLCNT_HSPEED_RADIO, OnCountHspeedRadio)
  151. ON_BN_CLICKED(IDC_POOLCNT_LOW_RADIO, OnCountLowRadio)
  152. ON_BN_CLICKED(IDC_POOLCNT_MANUAL_RADIO, OnCountManualRadio)
  153. ON_BN_CLICKED(IDC_POOLCNT_NORM_RADIO, OnCountNormRadio)
  154. ON_CBN_SELENDOK(IDC_POOLCNT_DRVNAME_COMBO, OnDriversNameSelChanged)
  155. ON_MESSAGE( WM_HELP, OnHelp )
  156. ON_MESSAGE( WM_CONTEXTMENU, OnContextMenu )
  157. //}}AFX_MSG_MAP
  158. END_MESSAGE_MAP()
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CPoolCntPage message handlers
  161. /////////////////////////////////////////////////////////////////////
  162. void CPoolCntPage::OnRefreshTimerChanged()
  163. {
  164. UINT uTimerElapse = 0;
  165. // kill the pending timer
  166. if( m_uTimerHandler != 0 )
  167. {
  168. VERIFY( KillTimer( REFRESH_TIMER_ID ) );
  169. }
  170. // sanity check
  171. if( m_nUpdateIntervalIndex < 0 ||
  172. m_nUpdateIntervalIndex >= REFRESH_SPEED_VARS )
  173. {
  174. m_nUpdateIntervalIndex = 0;
  175. CheckRadioButton( IDC_POOLCNT_MANUAL_RADIO, IDC_POOLCNT_LOW_RADIO,
  176. IDC_POOLCNT_MANUAL_RADIO );
  177. }
  178. // new timer interval
  179. uTimerElapse = uTimerIntervals[ m_nUpdateIntervalIndex ];
  180. if( uTimerElapse > 0 )
  181. {
  182. VERIFY( m_uTimerHandler = SetTimer( REFRESH_TIMER_ID,
  183. uTimerElapse, NULL ) );
  184. }
  185. }
  186. /////////////////////////////////////////////////////////////////////
  187. // CPoolCntPage message handlers
  188. BOOL CPoolCntPage::OnInitDialog()
  189. {
  190. CPropertyPage::OnInitDialog();
  191. OnRefreshTimerChanged();
  192. return TRUE; // return TRUE unless you set the focus to a control
  193. // EXCEPTION: OCX Property Pages should return FALSE
  194. }
  195. /////////////////////////////////////////////////////////////////////
  196. void CPoolCntPage::OnCountRefreshButton()
  197. {
  198. UpdateData( FALSE );
  199. }
  200. /////////////////////////////////////////////////////////////////////
  201. void CPoolCntPage::OnTimer(UINT nIDEvent)
  202. {
  203. if( nIDEvent == REFRESH_TIMER_ID )
  204. {
  205. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  206. if( pParentSheet != NULL )
  207. {
  208. ASSERT_VALID( pParentSheet );
  209. if( pParentSheet->GetActivePage() == this )
  210. {
  211. // refresh the displayed data
  212. OnCountRefreshButton();
  213. }
  214. }
  215. }
  216. CPropertyPage::OnTimer(nIDEvent);
  217. }
  218. /////////////////////////////////////////////////////////////////////
  219. BOOL CPoolCntPage::OnQueryCancel()
  220. {
  221. // give parent PropertySheet a chance to refuse the Cancel if needed
  222. CDrvChkSheet *pParentSheet = (CDrvChkSheet *)GetParent();
  223. if( pParentSheet != NULL )
  224. {
  225. ASSERT_VALID( pParentSheet );
  226. if( ! pParentSheet->OnQueryCancel() )
  227. {
  228. return FALSE;
  229. }
  230. }
  231. return CPropertyPage::OnQueryCancel();
  232. }
  233. /////////////////////////////////////////////////////////////////////
  234. BOOL CPoolCntPage::OnApply()
  235. {
  236. // refuse to apply
  237. // (we don't use the standard PropertSheet buttons; Apply, OK)
  238. return FALSE;
  239. }
  240. /////////////////////////////////////////////////////////////////////
  241. void CPoolCntPage::OnCountManualRadio()
  242. {
  243. // switch to manual refresh
  244. m_nUpdateIntervalIndex = 0;
  245. OnRefreshTimerChanged();
  246. }
  247. void CPoolCntPage::OnCountHspeedRadio()
  248. {
  249. // switch to high speed refresh
  250. m_nUpdateIntervalIndex = 1;
  251. OnRefreshTimerChanged();
  252. }
  253. void CPoolCntPage::OnCountNormRadio()
  254. {
  255. // switch to normal speed refresh
  256. m_nUpdateIntervalIndex = 2;
  257. OnRefreshTimerChanged();
  258. }
  259. void CPoolCntPage::OnCountLowRadio()
  260. {
  261. // switch to low speed refresh
  262. m_nUpdateIntervalIndex = 3;
  263. OnRefreshTimerChanged();
  264. }
  265. /////////////////////////////////////////////////////////////////////
  266. void CPoolCntPage::OnDriversNameSelChanged()
  267. {
  268. int nCrtSelItem;
  269. int nIndexInArray;
  270. BOOL bAllCountersZero;
  271. bAllCountersZero = TRUE;
  272. nCrtSelItem = m_DrvNamesCombo.GetCurSel();
  273. if( nCrtSelItem >= 0 && nCrtSelItem < (int)m_KrnVerifState.DriverCount )
  274. {
  275. nIndexInArray = (int)m_DrvNamesCombo.GetItemData( nCrtSelItem );
  276. if( nIndexInArray >= 0 && nIndexInArray < (int)m_KrnVerifState.DriverCount )
  277. {
  278. bAllCountersZero = FALSE;
  279. // CurrentPagedPoolAllocations
  280. GetStringFromULONG( m_strCrtPPAlloc,
  281. m_KrnVerifState.DriverInfo[ nIndexInArray ].CurrentPagedPoolAllocations );
  282. // CurrentNonPagedPoolAllocations
  283. GetStringFromULONG( m_strCrtNPAlloc,
  284. m_KrnVerifState.DriverInfo[ nIndexInArray ].CurrentNonPagedPoolAllocations );
  285. // PeakPagedPoolAllocations
  286. GetStringFromULONG( m_strPeakPPAlloc,
  287. m_KrnVerifState.DriverInfo[ nIndexInArray ].PeakPagedPoolAllocations );
  288. // PeakNonPagedPoolAllocations
  289. GetStringFromULONG( m_strPeakNPPAlloc,
  290. m_KrnVerifState.DriverInfo[ nIndexInArray ].PeakNonPagedPoolAllocations );
  291. // PagedPoolUsageInBytes
  292. GetStringFromULONG( m_strCrtPPBytes,
  293. m_KrnVerifState.DriverInfo[ nIndexInArray ].PagedPoolUsageInBytes );
  294. // NonPagedPoolUsageInBytes
  295. GetStringFromULONG( m_strCrtNPBytes,
  296. m_KrnVerifState.DriverInfo[ nIndexInArray ].NonPagedPoolUsageInBytes );
  297. // PeakPagedPoolUsageInBytes
  298. GetStringFromULONG( m_strPeakPPBytes,
  299. m_KrnVerifState.DriverInfo[ nIndexInArray ].PeakPagedPoolUsageInBytes );
  300. // PeakNonPagedPoolUsageInBytes
  301. GetStringFromULONG( m_strPeakNPPBytes,
  302. m_KrnVerifState.DriverInfo[ nIndexInArray ].PeakNonPagedPoolUsageInBytes );
  303. }
  304. else
  305. {
  306. ASSERT( FALSE );
  307. }
  308. }
  309. if( bAllCountersZero )
  310. {
  311. // CurrentPagedPoolAllocations
  312. VERIFY( m_strCrtPPAlloc.LoadString( IDS_ZERO ) );
  313. // CurrentNonPagedPoolAllocations
  314. VERIFY( m_strCrtNPAlloc.LoadString( IDS_ZERO ) );
  315. // PeakPagedPoolAllocations
  316. VERIFY( m_strPeakPPAlloc.LoadString( IDS_ZERO ) );
  317. // PeakNonPagedPoolAllocations
  318. VERIFY( m_strPeakNPPAlloc.LoadString( IDS_ZERO ) );
  319. // PagedPoolUsageInBytes
  320. VERIFY( m_strCrtPPBytes.LoadString( IDS_ZERO ) );
  321. // NonPagedPoolUsageInBytes
  322. VERIFY( m_strCrtNPBytes.LoadString( IDS_ZERO ) );
  323. // PeakPagedPoolUsageInBytes
  324. VERIFY( m_strPeakPPBytes.LoadString( IDS_ZERO ) );
  325. // PeakNonPagedPoolUsageInBytes
  326. VERIFY( m_strPeakNPPBytes.LoadString( IDS_ZERO ) );
  327. }
  328. //
  329. // set the text in edit controls
  330. //
  331. SetDlgItemText( IDC_POOLCNT_CRT_NPPOOL_ALLOC_EDIT, m_strCrtNPAlloc);
  332. SetDlgItemText( IDC_POOLCNT_CRT_NPPOOL_BYTES_EDIT, m_strCrtNPBytes);
  333. SetDlgItemText( IDC_POOLCNT_CRT_PPOOL_ALLOC_EDIT, m_strCrtPPAlloc);
  334. SetDlgItemText( IDC_POOLCNT_CRT_PPOOL_BYTES_EDIT, m_strCrtPPBytes);
  335. SetDlgItemText( IDC_POOLCNT_PEAK_NPPOOL_ALLOC_EDIT, m_strPeakNPPAlloc);
  336. SetDlgItemText( IDC_POOLCNT_PEAK_NPPOOL_BYTES_EDIT, m_strPeakNPPBytes);
  337. SetDlgItemText( IDC_POOLCNT_PEAK_PPOOL_ALLOC_EDIT, m_strPeakPPAlloc);
  338. SetDlgItemText( IDC_POOLCNT_PEAK_PPOOL_BYTES_EDIT, m_strPeakPPBytes);
  339. }
  340. /////////////////////////////////////////////////////////////////////
  341. // operations
  342. void CPoolCntPage::GetCurrentSelDriverName(
  343. TCHAR *szCrtDriverName,
  344. int nBufferLength )
  345. {
  346. int nCrtSel;
  347. int nNameLength;
  348. int nDriverEntryIndex;
  349. if( nBufferLength < 1 )
  350. {
  351. ASSERT( FALSE );
  352. return;
  353. }
  354. szCrtDriverName[ 0 ] = (TCHAR)0;
  355. nCrtSel = m_DrvNamesCombo.GetCurSel();
  356. if( nCrtSel != CB_ERR && nCrtSel < (int)m_KrnVerifState.DriverCount )
  357. {
  358. nDriverEntryIndex = (int)m_DrvNamesCombo.GetItemData( nCrtSel );
  359. if( nDriverEntryIndex >= 0 && nDriverEntryIndex < (int)m_KrnVerifState.DriverCount )
  360. {
  361. nNameLength = _tcslen( m_KrnVerifState.DriverInfo[ nDriverEntryIndex ].Name );
  362. if( nNameLength < nBufferLength )
  363. {
  364. _tcscpy( szCrtDriverName, m_KrnVerifState.DriverInfo[ nDriverEntryIndex ].Name );
  365. }
  366. }
  367. else
  368. {
  369. ASSERT( FALSE );
  370. }
  371. }
  372. }
  373. /////////////////////////////////////////////////////////////////////
  374. void CPoolCntPage::FillDriversNameCombo(
  375. TCHAR *strNameToSelect )
  376. {
  377. BOOL *pbAlreadyInCombo;
  378. CString strDriverName;
  379. UINT uCrtVerifiedDriver;
  380. int nCrtItemIndex;
  381. int nCrtSelectedItem;
  382. int nComboItemCount;
  383. int nActualIndex;
  384. nCrtSelectedItem = 0;
  385. if( m_KrnVerifState.DriverCount > 0 )
  386. {
  387. //
  388. // allocate a logical value for each currently verified driver
  389. // with initial value FALSE
  390. //
  391. pbAlreadyInCombo = new BOOL[ m_KrnVerifState.DriverCount ];
  392. if( pbAlreadyInCombo == NULL )
  393. {
  394. m_DrvNamesCombo.ResetContent();
  395. return;
  396. }
  397. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++ )
  398. {
  399. pbAlreadyInCombo[ uCrtVerifiedDriver ] = FALSE;
  400. }
  401. //
  402. // parse each name currently in combo
  403. //
  404. nComboItemCount = m_DrvNamesCombo.GetCount();
  405. for( nCrtItemIndex = 0; nCrtItemIndex < nComboItemCount; nCrtItemIndex++ )
  406. {
  407. m_DrvNamesCombo.GetLBText( nCrtItemIndex, strDriverName );
  408. //
  409. // parse the driver names in m_KrnVerifState and see if we have a match
  410. //
  411. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++ )
  412. {
  413. if( _tcsicmp( (LPCTSTR)strDriverName, m_KrnVerifState.DriverInfo[ uCrtVerifiedDriver ].Name ) == 0 )
  414. {
  415. //
  416. // it's still verified
  417. //
  418. pbAlreadyInCombo[ uCrtVerifiedDriver ] = TRUE;
  419. //
  420. // update the index in m_KrnVerifState.DriverInfo array
  421. //
  422. m_DrvNamesCombo.SetItemData( nCrtItemIndex, uCrtVerifiedDriver );
  423. break;
  424. }
  425. }
  426. if( uCrtVerifiedDriver >= m_KrnVerifState.DriverCount )
  427. {
  428. //
  429. // this driver is no longer verified, remove it from the list
  430. //
  431. m_DrvNamesCombo.DeleteString( nCrtItemIndex );
  432. nCrtItemIndex--;
  433. nComboItemCount--;
  434. }
  435. }
  436. //
  437. // add the new verified drivers
  438. //
  439. for( uCrtVerifiedDriver = 0; uCrtVerifiedDriver < m_KrnVerifState.DriverCount; uCrtVerifiedDriver++ )
  440. {
  441. if( pbAlreadyInCombo[ uCrtVerifiedDriver ] == FALSE )
  442. {
  443. nActualIndex = m_DrvNamesCombo.AddString( m_KrnVerifState.DriverInfo[ uCrtVerifiedDriver ].Name );
  444. if( nActualIndex != CB_ERR )
  445. {
  446. m_DrvNamesCombo.SetItemData( nActualIndex, uCrtVerifiedDriver );
  447. }
  448. }
  449. }
  450. ASSERT( m_DrvNamesCombo.GetCount() == m_KrnVerifState.DriverCount );
  451. //
  452. // current selection
  453. //
  454. nComboItemCount = m_DrvNamesCombo.GetCount();
  455. for( nCrtItemIndex = 0; nCrtItemIndex < nComboItemCount; nCrtItemIndex++ )
  456. {
  457. m_DrvNamesCombo.GetLBText( nCrtItemIndex, strDriverName );
  458. if( _tcsicmp( (LPCTSTR)strDriverName, strNameToSelect ) == 0 )
  459. {
  460. nCrtSelectedItem = nCrtItemIndex;
  461. break;
  462. }
  463. }
  464. delete pbAlreadyInCombo;
  465. }
  466. else
  467. {
  468. m_DrvNamesCombo.ResetContent();
  469. }
  470. m_DrvNamesCombo.SetCurSel( nCrtSelectedItem );
  471. }
  472. /////////////////////////////////////////////////////////////
  473. LONG CPoolCntPage::OnHelp( WPARAM wParam, LPARAM lParam )
  474. {
  475. LONG lResult = 0;
  476. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  477. ::WinHelp(
  478. (HWND) lpHelpInfo->hItemHandle,
  479. VERIFIER_HELP_FILE,
  480. HELP_WM_HELP,
  481. (DWORD_PTR) MyHelpIds );
  482. return lResult;
  483. }
  484. /////////////////////////////////////////////////////////////
  485. LONG CPoolCntPage::OnContextMenu( WPARAM wParam, LPARAM lParam )
  486. {
  487. LONG lResult = 0;
  488. ::WinHelp(
  489. (HWND) wParam,
  490. VERIFIER_HELP_FILE,
  491. HELP_CONTEXTMENU,
  492. (DWORD_PTR) MyHelpIds );
  493. return lResult;
  494. }