//gets the task that is currently being viewed CTask* CBackEndDialog::GetViewedTask() { //first get the selected task int nSel = GetTaskList()->GetCurSel(); if(nSel == LB_ERR) { //no selection return NULL; } //get the actual task return (CTask*)GetTaskList()->GetItemData(nSel); }
void GetTaskName( ULONG pid, char *szTaskName, LPDWORD pdwSize ) /*++ Routine Description: Gets the task name for a given process id. Arguments: pid - Process id to look for. szTaskName - Buffer to put the task name into. lpdwSize - Pointer to a dword. On entry it contains the size of the szTaskName buffer. On exit it contains the number of characters in the buffer. Return Value: None. --*/ { PTASK_LIST pTask; PTASK_LIST pTaskBegin; LONG NumTasks; pTask = pTaskBegin = GetTaskList( &NumTasks ); if (pTask == NULL) { if (szTaskName) { strncpy( szTaskName, "unknown", *pdwSize ); } *pdwSize = min( 7, *pdwSize ); } else { while (NumTasks--) { if (pTask->dwProcessId == pid) { if (szTaskName) { strncpy( szTaskName, pTask->ProcessName, *pdwSize ); } *pdwSize = min( strlen(pTask->ProcessName), *pdwSize ); break; } pTask++; } if (NumTasks < 0) { if (szTaskName) { strncpy( szTaskName, "<exited>", *pdwSize ); } *pdwSize = min( 8, *pdwSize ); } free( pTaskBegin ); } }
LRESULT CBackEndDialog::OnAddTask(WPARAM wParam, LPARAM lParam) { //extract the task CTask* pNewTask = (CTask*)wParam; ASSERT(pNewTask); //see if this task is already in the list CTask* pCurr = m_pHeadTask; while(pCurr) { if(stricmp(pCurr->GetName(), pNewTask->GetName()) == 0) { //already have a task of that name delete pNewTask; return 0; } pCurr = pCurr->GetNextTask(); } if(m_pHeadTask == NULL) { m_pHeadTask = pNewTask; } else { //add it onto the end CTask* pCurr = m_pHeadTask; while(pCurr->GetNextTask()) pCurr = pCurr->GetNextTask(); pCurr->SetNextTask(pNewTask); } //now we can update the list control int nIndex = GetTaskList()->AddString(pNewTask->GetName()); GetTaskList()->SetItemData(nIndex, (DWORD)pNewTask); return 0; }
void LogTaskList( void ) /*++ Routine Description: This function gets the current task list and logs the process id & process name to the log file. Arguments: None. Return Value: None. --*/ { PTASK_LIST pTask; PTASK_LIST pTaskBegin; LONG NumTasks; lprintf( MSG_TASK_LIST ); pTask = pTaskBegin = GetTaskList( &NumTasks ); if (pTask == NULL) { printf( "ERROR: could not get the task list\n" ); } while (NumTasks--) { lprintfs("%4d %s\r\n",pTask->dwProcessId, pTask->ProcessName ); pTask++; } lprintfs( "\r\n" ); free( pTaskBegin ); }
/**************************************************************************************************** * @fn DoProfiling * Calculates and prints CPU/Stack profiling information * ***************************************************************************************************/ static void DoProfiling( osp_bool_t withStartEnd ) { uint8_t taskCounter, numTasks; uint32_t start, end, highWater; uint32_t totalElapsedTime; osp_float_t taskLoad; P_TCB tskPtr; uint8_t *pTaskList; TaskId tid; numTasks = GetTaskList( &pTaskList ); # ifdef STACK_INFO_ONLY /* Stack check */ i_printf("\r\n\t\t\t*** "); for (taskCounter = 0; taskCounter < numTasks; taskCounter++) { tid = (TaskId)pTaskList[taskCounter]; start = (uint32_t)asfTaskHandleTable[tid].pStack; end = start + asfTaskHandleTable[tid].stkSize; highWater = HighWaterMarkSearch( start, end ); i_printf("%02d ", (highWater * 100)/asfTaskHandleTable[tid].stkSize); } /* Main stack check */ start = (uint32_t)&gStackMem; end = start + (uint32_t)&gStackSize; highWater = HighWaterMarkSearch( start, end ); i_printf("%02d ***\r\n\n", (highWater * 100)/((uint32_t)&gStackSize)); # else i_printf("\r\n------------------------------------------------------\r\n"); totalElapsedTime = RTC_GetCounter() - gSystemRTCRefTime; for (taskCounter = 0; taskCounter < numTasks; taskCounter++) { /* Stack check */ tid = (TaskId)pTaskList[taskCounter]; start = (uint32_t)asfTaskHandleTable[tid].pStack; end = start + asfTaskHandleTable[tid].stkSize; highWater = HighWaterMarkSearch( start, end ); /* CPU Usage */ tskPtr = os_active_TCB[asfTaskHandleTable[tid].handle - 1]; taskLoad = ((osp_float_t)tskPtr->cumulativeRunTime * 100.0f)/(osp_float_t)totalElapsedTime; if (withStartEnd) { i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", C_gAsfTaskInitTable[tid].tskName, start, end, highWater, asfTaskHandleTable[tid].stkSize, (highWater * 100)/asfTaskHandleTable[tid].stkSize, taskLoad, tskPtr->runCount); } else { i_printf("%16s: %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", C_gAsfTaskInitTable[tid].tskName, highWater, asfTaskHandleTable[tid].stkSize, (highWater * 100)/asfTaskHandleTable[tid].stkSize, taskLoad, tskPtr->runCount); } # ifdef ON_DEMAND_PROFILING /* Reset (only for CPU usage) runtime for next profiling period */ tskPtr->cumulativeRunTime = 0; # endif } /* For IDLE task */ /* --- Stack check */ start = (uint32_t)os_idle_TCB.stack; end = start + C_gOsStkSize; highWater = HighWaterMarkSearch( start, end ); /* --- CPU load */ taskLoad = ((osp_float_t)os_idle_TCB.cumulativeRunTime * 100.0f)/(osp_float_t)totalElapsedTime; # ifdef ON_DEMAND_PROFILING /* Reset (only for CPU usage) runtime for next profiling period */ os_idle_TCB.cumulativeRunTime = 0; gSystemRTCRefTime = RTC_GetCounter(); //Reset reference time # endif if (withStartEnd) { i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", "IDLE TASK", start, end, highWater, C_gOsStkSize, (highWater * 100)/C_gOsStkSize, taskLoad, os_idle_TCB.runCount); } else { i_printf("%16s: %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", "IDLE TASK", highWater, C_gOsStkSize, (highWater * 100)/C_gOsStkSize, taskLoad, os_idle_TCB.runCount); } /* Main stack check */ start = (uint32_t)&gStackMem; end = start + (uint32_t)&gStackSize; highWater = HighWaterMarkSearch( start, end ); if (withStartEnd) { i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t -*-\t -*-\r\n", "System Stack", start, end, highWater, (uint32_t)&gStackSize, (highWater * 100)/((uint32_t)&gStackSize)); } else { i_printf("%16s: %04ld/%04ld\t%d%%\t -*-\t -*-\r\n", "System Stack", highWater, (uint32_t)&gStackSize, (highWater * 100)/((uint32_t)&gStackSize)); } i_printf("------------------------------------------------------\r\n"); # endif }
LRESULT CBackEndDialog::OnActivateTask(WPARAM wParam, LPARAM lParam) { //get the text char* pszTaskName = (char*)wParam; //track the old task CTask* pOldTask = m_pCurrTask; //run through the list and find the task CTask* pCurr = m_pHeadTask; while(pCurr) { if(stricmp(pszTaskName, pCurr->GetName()) == 0) { m_pCurrTask = pCurr; break; } pCurr = pCurr->GetNextTask(); } //clean up the name now delete [] pszTaskName; pszTaskName = NULL; //see if we didn't find the task if(pCurr == NULL) { return false; } //set the active task name around the progress bar CStatic* pTaskName = (CStatic*)GetDlgItem(IDC_STATIC_TASK_NAME); CString sText; sText.Format("Task: %s", (m_pCurrTask) ? m_pCurrTask->GetName() : "None"); ((CStatic*)GetDlgItem(IDC_STATIC_TASK_NAME))->SetWindowText(sText); //also update the progress bar to reflect the change SetTaskProgress((m_pCurrTask) ? m_pCurrTask->GetProgress() : 0.0f); //if the user was viewing the previous task, then we want to start viewing the new //task, the same goes for if the user isn't viewing any tasks CTask* pViewedTask = GetViewedTask(); if((pOldTask == pViewedTask) || (pViewedTask == NULL)) { //find this new task for(uint32 nCurrTask = 0; nCurrTask < (uint32)GetTaskList()->GetCount(); nCurrTask++) { if((CTask*)GetTaskList()->GetItemData(nCurrTask) == m_pCurrTask) { //this is a match, select it GetTaskList()->SetCurSel(nCurrTask); ResetMessageList(); break; } } } //save this task as our current subtask m_sSubTaskName = (m_pCurrTask) ? m_pCurrTask->GetName() : ""; //update the title bar UpdateTitleNonIconic(); return 0; }
BOOL CBackEndDialog::OnInitDialog() { CDialog::OnInitDialog(); //setup the icon for this window SetIcon(m_hMainIcon, TRUE); // Set big icon SetIcon(m_hMainIcon, FALSE); // Set small icon //make it so that the OK button is hidden, it will be revealed again once the processing //is done ((CButton*)GetDlgItem(IDOK))->ModifyStyle(WS_VISIBLE, 0); //set up the save button to be invisible and have the disk icon ((CButton*)(GetDlgItem(IDC_BUTTON_SAVE_LOG)))->SetIcon(m_hSaveIcon); ((CButton*)GetDlgItem(IDC_BUTTON_SAVE_LOG))->ModifyStyle(WS_VISIBLE, 0); ((CButton*)(GetDlgItem(IDC_BUTTON_MESSAGE_OPTIONS)))->SetIcon(m_hOptionsIcon); //setup the progress bar CProgressCtrl* pProgress = ((CProgressCtrl*)GetDlgItem(IDC_PROGRESS_TASK)); pProgress->SetRange(0, 1000); //the base registry location CString sRegBase = PACKER_REGISTRY_DIRECTORY; //set the thread priority to normal uint32 nThreadPri = atoi(GetRegistryKey(HKEY_CURRENT_USER, sRegBase + "ThreadPri", "2")); ((CComboBox*)GetDlgItem(IDC_COMBO_THREAD_PRIORITY))->SetCurSel(nThreadPri); //set the message filter to show everything uint32 nFilter = atoi(GetRegistryKey(HKEY_CURRENT_USER, sRegBase + "Filter", "5")); ((CComboBox*)GetDlgItem(IDC_COMBO_MESSAGE_FILTER))->SetCurSel(nFilter); OnChangeMessageFilter(); //create the thread data g_ThreadData.m_sFilename = m_sFilename; g_ThreadData.m_pIPackerImpl = m_pIPackerImpl; g_ThreadData.m_pIPackerOutput = (IPackerOutput*)this; g_ThreadData.m_pPropList = m_pPropList; //load the options for the severities LoadSevOptionsFromReg(); //setup the tooltips m_ToolTip.Create(this); m_ToolTip.AddWindowTool(GetDlgItem(IDC_BUTTON_SAVE_LOG), IDS_TOOLTIP_SAVE_LOG); m_ToolTip.AddWindowTool(GetDlgItem(IDC_COMBO_THREAD_PRIORITY), IDS_TOOLTIP_THREAD_PRIORITY); m_ToolTip.AddWindowTool(GetDlgItem(IDC_COMBO_MESSAGE_FILTER), IDS_TOOLTIP_MESSAGE_FILTER); m_ToolTip.AddWindowTool(GetDlgItem(IDC_PROGRESS_TASK), IDS_TOOLTIP_TASK_PROGRESS); m_ToolTip.AddWindowTool(GetTaskList(), IDS_TOOLTIP_TASK_LIST); m_ToolTip.AddWindowTool(GetMessageList(), IDS_TOOLTIP_MESSAGE_LIST); m_ToolTip.AddWindowTool(GetDlgItem(IDC_BUTTON_MESSAGE_OPTIONS), IDS_TOOLTIP_MESSAGE_OPTIONS); //now we need to launch the background thread which will spawn the packer to do its //thing DWORD nThreadID; m_hThread = CreateThread(NULL, 0, LaunchPackerThreadMain, NULL, 0, &nThreadID); //now that the thread is created, we need to ensure that the proper priority is set //on it OnThreadPriorityChanged(); SetTimer(TIMER_EVENT_ID, 50, NULL); return TRUE; }