📄 vcmon.c
字号:
Graph[i].numplots = 2;
sprintf(Graph[i].graphtitle, "VCache Hit/Miss Rate" );
sprintf(Graph[i].titles[0], "VCache Hits" );
sprintf(Graph[i].titles[1], "VCache Misses" );
break;
case HOLDINDEX:
Graph[i].numplots = 1;
sprintf(Graph[i].graphtitle, "Block Holds" );
sprintf(Graph[i].titles[0], "Holds" );
break;
case NEWINDEX:
Graph[i].numplots = 1;
sprintf(Graph[i].graphtitle, "Created Blocks" );
sprintf(Graph[i].titles[0], "Created Blocks" );
break;
case REPINDEX:
Graph[i].numplots = 2;
sprintf(Graph[i].graphtitle, "Reported Statistics" );
sprintf(Graph[i].titles[0], "Reported Hits" );
sprintf(Graph[i].titles[1], "Reported Misses" );
break;
case PGFLTINDEX:
Graph[i].numplots = 2;
sprintf(Graph[i].graphtitle, "Paging Activity" );
sprintf(Graph[i].titles[0], "Pagefile Reads" );
sprintf(Graph[i].titles[1], "Pagefile Writes" );
break;
}
}
}
//----------------------------------------------------------------------
//
// GraphProc
//
// Windows routine for the logo window.
//
//----------------------------------------------------------------------
LONG APIENTRY GraphProc( HWND hWnd, UINT message, WPARAM uParam,
LPARAM lParam )
{
HDC hDC;
static int firstgraph = 1;
static RECT origrc;
graphdata *mygraph;
switch( message) {
case WM_CREATE: {
HDC hdcMem;
HBITMAP oldbitmap;
HBRUSH hbrBkGnd;
HFONT hOldFont = NULL;
RECT rc;
int j;
char tmp[256];
// determine which graph we are
mygraph = &Graph[ NewGraph ];
mygraph->graphwnd = hWnd;
SetWindowLong( hWnd, 0, (long) mygraph );
// save original size of window
if( firstgraph) {
GetWindowRect( hWnd, &origrc );
firstgraph = 0;
}
GetClientRect( hWnd, &rc );
// grab device context
hDC = GetDC( hWnd );
// create the legend bitmap
mygraph->hlegendbmp = CreateCompatibleBitmap( hDC,
rc.right-rc.left,
FontTM.tmHeight );
GetObject( mygraph->hlegendbmp, sizeof (BITMAP),
(LPSTR) &mygraph->legendbmp) ;
hdcMem = CreateCompatibleDC (hDC) ;
oldbitmap = SelectObject( hdcMem, mygraph->hlegendbmp ) ;
// fill bitmap with grey background and draw graph border
FillStock( hdcMem, &rc, LTGRAY_BRUSH );
DrawSeperator( hdcMem, 0, rc.right - rc.left );
// divide things up into different colors
SetBkColor( hdcMem, GetSysColor(COLOR_BTNFACE));
if (hFont) hOldFont = SelectObject( hdcMem, hFont);
if( mygraph->numplots == 1 ) {
SetTextColor( hdcMem, MYBLUE );
TextOut( hdcMem, 0, 3, mygraph->titles[0], strlen(mygraph->titles[0]) );
} else {
SetTextColor( hdcMem, MYRED );
TextOut( hdcMem, 0, 3, mygraph->titles[1], strlen(mygraph->titles[1]) );
sprintf( tmp, "0/%g", mygraph->highpty[1] );
TextOut( hdcMem, rc.right/2, 3, tmp, strlen( tmp ));
}
if (hOldFont) SelectObject( hdcMem, hOldFont);
mygraph->hlegendbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
// creat axis label bitmap
mygraph->haxisbmp = CreateCompatibleBitmap( hDC,
rc.right-rc.left,
FontTM.tmHeight );
GetObject( mygraph->haxisbmp, sizeof (BITMAP),
(LPSTR) &mygraph->axisbmp) ;
hdcMem = CreateCompatibleDC (hDC) ;
oldbitmap = SelectObject( hdcMem, mygraph->haxisbmp ) ;
// fill bitmap with grey background and draw seperator
FillStock( hdcMem, &rc, LTGRAY_BRUSH );
DrawSeperator( hdcMem, mygraph->axisbmp.bmHeight - 2, rc.right - rc.left );
// divide things up into different colors
SetBkColor( hdcMem, GetSysColor(COLOR_BTNFACE));
if (hFont) hOldFont = SelectObject( hdcMem, hFont);
if( mygraph->numplots == 1 ) {
SetTextColor( hdcMem, MYBLUE );
sprintf( tmp, "0/%g", mygraph->highpty[0] );
TextOut( hdcMem, 0, 0, tmp, strlen( tmp ) );
} else {
SetTextColor( hdcMem, MYBLUE );
TextOut( hdcMem, 0, 0, mygraph->titles[0], strlen( mygraph->titles[0] ) );
sprintf( tmp, "0/%g", mygraph->highpty[0] );
TextOut( hdcMem, rc.right/2, 0,
tmp, strlen( tmp ));
}
if (hOldFont) SelectObject( hdcMem, hOldFont);
mygraph->haxisbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
// calculate size of graphic bitmap
mygraph->graphwidth = rc.right;
mygraph->graphheight = rc.bottom - mygraph->legendbmp.bmHeight -
mygraph->axisbmp.bmHeight;
// create graphic bitmap
mygraph->hgraphbmp = CreateCompatibleBitmap( hDC,
mygraph->graphwidth, mygraph->graphheight );
GetObject( mygraph->hgraphbmp, sizeof (BITMAP),
(LPSTR) &mygraph->graphbmp) ;
// fill with background color
hdcMem = CreateCompatibleDC (hDC) ;
oldbitmap = SelectObject( hdcMem, mygraph->hgraphbmp ) ;
hbrBkGnd = GRAPHBKGRND;
FillRect(hdcMem, &rc, hbrBkGnd);
DeleteObject(hbrBkGnd);
// draw the graph seperator and set bitmap
if( mygraph->numplots == 2) {
mygraph->halfheight[0] = (mygraph->graphheight - 2)/2 - 1;
mygraph->halfheight[1] = mygraph->graphheight - mygraph->halfheight[0] - 4;
DrawSeperator( hdcMem, mygraph->halfheight[0] + 1, rc.right - rc.left );
} else
mygraph->halfheight[0] = mygraph->graphheight - 1;
mygraph->hgraphbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
// create and zero the data points associated with the graph
mygraph->yval[0] = (double *) malloc( (mygraph->graphwidth+1) * sizeof(double) );
if( mygraph->numplots == 2)
mygraph->yval[1] = (double *) malloc( (mygraph->graphwidth+1) * sizeof(double) );
for(j=0; j < mygraph->graphwidth; j++ ) {
mygraph->yval[0][j] = -1.0;
if( mygraph->numplots == 2 )
mygraph->yval[1][j] = -1.0;
}
// draw the bitmaps
DrawBitmap( hDC, mygraph->haxisbmp, 0, 0,
rc.right, mygraph->axisbmp.bmHeight, 0 );
DrawBitmap( hDC, mygraph->hgraphbmp, 0,
(short) mygraph->axisbmp.bmHeight,
rc.right, rc.bottom - mygraph->legendbmp.bmHeight -
mygraph->axisbmp.bmHeight, 0 );
DrawBitmap( hDC, mygraph->hlegendbmp,
0, (short) (rc.bottom - mygraph->legendbmp.bmHeight),
(int) mygraph->legendbmp.bmWidth, (int) mygraph->legendbmp.bmHeight, 0 );
ReleaseDC( hWnd, hDC );
// flush
GdiFlush();
return 0;
}
case WM_GETMINMAXINFO: {
MINMAXINFO FAR* lpmmi;
// don't let windows shrink to less than original size
lpmmi = (MINMAXINFO FAR*) lParam;
lpmmi->ptMinTrackSize.x = origrc.right;
lpmmi->ptMinTrackSize.y = origrc.bottom;
return 0;
}
case WM_CLOSE:
// time to go away
mygraph = (graphdata *) GetWindowLong( hWnd, 0 );
mygraph->graphstat = 0;
// toggle our checkbox, if it exists
if( mygraph->buttonid )
CheckDlgButton( mygraph->graphdlg, mygraph->buttonid, 0);
// free all resources associated with the graph
if( mygraph->yval[0] ) free( mygraph->yval[0] );
if( mygraph->yval[1] ) free( mygraph->yval[1] );
DeleteObject( mygraph->hgraphbmp );
DeleteObject( mygraph->haxisbmp );
DeleteObject( mygraph->hlegendbmp );
DestroyWindow( hWnd );
return 0;
case WM_PAINT: {
RECT bckrect, rc;
PAINTSTRUCT Paint;
// get drawing critical section
WaitForSingleObject( DrawCrit, INFINITE );
// determine which graph I am
mygraph = (graphdata *) GetWindowLong( hWnd, 0 );
// get our DC
GetClientRect( hWnd, &rc);
hDC = BeginPaint( hWnd, &Paint );
// draw axis bitmap and seperator
bckrect = rc;
bckrect.bottom = mygraph->axisbmp.bmHeight - 2;
bckrect.left = mygraph->axisbmp.bmWidth;
FillStock( hDC, &bckrect, LTGRAY_BRUSH );
DrawBitmap( hDC, mygraph->haxisbmp,
0, 0,
(int) mygraph->axisbmp.bmWidth,
(int) mygraph->axisbmp.bmHeight, 0 );
DrawSeperator( hDC, mygraph->axisbmp.bmHeight - 2,
rc.right );
// draw the graph
DrawBitmap( hDC, mygraph->hgraphbmp, 0,
(short) mygraph->axisbmp.bmHeight,
rc.right,
(int) (rc.bottom - mygraph->legendbmp.bmHeight -
mygraph->axisbmp.bmHeight ), 1);
// do background for text areas
bckrect = rc;
bckrect.top = rc.bottom - mygraph->legendbmp.bmHeight + 2;
bckrect.left = mygraph->legendbmp.bmWidth;
FillStock( hDC, &bckrect, LTGRAY_BRUSH );
// draw legend bitmap and seperator
DrawSeperator( hDC, rc.bottom - mygraph->legendbmp.bmHeight,
rc.right );
DrawBitmap( hDC, mygraph->hlegendbmp, 0,
(short) (rc.bottom - mygraph->legendbmp.bmHeight),
(int) mygraph->legendbmp.bmWidth,
(int) mygraph->legendbmp.bmHeight, 0 );
EndPaint( hWnd, &Paint );
// release critical section
ReleaseSemaphore( DrawCrit, 1, NULL );
break;
}
}
return DefWindowProc ( hWnd, message, uParam, lParam);
}
//----------------------------------------------------------------------
//
// ToggleGraph
//
// Turns graph on or off. If the graph is to be turned on, it means
// creating the graph from scratch and sending it updated information
// whenever we get new information from the VxD.
//
//----------------------------------------------------------------------
VOID ToggleGraph( HWND hDlg, int buttonid, int index )
{
HWND hWnd, checkbox;
RECT rc;
int screenx, screeny;
if( Graph[ index ].graphstat && !IsDlgButtonChecked( hDlg, buttonid)) {
// graph is on so turn it off!
DestroyWindow( Graph[ index ].graphwnd );
} else if( !Graph[ index].graphstat && IsDlgButtonChecked( hDlg, buttonid )) {
// set global variable so graph knows which one it is when it
// handles WM_CREATE - I can find no other way of sending instance
// data to a window as it creates!
NewGraph = index;
// re-initialize key values
Graph[index].graphdlg = hDlg;
Graph[index].buttonid = buttonid;
Graph[index].xval = 0;
Graph[index].xaxis[0] = 1.0;
Graph[index].xaxis[1] = 1.0;
Graph[index].highpty[0] = 0.0;
Graph[index].highpty[1] = 0.0;
// turn the graph on
hWnd = CreateWindow( "Graph", Graph[ index ].graphtitle,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_THICKFRAME,
0, 0, GRAPHWIDTH, GRAPHHEIGHT,
NULL, NULL, hInst, NULL );
// determine where to place the graph (just to the right and below the checkbox)
checkbox = GetDlgItem( hDlg, buttonid );
GetWindowRect( checkbox, &rc );
screenx = GetSystemMetrics( SM_CXSCREEN );
screeny = GetSystemMetrics( SM_CYSCREEN );
if( rc.right + GRAPHWIDTH >= screenx )
rc.right = screenx - GRAPHWIDTH;
if( rc.bottom + GRAPHHEIGHT >= screeny )
rc.bottom = screeny - GRAPHHEIGHT;
SetWindowPos( hWnd, 0, rc.right+XGRAPHSPACE, rc.bottom+YGRAPHSPACE,
0, 0, SWP_NOSIZE );
// Show window
ShowWindow (hWnd, TRUE) ;
}
Graph[ index ].graphstat = !Graph[ index ].graphstat;
}
//----------------------------------------------------------------------
//
// UpdateInfoDialog
//
// Updates all the statistics text fields in the information dialog
// box.
//
//----------------------------------------------------------------------
void UpdateInfoDialog( HWND hDlg, BOOL init )
{
static hitrate = 0;
int newrate;
// cache size
if( CurStats.size != LastStats.size || init ) {
sprintf( msgbuf, "%d KB", CurStats.size );
SetDlgItemText( hDlg, IDC_VCSIZE, msgbuf );
}
// free memory
if( CurStats.free != LastStats.free || init ) {
sprintf( msgbuf, "%d KB", CurStats.free );
SetDlgItemText( hDlg, IDC_VCFREE, msgbuf );
}
// hit rate
if( CurStats.hits != LastStats.hits ||
CurStats.misses != LastStats.misses || init ) {
if( CurStats.hits + CurStats.misses == 0 ) {
sprintf( msgbuf, "0 %%" );
SetDlgItemText( hDlg, IDC_VCHITRATE, msgbuf );
} else {
newrate = (int) (((double)CurStats.hits/
((double)CurStats.misses + (double)CurStats.hits))*100.0);
if( newrate != hitrate ) {
sprintf( msgbuf, "%d %%", newrate );
SetDlgItemText( hDlg, IDC_VCHITRATE, msgbuf );
hitrate = newrate;
}
}
}
// hits
if( CurStats.hits != LastStats.hits || init ) {
sprintf( msgbuf, "%d", CurStats.hits );
SetDlgItemText( hDlg, IDC_VCHIT, msgbuf );
}
// misses
if( CurStats.misses != LastStats.misses || init ) {
sprintf( msgbuf, "%d", CurStats.misses );
SetDlgItemText( hDlg, IDC_VCMISS, msgbuf );
}
// holds
if( CurStats.holds != LastStats.holds || init ) {
sprintf( msgbuf, "%d", CurStats.holds );
SetDlgItemText( hDlg, IDC_VCHOLD, msgbuf );
}
// new blocks
if( CurStats.new != LastStats.new || init ) {
sprintf( msgbuf, "%d", CurStats.new );
SetDlgItemText( hDlg, IDC_VCNEW, msgbuf );
}
// pagefile reads
if( CurStats.pagereads != LastStats.pagereads || init ) {
sprintf( msgbuf, "%d", CurStats.pagereads );
SetDlgItemText( hDlg, IDC_VCPGREAD, msgbuf );
}
// pagefile writes
if( CurStats.pagewrites != LastStats.pagewrites || init ) {
sprintf( msgbuf, "%d", CurStats.pagewrites );
SetDlgItemText( hDlg, IDC_VCPGWRITE, msgbuf );
}
// reports hits
if( CurStats.rephits != LastStats.rephits || init ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -