home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / ODBC / mfcperf / perfview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  14.2 KB  |  457 lines

  1. // PerfStatsView.cpp : implementation file
  2. //
  3. // This file is part of Microsoft SQL Server online documentation.
  4. // Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  5. //
  6. // This source code is an intended supplement to the Microsoft SQL
  7. // Server online references and related electronic documentation.
  8. #include "stdafx.h"
  9. #include "MFCPerf.h"
  10. #include "PerfDoc.h"
  11. #include "PerfView.h"
  12.  
  13. #include "odbcss.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CPerfStatsView
  23. IMPLEMENT_DYNCREATE(CPerfStatsView, CFormView)
  24.  
  25. CPerfStatsView::CPerfStatsView()
  26.     : CFormView(CPerfStatsView::IDD)
  27.     {
  28.     //{{AFX_DATA_INIT(CPerfStatsView)
  29.     //}}AFX_DATA_INIT
  30.     }
  31.  
  32. CPerfStatsView::~CPerfStatsView()
  33.     {
  34.     }
  35.  
  36. void CPerfStatsView::DoDataExchange(CDataExchange* pDX)
  37.     {
  38.     CFormView::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CPerfStatsView)
  40.     DDX_Control(pDX, IDC_GRID_STATS, m_gridStats);
  41.     //}}AFX_DATA_MAP
  42.     }
  43.  
  44. BEGIN_MESSAGE_MAP(CPerfStatsView, CFormView)
  45.     //{{AFX_MSG_MAP(CPerfStatsView)
  46.         // NOTE - the ClassWizard will add and remove mapping macros here.
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CPerfStatsView diagnostics
  52. #ifdef _DEBUG
  53. void CPerfStatsView::AssertValid() const
  54.     {
  55.     CFormView::AssertValid();
  56.     }
  57.  
  58. void CPerfStatsView::Dump(CDumpContext& dc) const
  59.     {
  60.     CFormView::Dump(dc);
  61.     }
  62.  
  63. CPerfStatsDoc* CPerfStatsView::GetDocument() // non-debug version is inline
  64.     {
  65.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPerfStatsDoc)));
  66.     return (CPerfStatsDoc*)m_pDocument;
  67.     }
  68. #endif //_DEBUG
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CPerfStatsView message handlers
  72. void CPerfStatsView::OnInitialUpdate() 
  73.     {
  74.     CFormView::OnInitialUpdate();
  75.     
  76.     PTSTR       pStatsText[] =
  77.         {
  78.         _T("SQLidu"),           _T("SQLiduRows"),       _T("SQLSelects"),
  79.         _T("SQLSelectRows"),    _T("Transactions"),     _T("SQLPrepares"),
  80.         _T("ExecDirects"),      _T("SQLExecutes"),      _T("CursorOpens"),
  81.         _T("CursorSize"),       _T("CursorUsed"),       _T("PercentCursorUsed"),
  82.         _T("AvgFetchTime"),     _T("AvgCursorSize"),    _T("AvgCursorUsed"),
  83.         _T("SQLFetchTime"),     _T("SQLFetchCount"),    _T("CurrentStmtCount"),
  84.         _T("MaxOpenStmt"),      _T("SumOpenStmt"),      _T("CurrentConnectionCount"),
  85.         _T("MaxConnectionsOpened"),                     _T("SumConnectionsOpened"),
  86.         _T("SumConnectiontime"),_T("AvgTimeOpened"),    _T("ServerRndTrips"),
  87.         _T("BuffersSent"),      _T("BuffersRec"),       _T("BytesSent"),
  88.         _T("BytesRec"),         _T("msExecutionTime"),  _T("msNetWorkServerTime")
  89.         };
  90.  
  91.     RECT        rectGrid;
  92.     RECT        rectFrame;
  93.     CWnd*       wndFrame = this->GetParent();
  94.  
  95.     m_gridStats.GetWindowRect(&rectGrid);
  96.     wndFrame->GetWindowRect(&rectFrame);
  97.  
  98.     rectFrame.bottom = (rectGrid.bottom - rectFrame.top) + 16;
  99.     rectFrame.right = rectFrame.right - rectFrame.left;
  100.     rectFrame.top = 0;
  101.     rectFrame.left = 0;
  102.  
  103.     wndFrame->MoveWindow(&rectFrame);
  104.  
  105.     m_gridStats.SetColWidth(0, 156 * 15);
  106.     m_gridStats.SetColWidth(1, 121 * 15);
  107.     m_gridStats.SetColWidth(2, 121 * 15);
  108.     m_gridStats.SetRow(0);
  109.     m_gridStats.SetCol(0);
  110.     m_gridStats.SetText(_T("Statistic"));
  111.     m_gridStats.SetCol(1);
  112.     m_gridStats.SetText(_T("Slow execution"));
  113.     m_gridStats.SetCol(2);
  114.     m_gridStats.SetText(_T("Fast execution"));
  115.     m_gridStats.SetCol(0);
  116.  
  117.     for (UINT i = 0; i < 32; i++)
  118.         {
  119.         m_gridStats.SetRow(i+1);
  120.         m_gridStats.SetText(pStatsText[i]);
  121.         }
  122.  
  123.     }
  124.  
  125. void CPerfStatsView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  126.     {
  127.     CPerfStatsDoc*  pDocument = GetDocument();
  128.     if (!pDocument->IsModified())
  129.         {
  130.         return;
  131.         }
  132.  
  133.     CString         strValue;
  134.     
  135.     m_gridStats.SetRow(1);
  136.     
  137.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLidu);
  138.     m_gridStats.SetCol(1);
  139.     m_gridStats.SetText((LPCTSTR) strValue);
  140.  
  141.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLidu);
  142.     m_gridStats.SetCol(2);
  143.     m_gridStats.SetText((LPCTSTR) strValue);
  144.  
  145.     m_gridStats.SetRow(2);
  146.  
  147.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLiduRows);
  148.     m_gridStats.SetCol(1);
  149.     m_gridStats.SetText((LPCTSTR) strValue);
  150.  
  151.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLiduRows);
  152.     m_gridStats.SetCol(2);
  153.     m_gridStats.SetText((LPCTSTR) strValue);
  154.  
  155.     m_gridStats.SetRow(3);
  156.  
  157.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLSelects);
  158.     m_gridStats.SetCol(1);
  159.     m_gridStats.SetText((LPCTSTR) strValue);
  160.  
  161.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLSelects);
  162.     m_gridStats.SetCol(2);
  163.     m_gridStats.SetText((LPCTSTR) strValue);
  164.  
  165.     m_gridStats.SetRow(4);
  166.  
  167.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLSelectRows);
  168.     m_gridStats.SetCol(1);
  169.     m_gridStats.SetText((LPCTSTR) strValue);
  170.  
  171.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLSelectRows);
  172.     m_gridStats.SetCol(2);
  173.     m_gridStats.SetText((LPCTSTR) strValue);
  174.  
  175.     m_gridStats.SetRow(5);
  176.  
  177.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.Transactions);
  178.     m_gridStats.SetCol(1);
  179.     m_gridStats.SetText((LPCTSTR) strValue);
  180.  
  181.     strValue.Format(_T("%lu"), pDocument->m_perfFast.Transactions);
  182.     m_gridStats.SetCol(2);
  183.     m_gridStats.SetText((LPCTSTR) strValue);
  184.  
  185.     m_gridStats.SetRow(6);
  186.  
  187.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLPrepares);
  188.     m_gridStats.SetCol(1);
  189.     m_gridStats.SetText((LPCTSTR) strValue);
  190.  
  191.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLPrepares);
  192.     m_gridStats.SetCol(2);
  193.     m_gridStats.SetText((LPCTSTR) strValue);
  194.  
  195.     m_gridStats.SetRow(7);
  196.  
  197.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.ExecDirects);
  198.     m_gridStats.SetCol(1);
  199.     m_gridStats.SetText((LPCTSTR) strValue);
  200.  
  201.     strValue.Format(_T("%lu"), pDocument->m_perfFast.ExecDirects);
  202.     m_gridStats.SetCol(2);
  203.     m_gridStats.SetText((LPCTSTR) strValue);
  204.  
  205.     m_gridStats.SetRow(8);
  206.  
  207.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLExecutes);
  208.     m_gridStats.SetCol(1);
  209.     m_gridStats.SetText((LPCTSTR) strValue);
  210.  
  211.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLExecutes);
  212.     m_gridStats.SetCol(2);
  213.     m_gridStats.SetText((LPCTSTR) strValue);
  214.  
  215.     m_gridStats.SetRow(9);
  216.  
  217.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.CursorOpens);
  218.     m_gridStats.SetCol(1);
  219.     m_gridStats.SetText((LPCTSTR) strValue);
  220.  
  221.     strValue.Format(_T("%lu"), pDocument->m_perfFast.CursorOpens);
  222.     m_gridStats.SetCol(2);
  223.     m_gridStats.SetText((LPCTSTR) strValue);
  224.  
  225.     m_gridStats.SetRow(10);
  226.  
  227.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.CursorSize);
  228.     m_gridStats.SetCol(1);
  229.     m_gridStats.SetText((LPCTSTR) strValue);
  230.  
  231.     strValue.Format(_T("%lu"), pDocument->m_perfFast.CursorSize);
  232.     m_gridStats.SetCol(2);
  233.     m_gridStats.SetText((LPCTSTR) strValue);
  234.  
  235.     m_gridStats.SetRow(11);
  236.  
  237.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.CursorUsed);
  238.     m_gridStats.SetCol(1);
  239.     m_gridStats.SetText((LPCTSTR) strValue);
  240.  
  241.     strValue.Format(_T("%lu"), pDocument->m_perfFast.CursorUsed);
  242.     m_gridStats.SetCol(2);
  243.     m_gridStats.SetText((LPCTSTR) strValue);
  244.  
  245.     m_gridStats.SetRow(12);
  246.  
  247.     strValue.Format(_T("%.4f"), pDocument->m_perfSlow.PercentCursorUsed);
  248.     m_gridStats.SetCol(1);
  249.     m_gridStats.SetText((LPCTSTR) strValue);
  250.  
  251.     strValue.Format(_T("%.4f"), pDocument->m_perfFast.PercentCursorUsed);
  252.     m_gridStats.SetCol(2);
  253.     m_gridStats.SetText((LPCTSTR) strValue);
  254.  
  255.     m_gridStats.SetRow(13);
  256.  
  257.     strValue.Format(_T("%.4f"), pDocument->m_perfSlow.AvgFetchTime);
  258.     m_gridStats.SetCol(1);
  259.     m_gridStats.SetText((LPCTSTR) strValue);
  260.  
  261.     strValue.Format(_T("%.4f"), pDocument->m_perfFast.AvgFetchTime);
  262.     m_gridStats.SetCol(2);
  263.     m_gridStats.SetText((LPCTSTR) strValue);
  264.  
  265.     m_gridStats.SetRow(14);
  266.  
  267.     strValue.Format(_T("%.4f"), pDocument->m_perfSlow.AvgCursorSize);
  268.     m_gridStats.SetCol(1);
  269.     m_gridStats.SetText((LPCTSTR) strValue);
  270.  
  271.     strValue.Format(_T("%.4f"), pDocument->m_perfFast.AvgCursorSize);
  272.     m_gridStats.SetCol(2);
  273.     m_gridStats.SetText((LPCTSTR) strValue);
  274.  
  275.     m_gridStats.SetRow(15);
  276.  
  277.     strValue.Format(_T("%.4f"), pDocument->m_perfSlow.AvgCursorUsed);
  278.     m_gridStats.SetCol(1);
  279.     m_gridStats.SetText((LPCTSTR) strValue);
  280.  
  281.     strValue.Format(_T("%.4f"), pDocument->m_perfFast.AvgCursorUsed);
  282.     m_gridStats.SetCol(2);
  283.     m_gridStats.SetText((LPCTSTR) strValue);
  284.  
  285.     m_gridStats.SetRow(16);
  286.  
  287.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLFetchTime);
  288.     m_gridStats.SetCol(1);
  289.     m_gridStats.SetText((LPCTSTR) strValue);
  290.  
  291.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLFetchTime);
  292.     m_gridStats.SetCol(2);
  293.     m_gridStats.SetText((LPCTSTR) strValue);
  294.  
  295.     m_gridStats.SetRow(17);
  296.  
  297.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SQLFetchCount);
  298.     m_gridStats.SetCol(1);
  299.     m_gridStats.SetText((LPCTSTR) strValue);
  300.  
  301.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SQLFetchCount);
  302.     m_gridStats.SetCol(2);
  303.     m_gridStats.SetText((LPCTSTR) strValue);
  304.  
  305.     m_gridStats.SetRow(18);
  306.  
  307.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.CurrentStmtCount);
  308.     m_gridStats.SetCol(1);
  309.     m_gridStats.SetText((LPCTSTR) strValue);
  310.  
  311.     strValue.Format(_T("%lu"), pDocument->m_perfFast.CurrentStmtCount);
  312.     m_gridStats.SetCol(2);
  313.     m_gridStats.SetText((LPCTSTR) strValue);
  314.  
  315.     m_gridStats.SetRow(19);
  316.  
  317.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.MaxOpenStmt);
  318.     m_gridStats.SetCol(1);
  319.     m_gridStats.SetText((LPCTSTR) strValue);
  320.  
  321.     strValue.Format(_T("%lu"), pDocument->m_perfFast.MaxOpenStmt);
  322.     m_gridStats.SetCol(2);
  323.     m_gridStats.SetText((LPCTSTR) strValue);
  324.  
  325.     m_gridStats.SetRow(20);
  326.  
  327.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SumOpenStmt);
  328.     m_gridStats.SetCol(1);
  329.     m_gridStats.SetText((LPCTSTR) strValue);
  330.  
  331.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SumOpenStmt);
  332.     m_gridStats.SetCol(2);
  333.     m_gridStats.SetText((LPCTSTR) strValue);
  334.  
  335.     m_gridStats.SetRow(21);
  336.  
  337.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.CurrentConnectionCount);
  338.     m_gridStats.SetCol(1);
  339.     m_gridStats.SetText((LPCTSTR) strValue);
  340.  
  341.     strValue.Format(_T("%lu"), pDocument->m_perfFast.CurrentConnectionCount);
  342.     m_gridStats.SetCol(2);
  343.     m_gridStats.SetText((LPCTSTR) strValue);
  344.  
  345.     m_gridStats.SetRow(22);
  346.  
  347.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.MaxConnectionsOpened);
  348.     m_gridStats.SetCol(1);
  349.     m_gridStats.SetText((LPCTSTR) strValue);
  350.  
  351.     strValue.Format(_T("%lu"), pDocument->m_perfFast.MaxConnectionsOpened);
  352.     m_gridStats.SetCol(2);
  353.     m_gridStats.SetText((LPCTSTR) strValue);
  354.  
  355.     m_gridStats.SetRow(23);
  356.  
  357.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SumConnectionsOpened);
  358.     m_gridStats.SetCol(1);
  359.     m_gridStats.SetText((LPCTSTR) strValue);
  360.  
  361.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SumConnectionsOpened);
  362.     m_gridStats.SetCol(2);
  363.     m_gridStats.SetText((LPCTSTR) strValue);
  364.  
  365.     m_gridStats.SetRow(24);
  366.  
  367.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.SumConnectiontime);
  368.     m_gridStats.SetCol(1);
  369.     m_gridStats.SetText((LPCTSTR) strValue);
  370.  
  371.     strValue.Format(_T("%lu"), pDocument->m_perfFast.SumConnectiontime);
  372.     m_gridStats.SetCol(2);
  373.     m_gridStats.SetText((LPCTSTR) strValue);
  374.  
  375.     m_gridStats.SetRow(25);
  376.  
  377.     strValue.Format(_T("%.4f"), pDocument->m_perfSlow.AvgTimeOpened);
  378.     m_gridStats.SetCol(1);
  379.     m_gridStats.SetText((LPCTSTR) strValue);
  380.  
  381.     strValue.Format(_T("%.4f"), pDocument->m_perfFast.AvgTimeOpened);
  382.     m_gridStats.SetCol(2);
  383.     m_gridStats.SetText((LPCTSTR) strValue);
  384.  
  385.     m_gridStats.SetRow(26);
  386.  
  387.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.ServerRndTrips);
  388.     m_gridStats.SetCol(1);
  389.     m_gridStats.SetText((LPCTSTR) strValue);
  390.  
  391.     strValue.Format(_T("%lu"), pDocument->m_perfFast.ServerRndTrips);
  392.     m_gridStats.SetCol(2);
  393.     m_gridStats.SetText((LPCTSTR) strValue);
  394.  
  395.     m_gridStats.SetRow(27);
  396.  
  397.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.BuffersSent);
  398.     m_gridStats.SetCol(1);
  399.     m_gridStats.SetText((LPCTSTR) strValue);
  400.  
  401.     strValue.Format(_T("%lu"), pDocument->m_perfFast.BuffersSent);
  402.     m_gridStats.SetCol(2);
  403.     m_gridStats.SetText((LPCTSTR) strValue);
  404.  
  405.     m_gridStats.SetRow(28);
  406.  
  407.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.BuffersRec);
  408.     m_gridStats.SetCol(1);
  409.     m_gridStats.SetText((LPCTSTR) strValue);
  410.  
  411.     strValue.Format(_T("%lu"), pDocument->m_perfFast.BuffersRec);
  412.     m_gridStats.SetCol(2);
  413.     m_gridStats.SetText((LPCTSTR) strValue);
  414.  
  415.     m_gridStats.SetRow(29);
  416.  
  417.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.BytesSent);
  418.     m_gridStats.SetCol(1);
  419.     m_gridStats.SetText((LPCTSTR) strValue);
  420.  
  421.     strValue.Format(_T("%lu"), pDocument->m_perfFast.BytesSent);
  422.     m_gridStats.SetCol(2);
  423.     m_gridStats.SetText((LPCTSTR) strValue);
  424.  
  425.     m_gridStats.SetRow(30);
  426.  
  427.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.BytesRec);
  428.     m_gridStats.SetCol(1);
  429.     m_gridStats.SetText((LPCTSTR) strValue);
  430.  
  431.     strValue.Format(_T("%lu"), pDocument->m_perfFast.BytesRec);
  432.     m_gridStats.SetCol(2);
  433.     m_gridStats.SetText((LPCTSTR) strValue);
  434.  
  435.     m_gridStats.SetRow(31);
  436.  
  437.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.msExecutionTime);
  438.     m_gridStats.SetCol(1);
  439.     m_gridStats.SetText((LPCTSTR) strValue);
  440.  
  441.     strValue.Format(_T("%lu"), pDocument->m_perfFast.msExecutionTime);
  442.     m_gridStats.SetCol(2);
  443.     m_gridStats.SetText((LPCTSTR) strValue);
  444.  
  445.     m_gridStats.SetRow(32);
  446.  
  447.     strValue.Format(_T("%lu"), pDocument->m_perfSlow.msNetWorkServerTime);
  448.     m_gridStats.SetCol(1);
  449.     m_gridStats.SetText((LPCTSTR) strValue);
  450.  
  451.     strValue.Format(_T("%lu"), pDocument->m_perfFast.msNetWorkServerTime);
  452.     m_gridStats.SetCol(2);
  453.     m_gridStats.SetText((LPCTSTR) strValue);
  454.  
  455.     pDocument->SetModifiedFlag(FALSE);
  456.     }
  457.