bool CaProfileWriter::writeProfileTotal(PidProcessMap * procMap) { AggregatedSample aggSamp; PidProcessMap::iterator pit = procMap->begin(); PidProcessMap::iterator pend = procMap->end(); for(; pit != pend; pit++) { aggSamp.addSamples((const AggregatedSample *)&(pit->second)); } fwprintf(m_pFile, L"TOTAL="); CA_SampleMap::const_iterator ait = aggSamp.getBeginSample(); CA_SampleMap::const_iterator aend = aggSamp.getEndSample(); while (ait != aend) { SampleKey key = ait->first; map<EVMASK_T, int>::iterator eit; if ((eit = m_evToIndexMap.find(key.event)) == m_evToIndexMap.end()) { m_err = E_INVALIDPROCESSMAP; return false; } fwprintf(m_pFile, L"[%u %d] %u", key.cpu, eit->second, ait->second); if (++ait != aend) fwprintf(m_pFile, L","); else fwprintf(m_pFile, L"\n"); } return true; }
bool CaProfileWriter::writeModLineData(CA_Module & mod, PID_T pid, const AggregatedSample & agSamp) { m_err = OK; if (!m_pFile) { m_err = E_OPENFAILED; return false; } if (m_stage != evOut_ModSummary) { m_err = E_UNKNOWN; return false; } // taskid fwprintf (m_pFile, L"%u", pid); // TOTALSAMPLE fwprintf (m_pFile, L",%llu", agSamp.getTotal()); // #EVENTSET fwprintf (m_pFile, L",%u",agSamp.getSampleMapSize()); // [CPU EVENT-INDEX] #SAMPLE CA_SampleMap::const_iterator it = agSamp.getBeginSample(); CA_SampleMap::const_iterator itEnd = agSamp.getEndSample(); for (; it != itEnd; it++) { SampleKey key = (*it).first; if ((*it).second) { map<EVMASK_T, int>::iterator eit; if ((eit = m_evToIndexMap.find(key.event)) == m_evToIndexMap.end()) { m_err = E_INVALIDMODULEMAP; return false; } fwprintf(m_pFile, L",[%u %d] %u", key.cpu, eit->second, (*it).second); } } // 32-bit-Flag fwprintf(m_pFile, L",%d", mod.m_is32Bit? 1 : 0); // module name fwprintf(m_pFile, L",%ls\n", (wchar_t*)(mod.getPath().c_str())); return true; }
// Convert an aggregated sample to data array gtUInt32 AggregateSamples(CpuProfileReader& profileReader, const AggregatedSample& sm, gtVector<gtUInt64>& dataVector, gtVector<gtUInt64>& totalVector, EventToIndexMap& evtToIdxMap, bool seperateByCore) { gtUInt32 total = 0; { CpuProfileSampleMap::const_iterator sampleIt = sm.getBeginSample(); CpuProfileSampleMap::const_iterator sampleItEnd = sm.getEndSample(); for (; sampleIt != sampleItEnd; ++sampleIt) { gtUInt32 sampleCount = sampleIt->second; total += sampleCount; // If separateByCore, then idx = (number-of-events * eventidx) // Given cpu/event select from profile, find column index: int index = GetIndexForEvent(evtToIdxMap, sampleIt->first.event); if (seperateByCore) { index *= profileReader.getProfileInfo()->m_numCpus; } // TODO: if ((index >= 0) && (index < (int)dataVector.size())) if (index >= 0) { // Aggregate total: totalVector[index] += sampleCount; dataVector[index] += sampleCount; } } } return total; }
bool SystemDataTab::displayProcessToPidToModule() { m_pList->setColumnText (SYS_MOD_NAME, "Process -> Pid -> Module"); m_nameProgItemMap.clear(); PidProcessMap::const_iterator pit = m_pProcMap->begin(); PidProcessMap::const_iterator pend = m_pProcMap->end(); for(; pit != pend; pit++) { SystemItem * pProgItem = NULL; AggregatedSample * pProgAgg = NULL; NameProgramItemMap::iterator nit = m_nameProgItemMap.find(pit->second.getPath()); if (nit == m_nameProgItemMap.end()) { ProgramItem progItem; progItem.pProg = new SystemItem(m_pViewShown, SYS_OFFSET_INDEX, m_pList); RETURN_FALSE_IF_NULL (progItem.pProg, this); m_nameProgItemMap.insert( NameProgramItemMap::value_type(pit->second.getPath(), progItem)); // Refind nit = m_nameProgItemMap.find(pit->second.getPath()); if (nit == m_nameProgItemMap.end()) return false; pProgItem = nit->second.pProg; pProgAgg = &(nit->second.progAgg); // Set Process Name pProgItem->setText (SYS_MOD_NAME, wstrToQStr(pit->second.getPath())); // Set SixtyFourBit if (!pit->second.m_is32Bit) pProgItem->setChecked (SYS_64_BIT); else pProgItem->setChecked (-1); pProgAgg->clear(); } else { pProgItem = nit->second.pProg; pProgAgg = &(nit->second.progAgg); } SystemItem * pPidItem = new SystemItem(m_pViewShown, SYS_OFFSET_INDEX, pProgItem); RETURN_FALSE_IF_NULL (pPidItem, this); // Set Process Name pPidItem->setText (SYS_MOD_NAME, QString("PID : ") + QString::number(pit->first)); // Set SixtyFourBit if (!pit->second.m_is32Bit) pPidItem->setChecked (SYS_64_BIT); else pPidItem->setChecked (-1); pPidItem->m_taskId = pit->first; AggregatedSample pidAgg; // For each module NameModuleMap::const_iterator mit = m_pModMap->begin(); NameModuleMap::const_iterator mend = m_pModMap->end(); for(; mit != mend; mit++) { // Find PID PidAggregatedSampleMap::const_iterator ait = mit->second.findSampleForPid(pit->first); if(ait == mit->second.getEndSample()) continue; SystemItem * pModItem = new SystemItem(m_pViewShown, SYS_OFFSET_INDEX, pPidItem); RETURN_FALSE_IF_NULL (pModItem, this); // Set Module Name pModItem->setText (SYS_MOD_NAME, wstrToQStr(mit->first)); // Set Module for the process item if (mit->first == pit->second.getPath()) pProgItem->m_pMod = &(mit->second); pModItem->m_pMod = &(mit->second); pModItem->m_taskId = ait->first; // Set Module Data pModItem->setTotal(&m_totalAgg); pModItem->drawData(&(ait->second), true); pModItem->updateShown (); pModItem->setBackgroundColor(Qt::lightGray); pidAgg.addSamples(&(ait->second)); } // for each module // Set Pid Data pPidItem->setTotal(&m_totalAgg); pPidItem->drawData(&(pidAgg), true); pPidItem->updateShown (); // Set Program Data pProgAgg->addSamples(&(pidAgg)); pProgItem->setTotal(&m_totalAgg); pProgItem->drawData(pProgAgg, true); pProgItem->updateShown (); } // for each pid return TRUE; }
bool SystemDataTab::displayModuleToProcess() { m_pList->setColumnText (SYS_MOD_NAME, "Module -> Process"); // For each module NameModuleMap::const_iterator mit = m_pModMap->begin(); NameModuleMap::const_iterator mend = m_pModMap->end(); for(; mit != mend; mit++) { SystemItem * pModItem = new SystemItem(m_pViewShown, SYS_OFFSET_INDEX, m_pList); RETURN_FALSE_IF_NULL (pModItem, this); // Set Module Name pModItem->setText (SYS_MOD_NAME, wstrToQStr(mit->first)); // Set SixtyFourBit if (!mit->second.m_is32Bit) pModItem->setChecked (SYS_64_BIT); else pModItem->setChecked (-1); // Set Module pModItem->m_pMod = &(mit->second); pModItem->m_taskId = SHOW_ALL_TASKS; AggregatedSample modAgg; // For each Pid PidAggregatedSampleMap::const_iterator ait = mit->second.getBeginSample(); PidAggregatedSampleMap::const_iterator aend = mit->second.getEndSample(); for(; ait != aend; ait++) { SystemItem * pProcItem = new SystemItem(m_pViewShown, SYS_OFFSET_INDEX, pModItem); RETURN_FALSE_IF_NULL (pProcItem, this); // Set Process Name pProcItem->setText (SYS_MOD_NAME, getProcNameForPid(ait) + " (" + QString::number(ait->first) + ")"); // Set Module pProcItem->m_pMod = &(mit->second); pProcItem->m_taskId = ait->first; // Set Process Data pProcItem->setTotal(&m_totalAgg); pProcItem->drawData(&(ait->second), true); pProcItem->updateShown (); pProcItem->setBackgroundColor(Qt::lightGray); modAgg.addSamples(&(ait->second)); } // Set Module Data pModItem->setTotal(&m_totalAgg); pModItem->drawData(&(modAgg), true); pModItem->updateShown (); } return TRUE; }