home *** CD-ROM | disk | FTP | other *** search
- // MFCPerf.cpp : Defines the class behaviors for the application.
- //
- // This file is part of Microsoft SQL Server online documentation.
- // Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
- //
- // This source code is an intended supplement to the Microsoft SQL
- // Server online references and related electronic documentation.
- #include "stdafx.h"
- #include "MFCPerf.h"
-
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "MFCPCust.h"
- #include "DocSlow.h"
- #include "ViewSlow.h"
- #include "DocFast.h"
- #include "ViewFast.h"
- #include "PerfDoc.h"
- #include "PerfView.h"
-
- #define PERF_ITERATIONS 20
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- static void PerfStart(SQLHDBC hdbc, SQLPERF** ppSQLPerf);
- static void PerfSnapshot(SQLHDBC hdbc, LPCTSTR szComment);
- static void PerfStop(SQLHDBC hdbc);
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPerfApp
- BEGIN_MESSAGE_MAP(CMFCPerfApp, CWinApp)
- //{{AFX_MSG_MAP(CMFCPerfApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_PERFTEST_RUNTEST, OnPerftestRuntest)
- ON_COMMAND(ID_PERFTEST_SETLOGFILENAME, OnPerftestSetlogfilename)
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW_FAST, CMFCPerfApp::OnFileNewFast)
- ON_COMMAND(ID_FILE_NEW_SLOW, CMFCPerfApp::OnFileNewSlow)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPerfApp construction
- CMFCPerfApp::CMFCPerfApp()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CMFCPerfApp object
- CMFCPerfApp theApp;
-
- // Global font objects.
- CFont g_fontEdits;
- CFont g_fontStatics;
-
- // Global statistics log file name.
- CString g_strLogFN = _T("");
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPerfApp initialization
- BOOL CMFCPerfApp::InitInstance()
- {
- // Initialize OLE control containing for Grid
- AfxEnableControlContainer();
-
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
-
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
-
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
-
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_MFCPERTYPE,
- RUNTIME_CLASS(CMFCPDocSlow),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CMFCPViewSlow));
- AddDocTemplate(pDocTemplate);
-
- pDocTemplate = new CMultiDocTemplate(
- IDR_MFCPERFAST,
- RUNTIME_CLASS(CMFCPDocFast),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CMFCPViewFast));
- AddDocTemplate(pDocTemplate);
-
- pDocTemplate = new CMultiDocTemplate(
- IDR_PERFSTATS,
- RUNTIME_CLASS(CPerfStatsDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CPerfStatsView));
- AddDocTemplate(pDocTemplate);
-
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
-
- // Replace standard processing for MFC database application.
- // Simply show the application main window.
- m_nCmdShow = SW_SHOWNORMAL;
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
-
- // Create the fonts for the form's edit and static controls.
- CDC* pDC = m_pMainWnd->GetDC();
-
- g_fontEdits.CreateFont(-MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72),
- 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- DEFAULT_PITCH, "Arial");
- g_fontStatics.CreateFont(-MulDiv(8, pDC->GetDeviceCaps(LOGPIXELSY), 72),
- 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- DEFAULT_PITCH, "Arial");
-
- m_pMainWnd->ReleaseDC(pDC);
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- // No message handlers
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // App command to run the dialog
- void CMFCPerfApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CLogFileDlg dialog used to set the name of the user's stats log file.
- class CLogFileDlg : public CDialog
- {
- // Construction
- public:
- CLogFileDlg(CWnd* pParent = NULL); // standard constructor
-
- // Dialog Data
- //{{AFX_DATA(CLogFileDlg)
- enum { IDD = IDD_DIALOG_LOGFN };
- CString m_editLogFN;
- //}}AFX_DATA
-
-
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CLogFileDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
-
- // Generated message map functions
- //{{AFX_MSG(CLogFileDlg)
- // NOTE: the ClassWizard will add member functions here
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- /////////////////////////////////////////////////////////////////////////////
- // CLogFileDlg dialog
- CLogFileDlg::CLogFileDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CLogFileDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CLogFileDlg)
- m_editLogFN = _T("");
- //}}AFX_DATA_INIT
- }
-
- void CLogFileDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLogFileDlg)
- DDX_Text(pDX, IDC_EDIT_LOGFN, m_editLogFN);
- DDV_MaxChars(pDX, m_editLogFN, 256);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CLogFileDlg, CDialog)
- //{{AFX_MSG_MAP(CLogFileDlg)
- // NOTE: the ClassWizard will add message map macros here
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPerfApp commands
- void CMFCPerfApp::OnFileNewFast()
- {
- CDocTemplate* pDocTemplate;
-
- POSITION pos = GetFirstDocTemplatePosition();
-
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocTemplate->OpenDocumentFile(NULL);
- }
-
- void CMFCPerfApp::OnFileNewSlow()
- {
- CDocTemplate* pDocTemplate;
-
- POSITION pos = GetFirstDocTemplatePosition();
-
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocTemplate->OpenDocumentFile(NULL);
- }
-
- void CMFCPerfApp::OnPerftestRuntest()
- {
- CDocTemplate* pDocTemplate;
- CMFCPDocFast* pDocFast;
- CMFCPViewFast* pViewFast;
- CMFCPDocSlow* pDocSlow;
- CMFCPViewSlow* pViewSlow;
- CMDIChildWnd* pChild;
- UINT i;
- POSITION pos;
- SQLPERF* pperf;
- CPerfStatsDoc* pDocStats;
-
- CWaitCursor WaitForIt;
-
- // Get the performance stats document.
- pos = GetFirstDocTemplatePosition();
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
- pDocStats = (CPerfStatsDoc*) pDocTemplate->OpenDocumentFile(NULL);
-
- // Do slow...
- pos = GetFirstDocTemplatePosition();
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
-
- // Check for cancel on login dialog box or other error.
- if ((pDocSlow = (CMFCPDocSlow*) pDocTemplate->OpenDocumentFile(NULL))
- == NULL)
- {
- return;
- }
-
- // Check for login to correct database.
- if (!pDocSlow->m_Database.IsOpen())
- {
- pDocSlow->OnCloseDocument();
- return;
- }
-
- // Get the view (child contains handling for CRecordset notifications).
- pChild = ((CMDIFrameWnd*) m_pMainWnd)->MDIGetActive();
- pViewSlow = (CMFCPViewSlow*) pChild->GetActiveView();
- pViewSlow->SetRedraw(FALSE);
-
- // Start performance data logging.
- PerfStart(pDocSlow->m_Database.m_hdbc, &pperf);
-
- // Animate the child.
- for (i = 0; i < PERF_ITERATIONS; i++)
- {
- pViewSlow->OnMove(ID_RECORD_NEXT);
- }
-
- // Snapshot the data, record it in the statistics doc, and then close the
- // stats source doc.
- PerfSnapshot(pDocSlow->m_Database.m_hdbc, NULL);
- PerfStop(pDocSlow->m_Database.m_hdbc);
- memcpy((void*) &(pDocStats->m_perfSlow), (void*) (pperf), sizeof(SQLPERF));
- pDocSlow->OnCloseDocument();
-
- // Do Fast...
- pDocTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
-
- // Check for cancel on login dialog box or other error.
- if ((pDocFast = (CMFCPDocFast*) pDocTemplate->OpenDocumentFile(NULL))
- == NULL)
- {
- return;
- }
-
- // Check for login to correct database.
- if (!pDocFast->m_Database.IsOpen())
- {
- pDocFast->OnCloseDocument();
- return;
- }
-
- // Get the view (child contains handling for CRecordset notifications).
- pChild = ((CMDIFrameWnd*) m_pMainWnd)->MDIGetActive();
- pViewFast = (CMFCPViewFast*) pChild->GetActiveView();
- pViewFast->SetRedraw(FALSE);
-
- // Start performance data logging.
- PerfStart(pDocFast->m_Database.m_hdbc, &pperf);
-
- // Animate the child.
- for (i = 0; i < PERF_ITERATIONS; i++)
- {
- pViewFast->OnMove(ID_RECORD_NEXT);
- }
-
- // Snapshot the data, record it in the statistics doc, and then close the
- // stats source doc.
- PerfSnapshot(pDocFast->m_Database.m_hdbc, NULL);
- PerfStop(pDocFast->m_Database.m_hdbc);
- memcpy((void*) &(pDocStats->m_perfFast), (void*) (pperf), sizeof(SQLPERF));
- pDocFast->OnCloseDocument();
-
- // Display the stats document...
- pDocStats->SetModifiedFlag();
- pDocStats->UpdateAllViews(NULL);
- }
-
- void CMFCPerfApp::OnPerftestSetlogfilename()
- {
- CLogFileDlg dlg;
-
- dlg.m_editLogFN = g_strLogFN;
-
- if (dlg.DoModal() == IDOK)
- {
- g_strLogFN = dlg.m_editLogFN;
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Global Functions
- void SetForm
- (
- CWnd* wndFrame,
- CEdit& editCompany,
- CEdit& editCountry,
- CMSFlexGrid& gridOrders,
- CMSFlexGrid& gridDetails,
- CStatic& staticClick,
- CStatic& staticToSee
- )
- {
- RECT rectGrid;
- RECT rectFrame;
-
- gridDetails.GetWindowRect(&rectGrid);
- wndFrame->GetWindowRect(&rectFrame);
-
- rectFrame.bottom = (rectGrid.bottom - rectFrame.top) + 16;
- rectFrame.right = rectFrame.right - rectFrame.left;
- rectFrame.top = 0;
- rectFrame.left = 0;
-
- wndFrame->MoveWindow(&rectFrame);
-
- editCompany.SetFont((CFont*) &g_fontEdits);
- editCountry.SetFont((CFont*) &g_fontEdits);
-
- staticClick.SetFont((CFont*) &g_fontStatics);
- staticToSee.SetFont((CFont*) &g_fontStatics);
-
- gridOrders.SetColWidth(0, 300);
- gridDetails.SetColWidth(0, 300);
-
- gridOrders.SetColWidth(1, 1215);
- gridOrders.SetColWidth(2, 2040);
- gridOrders.SetColWidth(3, 2040);
- gridOrders.SetColWidth(4, 2040);
-
- gridDetails.SetColWidth(1, 2880);
- gridDetails.SetColWidth(2, 1170);
- gridDetails.SetColWidth(3, 1170);
- gridDetails.SetColWidth(4, 1170);
- gridDetails.SetColWidth(5, 1170);
- }
-
- // Take a snapshot of the performance data. MFC is an ODBC 2.x consumer; use
- // ODBC 2.x SQLSetConnectOption, not 3.x SQLSetConnectAttr.
- void PerfSnapshot
- (
- SQLHDBC hdbc,
- LPCTSTR szComment
- )
- {
- SQLSetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA_LOG_NOW,
- (UDWORD) ((void*) szComment));
- }
-
- // Take a snapshot of the performance data.
- void PerfStart
- (
- SQLHDBC hdbc,
- SQLPERF** ppSQLPerf
- )
- {
- if (!g_strLogFN.GetLength())
- {
- g_strLogFN = DEFAULT_LOGFILE;
- }
-
- // Check to see if logging is already enabled on the connection. If
- // logging is on, disable and enable logging to clear log buffers
- // for our use.
- SQLGetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA,
- (SQLPOINTER) ppSQLPerf);
- if (*ppSQLPerf != NULL)
- {
- SQLSetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA,
- SQL_PERF_STOP);
- }
- else
- {
- SQLSetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA_LOG,
- (UDWORD) ((LPCTSTR) g_strLogFN));
- }
-
- SQLSetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA,
- SQL_PERF_START);
- SQLGetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA,
- (SQLPOINTER) ppSQLPerf);
- }
-
- void PerfStop
- (
- SQLHDBC hdbc
- )
- {
- SQLSetConnectOption(hdbc, SQL_COPT_SS_PERF_DATA, SQL_PERF_STOP);
- }