public SampleBuffer(uint size) { //mSize = size; //mSize if (size >= 999) { mSize = size; } mDecodedSamples = new BRetiredProfileSample[mSize]; for (int i = 0; i < mSize; i++) { mDecodedSamples[i] = new BRetiredProfileSample(); } }
public void ProcessSample(BRetiredProfileSample sample, int sampleID) { //Calculate a few stats as we go... if ((sample.mGPUStartTime != 0) && (mbHasGPUSamples == false)) { mbHasGPUSamples = true; mFirstGPUSampleIndex = (uint)sampleID; } else if (sample.mGPUStartTime != 0) { mbHasGPUSamples = true; mLastGPUSampleIndex = (uint)sampleID; } if (sample.mLevel > mMaxStackHeight) { mMaxStackHeight = sample.mLevel; } if (sample.mUserID >= 0 && sample.mUserID < 6) { mCPUsUsed[sample.mUserID] = true; mCPUID = (int)sample.mUserID; } else { throw new Exception("invalid cpu id:" + sample.mUserID); } mSectionStats[sample.mSectionID] += (uint)(sample.mCPUEndTime - sample.mCPUEndTime); mSectionStatsGpu[sample.mSectionID] += (uint)(sample.mGPUEndTime - sample.mGPUEndTime); if (sample.mSectionID == 8) { mCPUID = mCPUID + 0; } }
// false on failure //template<typename BitPackerType> public bool decodeSample(BitPacker bitPacker, ref BRetiredProfileSample decodedSample, /*const*/ /*BAlignedArray<const BProfileSection*>&*/ BProfileSection[] sections) { if (sections == null) { ErrorHandler.Error("Can't decompress frame, sections == null!"); return(false); } uint sectionID; if (-1 == mPrevLevel) { if (!mCoder.decodeOmega(ref bitPacker, out sectionID)) { return(false); } } else { int sectionIDDelta; if (!mCoder.decodeOmegaSigned(ref bitPacker, out sectionIDDelta)) { return(false); } sectionID = /*static_cast<BSectionID>*/ (ushort)(sectionIDDelta + mSectionPredDataArray[mPrevSectionID].mNextSectionID); } decodedSample.mSectionID = /*static_cast<BSectionID>*/ (ushort)(sectionID); // Sanity check, we should never have more than a few hundred sections! if (sectionID >= 512) { return(false); } if (sectionID >= size(mSectionPredDataArray)) { resize(ref mSectionPredDataArray, (int)sectionID + 100);//the current resize operation is slow... } // if this fails the passed in section array wasn't completely up to date if (sectionID >= size(sections)) { return(false); } bool cpuOnly = false; if (sections[sectionID] != null) { /*const*/ cpuOnly = sections[sectionID].cpuOnly(); } uint /*BCoderTime*/ cpuStartTime = 0; uint /*BCoderTime*/ cpuEndTime; uint /*BCoderTime*/ cpuDuration; uint /*BCoderTime*/ gpuStartTime = 0; uint /*BCoderTime*/ gpuEndTime = 0; uint /*BCoderTime*/ gpuDuration = 0; if (-1 == mPrevLevel) { uint level; if (!mCoder.decodeOmega(ref bitPacker, out level)) { return(false); } decodedSample.mLevel = /*static_cast<uchar>*/ (byte)(level); // sanity check if (level >= 128) { return(false); } if (!mCoder.decodeOmega(ref bitPacker, out decodedSample.mUserID)) { return(false); } if (!bitPacker.decode(out cpuStartTime, 32)) { return(false); } if (!bitPacker.decode(out cpuEndTime, 32)) { return(false); } if (!cpuOnly) { if (!bitPacker.decode(out gpuStartTime, 32)) { return(false); } if (!bitPacker.decode(out gpuEndTime, 32)) { return(false); } } cpuDuration = cpuEndTime - cpuStartTime; gpuDuration = gpuEndTime - gpuStartTime; } else { int levelDelta; if (!mCoder.decodeOmegaSigned(ref bitPacker, out levelDelta)) { return(false); } decodedSample.mLevel = /*static_cast<uchar>*/ (byte)(levelDelta + mPrevLevel); // Decode user ID - almost always 0, so read a single bit to determine if we need to omega decode the delta. int userIDDelta = 0; uint userIDDeltaNonZeroFlag; if (!bitPacker.decode(out userIDDeltaNonZeroFlag, 1)) { return(false); } if (userIDDeltaNonZeroFlag > 0) { if (!mCoder.decodeOmegaSigned(ref bitPacker, out userIDDelta)) { return(false); } } decodedSample.mUserID = (uint)(userIDDelta + mPrevUserID); // Decode the CPU start time. uint predStartCPUTime = mPrevCPUEndTime; if (decodedSample.mLevel > mPrevLevel) { predStartCPUTime = mPrevCPUStartTime; } uint deltaStartCPUTime; if (!mCoder.decodeOmega(ref bitPacker, out deltaStartCPUTime)) { return(false); } cpuStartTime = deltaStartCPUTime + mPrevCPUStartTime; // Decode the CPU duration. int deltaCPUDuration; if (!mCoder.decodeOmegaSigned(ref bitPacker, out deltaCPUDuration)) { return(false); } cpuDuration = (uint)(deltaCPUDuration + mSectionPredDataArray[sectionID].mPrevCPUDuration); cpuEndTime = cpuStartTime + cpuDuration; if (!cpuOnly) { // Decode the GPU start time. uint predStartGPUTime = mPrevGPUEndTime; if (decodedSample.mLevel > mPrevLevel) { predStartGPUTime = mPrevGPUStartTime; } uint deltaStartGPUTime; if (!mCoder.decodeOmega(ref bitPacker, out deltaStartGPUTime)) { return(false); } gpuStartTime = deltaStartGPUTime + mPrevGPUStartTime; // Decode the GPU end time. int deltaGPUDuration; if (!mCoder.decodeOmegaSigned(ref bitPacker, out deltaGPUDuration)) { return(false); } gpuDuration = (uint)(deltaGPUDuration + mSectionPredDataArray[sectionID].mPrevGPUDuration); gpuEndTime = gpuStartTime + gpuDuration; } } // Update the model - only record those things we need for speed mSectionPredDataArray[sectionID].mPrevCPUDuration = cpuDuration; mSectionPredDataArray[sectionID].mPrevGPUDuration = gpuDuration; mSectionPredDataArray[mPrevSectionID].mNextSectionID = sectionID; mPrevLevel = decodedSample.mLevel; mPrevUserID = decodedSample.mUserID; mPrevCPUStartTime = cpuStartTime; mPrevCPUEndTime = cpuEndTime; mPrevGPUStartTime = gpuStartTime; mPrevGPUEndTime = gpuEndTime; mPrevSectionID = sectionID; decodedSample.mCPUStartTime = cpuStartTime; decodedSample.mCPUEndTime = cpuEndTime; decodedSample.mGPUStartTime = 0; decodedSample.mGPUEndTime = 0; if (!cpuOnly) { decodedSample.mGPUStartTime = gpuStartTime; decodedSample.mGPUEndTime = gpuEndTime; } return(true); }
public void BuildDutyCycle(ref BRetiredProfileSample[] samples, uint numSamples, bool bGPU) { if ((mSegmentList.Count != 0) || (samples.Length == 0)) { return; } BRetiredProfileSample s = null; Line1D currentLine = null; uint sampleStart; uint sampleEnd; for (int sampleID = 0; sampleID < numSamples; sampleID++) { s = samples[sampleID]; if (bGPU == true) { sampleStart = s.mGPUStartTime; sampleEnd = s.mGPUEndTime; if ((sampleStart == sampleEnd) || (sampleEnd == 0)) { continue; } } else { sampleStart = s.mCPUStartTime; sampleEnd = s.mCPUEndTime; } if (currentLine == null) { currentLine = new Line1D(sampleStart, sampleEnd); mSegmentList.Add(currentLine); } else if (currentLine.Contains(sampleStart) == 0) { if (currentLine.Contains(sampleEnd) == 0) { continue; } else { currentLine.mEnd = sampleEnd; continue; } } else { if (currentLine.Contains(sampleStart) < 0) { mOutOfOrderCount++; //throw new Exception("samples out of order"); } mUnusedTime += (sampleStart - currentLine.mEnd); currentLine = new Line1D(sampleStart, sampleEnd); mSegmentList.Add(currentLine); } } }
// false on failure //template<typename BitPackerType> public bool codeSample(BitPacker bitPacker, /*const*/ ref BRetiredProfileSample sample, /*const*/ ref BProfileSection pSection) { if (sample.mSectionID >= size(mSectionPredDataArray)) { resize(ref mSectionPredDataArray, sample.mSectionID + 1); } /*const*/ uint /*BCoderTime*/ cpuStartTime = sample.mCPUStartTime; /*const*/ uint /*BCoderTime*/ cpuEndTime = sample.mCPUEndTime; uint /*BCoderTime*/ gpuStartTime = 0; uint /*BCoderTime*/ gpuEndTime = 0; if (!pSection.cpuOnly()) { gpuStartTime = sample.mGPUStartTime; gpuEndTime = sample.mGPUEndTime; } uint /*BCoderTime*/ cpuDuration = cpuEndTime - cpuStartTime; uint /*BCoderTime*/ gpuDuration = gpuEndTime - gpuStartTime; if (-1 == mPrevLevel) { if (!mCoder.encodeOmega(ref bitPacker, sample.mSectionID)) { return(false); } // Model is empty - send uncompressed sample if (!mCoder.encodeOmega(ref bitPacker, sample.mLevel)) { return(false); } if (!mCoder.encodeOmega(ref bitPacker, sample.mUserID)) { return(false); } if (!bitPacker.encode(cpuStartTime, 32)) { return(false); } if (!bitPacker.encode(cpuEndTime, 32)) { return(false); } if (!pSection.cpuOnly()) { if (!bitPacker.encode(gpuStartTime, 32)) { return(false); } if (!bitPacker.encode(gpuEndTime, 32)) { return(false); } } } else { // Compress sample // Code the section ID delta int sectionIDDelta = (int)(sample.mSectionID - mSectionPredDataArray[mPrevSectionID].mNextSectionID); if (!mCoder.encodeOmegaSigned(ref bitPacker, sectionIDDelta)) { return(false); } // Code the level delta using 1 or 2 bits [-1, 0, or 1] /*const*/ int levelDelta = sample.mLevel - mPrevLevel; if (!mCoder.encodeOmegaSigned(ref bitPacker, levelDelta)) { return(false); } /*const*/ int userIDDelta = (int)(sample.mUserID - mPrevUserID); if (userIDDelta == 0) { // Encode single bit to represent userIDDelta == 0. if (!bitPacker.encode((uint)(0), (int)(1))) { return(false); } } else { if (!bitPacker.encode((uint)(1), (int)(1))) { return(false); } if (!mCoder.encodeOmegaSigned(ref bitPacker, userIDDelta)) { return(false); } } uint predStartCPUTime = mPrevCPUEndTime; if (sample.mLevel > mPrevLevel) { predStartCPUTime = mPrevCPUStartTime; } //BDEBUG_ASSERT(predStartCPUTime <= cpuStartTime); /*const*/ uint deltaStartCPUTime = cpuStartTime - mPrevCPUStartTime; if (!mCoder.encodeOmega(ref bitPacker, deltaStartCPUTime)) { return(false); } /*const*/ int deltaCPUDuration = (int)(cpuDuration - mSectionPredDataArray[sample.mSectionID].mPrevCPUDuration); if (!mCoder.encodeOmegaSigned(ref bitPacker, deltaCPUDuration)) { return(false); } if (!pSection.cpuOnly()) { uint predStartGPUTime = mPrevGPUEndTime; if (sample.mLevel > mPrevLevel) { predStartGPUTime = mPrevGPUStartTime; } if (!sample.hasGPUTimes()) { // this should be very rare-- only when the gpu samples time out // we don't want to try encoding a negative start gpu time delta // instead, ensure the gpu times are both equal, which means the sample is invalid gpuStartTime = predStartGPUTime; gpuEndTime = predStartGPUTime; gpuDuration = 0; } //BDEBUG_ASSERT(predStartGPUTime <= gpuStartTime); /*const*/ uint deltaStartGPUTime = gpuStartTime - mPrevGPUStartTime; if (!mCoder.encodeOmega(ref bitPacker, deltaStartGPUTime)) { return(false); } /*const*/ int deltaGPUDuration = (int)(gpuDuration - mSectionPredDataArray[sample.mSectionID].mPrevGPUDuration); if (!mCoder.encodeOmegaSigned(ref bitPacker, deltaGPUDuration)) { return(false); } } } // Update the model - only record those things we need for speed mSectionPredDataArray[sample.mSectionID].mPrevCPUDuration = cpuDuration; mSectionPredDataArray[sample.mSectionID].mPrevGPUDuration = gpuDuration; mSectionPredDataArray[mPrevSectionID].mNextSectionID = sample.mSectionID; mPrevLevel = sample.mLevel; mPrevUserID = sample.mUserID; mPrevSectionID = sample.mSectionID; mPrevCPUStartTime = cpuStartTime; mPrevCPUEndTime = cpuEndTime; mPrevGPUStartTime = gpuStartTime; mPrevGPUEndTime = gpuEndTime; return(true); }