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; }