CDynamoRIOView::CDynamoRIOView() : CFormView(CDynamoRIOView::IDD) { //{{AFX_DATA_INIT(CDynamoRIOView) //}}AFX_DATA_INIT // TODO: add construction code here ZeroStrings(); m_stats = NULL; m_clientMap = NULL; m_clientView = NULL; m_clientStats = NULL; m_list_pos = 0; m_selected_pid = 0; m_StatsViewLines = 0; // FIXME: share w/ CDynamoRIOApp::CheckWindowsVersion OSVERSIONINFO version; version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); int res = GetVersionEx(&version); assert(res != 0); if (version.dwPlatformId == VER_PLATFORM_WIN32_NT && version.dwMajorVersion == 4) m_windows_NT = TRUE; else m_windows_NT = FALSE; }
CDynamoRIOView::CDynamoRIOView() : CFormView(CDynamoRIOView::IDD) { //{{AFX_DATA_INIT(CDynamoRIOView) //}}AFX_DATA_INIT // TODO: add construction code here ZeroStrings(); m_stats = NULL; m_clientMap = NULL; m_clientView = NULL; m_clientStats = NULL; m_list_pos = 0; m_selected_pid = 0; m_StatsViewLines = 0; OSVERSIONINFOW version; CDynamoRIOApp::GetWindowsVersion(&version); if (version.dwPlatformId == VER_PLATFORM_WIN32_NT && version.dwMajorVersion == 4) m_windows_NT = TRUE; else m_windows_NT = FALSE; }
BOOL CDynamoRIOView::Refresh() { if (m_selected_pid <= 0) { ZeroStrings(); return TRUE; } // We have to grab new stats every refresh dr_statistics_t *new_stats = get_dynamorio_stats(m_selected_pid); if (new_stats == NULL) { if (m_stats != NULL) { // Leave the stats for an exited process in place, for viewing // and copying } else return TRUE; } else { if (m_stats != NULL) free_dynamorio_stats(m_stats); m_stats = new_stats; } uint i; #define MAX_VISIBLE_STATS 75 #define STATS_BUFSZ (MAX_VISIBLE_STATS*(sizeof(single_stat_t)*2/*cover %10u, etc.*/)) TCHAR buf[STATS_BUFSZ]; TCHAR *c = buf; buf[0] = _T('\0'); // If I just use a CString hooked up via DDX, re-setting the // text causes the top of the visible box to show the top of // the stats string; plus the scrollbar goes to the top, // unless held in place; probably any reset of the string // does an auto-reset of the display and scrollbar position. // To have all the text in there do this: // int scroll_pos = m_StatsCtl.GetScrollPos(SB_VERT); // m_StatsCtl.SetWindowText(buf); // m_StatsCtl.LineScroll(scroll_pos); // But then there's a lot of flickering: too much. // We only put visible text lines in the CEdit box, to reduce the // flicker. It's too hard to do it w/ the CEdit's own scrollbar, // which sets itself based on the actual text, so we have a // separate one. // HACK: I don't know how to find out how many lines will // fit w/o putting actual text in there if (m_StatsViewLines == 0) { for (i = 0; i < m_stats->num_stats && i < MAX_VISIBLE_STATS /* can't be more than this */; i++) { if (c >= &buf[STATS_BUFSZ-STAT_NAME_MAX_LEN*2]) break; c += PrintStat(c, i, FALSE/*no filter*/); assert(c < &buf[STATS_BUFSZ-1]); } m_StatsCtl.SetWindowText(buf); UpdateData(FALSE); // write to screen // I tried having only one screenful of string there, and // setting the scrollbar range to be larger, but it doesn't // seem to support that. RECT rect; m_StatsCtl.GetRect(&rect); CPoint pos(rect.right, rect.bottom); m_StatsViewLines = HIWORD(m_StatsCtl.CharFromPos(pos)); assert(m_StatsViewLines > 0); m_StatsSB.SetScrollRange(0, m_stats->num_stats-1, TRUE/*redraw*/); c = buf; SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); info.fMask = SIF_PAGE; info.nPage = m_StatsViewLines; m_StatsSB.SetScrollInfo(&info); } int scroll_pos = m_StatsSB.GetScrollPos(); DWORD shown = 0; uint printed; for (i = scroll_pos; i < m_stats->num_stats && shown < m_StatsViewLines; i++) { if (c >= &buf[STATS_BUFSZ-STAT_NAME_MAX_LEN*2]) break; printed = PrintStat(c, i, TRUE/*filter*/); c += printed; assert(c < &buf[STATS_BUFSZ-1]); if (printed > 0) shown++; } m_StatsCtl.SetWindowText(buf); // num_stats could have changed so update m_StatsSB.SetScrollRange(0, m_stats->num_stats-1, TRUE/*redraw*/); if (new_stats == NULL) m_Exited = _T(" Exited"); // line right end up with Running else m_Exited = _T("Running"); #ifndef DRSTATS_DEMO m_LogLevel.Format(_T("%d"), m_stats->loglevel); m_LogMask.Format(_T("0x%05X"), m_stats->logmask); m_LogDir.Format(_T("%") ASCII_PRINTF, m_stats->logdir); #endif if (m_clientStats != NULL) { #define CLIENTSTATS_BUFSZ USHRT_MAX TCHAR buf[CLIENTSTATS_BUFSZ]; PrintClientStats(buf, &buf[CLIENTSTATS_BUFSZ-1]); m_ClientStats.Format(_T("%s"), buf); } else m_ClientStats.Format(_T("")); UpdateData(FALSE); // write to screen return TRUE; }