/* DISKSPD Copyright(c) Microsoft Corporation All rights reserved. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "xmlresultparser.h" // TODO: refactor to a single function shared with the ResultParser char printBuffer[4096] = {}; /// for CrystalDiskMark int XmlResultParser::GetTotalScore() { return 0; } double XmlResultParser::GetAverageLatency() { return 0.0; } void XmlResultParser::_PrintV(const char *format, va_list listArg) { _sResult.append(_indent, ' '); vsprintf_s(printBuffer, _countof(printBuffer), format, listArg); _sResult += printBuffer; } void XmlResultParser::_Print(const char *format, ...) { assert(nullptr != format); va_list listArg; va_start(listArg, format); _PrintV(format, listArg); va_end(listArg); } void XmlResultParser::_PrintInc(const char *format, ...) { assert(nullptr != format); va_list listArg; va_start(listArg, format); // Print & Increment Indent // e.g., _PrintV(format, listArg); _indent += 2; va_end(listArg); } void XmlResultParser::_PrintDec(const char *format, ...) { assert(nullptr != format); va_list listArg; va_start(listArg, format); // Decrement Indent & Print // e.g., _indent -= 2; _PrintV(format, listArg); va_end(listArg); } void XmlResultParser::_PrintTargetResults(const TargetResults& results) { // TODO: results.readBucketizer; // TODO: results.writeBucketizer; _Print("%s\n", results.sPath.c_str()); _Print("%I64u\n", results.ullBytesCount); _Print("%I64u\n", results.ullFileSize); _Print("%I64u\n", results.ullIOCount); _Print("%I64u\n", results.ullReadBytesCount); _Print("%I64u\n", results.ullReadIOCount); _Print("%I64u\n", results.ullWriteBytesCount); _Print("%I64u\n", results.ullWriteIOCount); if (results.vDistributionRange.size()) { _PrintInc("\n"); _PrintInc("\n"); // // Render hole(s) in effective distribution. Keep track of the expected base // of the next range and render a hole (IO = 0) over the gap as needed. // UINT64 expectBase = 0; for (auto& r : results.vDistributionRange) { if (r._dst.first != expectBase) { _Print("%I64u\n", 0, r._dst.first - expectBase); } _Print("%I64u\n", r._span, r._dst.second); expectBase = r._dst.first + r._dst.second; } _PrintDec("\n"); _PrintDec("\n"); } } void XmlResultParser::_PrintTargetLatency(const TargetResults& results) { if (results.readLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", results.readLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", results.readLatencyHistogram.GetStandardDeviation() / 1000); } if (results.writeLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", results.writeLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", results.writeLatencyHistogram.GetStandardDeviation() / 1000); } Histogram totalLatencyHistogram; totalLatencyHistogram.Merge(results.readLatencyHistogram); totalLatencyHistogram.Merge(results.writeLatencyHistogram); if (totalLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", totalLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", totalLatencyHistogram.GetStandardDeviation() / 1000); } } void XmlResultParser::_PrintTargetIops(const IoBucketizer& readBucketizer, const IoBucketizer& writeBucketizer, UINT32 bucketTimeInMs) { _PrintInc("\n"); IoBucketizer totalIoBucketizer; totalIoBucketizer.Merge(readBucketizer); totalIoBucketizer.Merge(writeBucketizer); if (readBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", readBucketizer.GetStandardDeviationIOPS() / (bucketTimeInMs / 1000.0)); } if (writeBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", writeBucketizer.GetStandardDeviationIOPS() / (bucketTimeInMs / 1000.0)); } if (totalIoBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", totalIoBucketizer.GetStandardDeviationIOPS() / (bucketTimeInMs / 1000.0)); } _PrintIops(readBucketizer, writeBucketizer, bucketTimeInMs); _PrintDec("\n"); } void XmlResultParser::_PrintETWSessionInfo(struct ETWSessionInfo sessionInfo) { _PrintInc("\n"); _Print("%lu\n", sessionInfo.ulBufferSize); _Print("%lu\n", sessionInfo.ulMinimumBuffers); _Print("%lu\n", sessionInfo.ulMaximumBuffers); _Print("%lu", sessionInfo.ulFreeBuffers); _Print("%lu\n", sessionInfo.ulBuffersWritten); _Print("%lu\n", sessionInfo.ulFlushTimer); _Print("%d\n", sessionInfo.lAgeLimit); _Print("%lu\n", sessionInfo.ulNumberOfBuffers); _Print("%lu\n", sessionInfo.ulEventsLost); _Print("%lu\n", sessionInfo.ulLogBuffersLost); _Print("%lu\n", sessionInfo.ulRealTimeBuffersLost); _PrintDec("\n"); } void XmlResultParser::_PrintETW(struct ETWMask ETWMask, struct ETWEventCounters EtwEventCounters) { _PrintInc("\n"); if (ETWMask.bDiskIO) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullIORead); _Print("%I64u\n", EtwEventCounters.ullIOWrite); _PrintDec("\n"); } if (ETWMask.bImageLoad) { _Print("%I64u\n", EtwEventCounters.ullImageLoad); } if (ETWMask.bMemoryPageFaults) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullMMCopyOnWrite); _Print("%I64u\n", EtwEventCounters.ullMMDemandZeroFault); _Print("%I64u\n", EtwEventCounters.ullMMGuardPageFault); _Print("%I64u\n", EtwEventCounters.ullMMHardPageFault); _Print("%I64u\n", EtwEventCounters.ullMMTransitionFault); _PrintDec("\n"); } if (ETWMask.bMemoryHardFaults && !ETWMask.bMemoryPageFaults) { _Print("%I64u\n", EtwEventCounters.ullMMHardPageFault); } if (ETWMask.bNetwork) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullNetAccept); _Print("%I64u\n", EtwEventCounters.ullNetConnect); _Print("%I64u\n", EtwEventCounters.ullNetDisconnect); _Print("%I64u\n", EtwEventCounters.ullNetReconnect); _Print("%I64u\n", EtwEventCounters.ullNetRetransmit); _Print("%I64u\n", EtwEventCounters.ullNetTcpSend); _Print("%I64u\n", EtwEventCounters.ullNetTcpReceive); _Print("%I64u\n", EtwEventCounters.ullNetUdpSend); _Print("%I64u\n", EtwEventCounters.ullNetUdpReceive); _PrintDec("\n"); } if (ETWMask.bProcess) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullProcessStart); _Print("%I64u\n", EtwEventCounters.ullProcessEnd); _PrintDec("\n"); } if (ETWMask.bRegistry) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullRegCreate); _Print("%I64u\n", EtwEventCounters.ullRegDelete); _Print("%I64u\n", EtwEventCounters.ullRegDeleteValue); _Print("%I64u\n", EtwEventCounters.ullRegEnumerateKey); _Print("%I64u\n", EtwEventCounters.ullRegEnumerateValueKey); _Print("%I64u\n", EtwEventCounters.ullRegFlush); _Print("%I64u\n", EtwEventCounters.ullRegOpen); _Print("%I64u\n", EtwEventCounters.ullRegQuery); _Print("%I64u\n", EtwEventCounters.ullRegQueryMultipleValue); _Print("%I64u\n", EtwEventCounters.ullRegQueryValue); _Print("%I64u\n", EtwEventCounters.ullRegSetInformation); _Print("%I64u\n", EtwEventCounters.ullRegSetValue); _PrintDec("\n"); } if (ETWMask.bThread) { _PrintInc("\n"); _Print("%I64u\n", EtwEventCounters.ullThreadStart); _Print("%I64u\n", EtwEventCounters.ullThreadEnd); _PrintDec("\n"); } _PrintDec("\n"); } void XmlResultParser::_PrintCpuUtilization(const Results& results, const SystemInformation& system) { const auto& topo = system.processorTopology; size_t procCount = results.vSystemProcessorPerfInfo.size(); size_t baseProc = 0; BYTE efficiencyClass = 0; BYTE processorCore = 0; _PrintInc("\n"); double busyTime = 0; double totalIdleTime = 0; double totalUserTime = 0; double totalKrnlTime = 0; for (const auto& group : topo._vProcessorGroupInformation) { // Sanity assert - results are sized to the sum of active processors assert(baseProc + group._activeProcessorCount <= procCount); for (BYTE processor = 0; processor < group._activeProcessorCount; processor++) { long long fTime = results.vSystemProcessorPerfInfo[baseProc + processor].KernelTime.QuadPart + results.vSystemProcessorPerfInfo[baseProc + processor].UserTime.QuadPart; double idleTime = 100.0 * results.vSystemProcessorPerfInfo[baseProc + processor].IdleTime.QuadPart / fTime; double krnlTime = 100.0 * results.vSystemProcessorPerfInfo[baseProc + processor].KernelTime.QuadPart / fTime; double userTime = 100.0 * results.vSystemProcessorPerfInfo[baseProc + processor].UserTime.QuadPart / fTime; double usedTime = (krnlTime - idleTime) + userTime; _PrintInc("\n"); _Print("%d\n", topo.GetSocketOfProcessor(group._groupNumber, processor)); _Print("%d\n", topo.GetNumaOfProcessor(group._groupNumber, processor)); _Print("%d\n", group._groupNumber); processorCore = topo.GetCoreOfProcessor(group._groupNumber, processor, efficiencyClass); _Print("%d\n", processorCore); _Print("%d\n", efficiencyClass); _Print("%d\n", processor); _Print("%.2f\n", usedTime); _Print("%.2f\n", userTime); _Print("%.2f\n", krnlTime - idleTime); _Print("%.2f\n", idleTime); _PrintDec("\n"); busyTime += usedTime; totalIdleTime += idleTime; totalUserTime += userTime; totalKrnlTime += krnlTime; } baseProc += group._activeProcessorCount; } assert(baseProc == procCount); _PrintInc("\n"); _Print("%.2f\n", busyTime / procCount); _Print("%.2f\n", totalUserTime / procCount); _Print("%.2f\n", (totalKrnlTime - totalIdleTime) / procCount); _Print("%.2f\n", totalIdleTime / procCount); _PrintDec("\n"); _PrintDec("\n"); } // emit the iops time series (this obviates needing perfmon counters, in common cases, and provides file level data) void XmlResultParser::_PrintIops(const IoBucketizer& readBucketizer, const IoBucketizer& writeBucketizer, UINT32 bucketTimeInMs) { bool done = false; for (size_t i = 0; !done; i++) { done = true; double r = 0.0; double r_min = 0.0; double r_max = 0.0; double r_avg = 0.0; double r_stddev = 0.0; double w = 0.0; double w_min = 0.0; double w_max = 0.0; double w_avg = 0.0; double w_stddev = 0.0; if (readBucketizer.GetNumberOfValidBuckets() > i) { r = readBucketizer.GetIoBucketCount(i) / (bucketTimeInMs / 1000.0); r_min = readBucketizer.GetIoBucketMinDurationUsec(i) / 1000.0; r_max = readBucketizer.GetIoBucketMaxDurationUsec(i) / 1000.0; r_avg = readBucketizer.GetIoBucketAvgDurationUsec(i) / 1000.0; r_stddev = readBucketizer.GetIoBucketDurationStdDevUsec(i) / 1000.0; done = false; } if (writeBucketizer.GetNumberOfValidBuckets() > i) { w = writeBucketizer.GetIoBucketCount(i) / (bucketTimeInMs / 1000.0); w_min = writeBucketizer.GetIoBucketMinDurationUsec(i) / 1000.0; w_max = writeBucketizer.GetIoBucketMaxDurationUsec(i) / 1000.0; w_avg = writeBucketizer.GetIoBucketAvgDurationUsec(i) / 1000.0; w_stddev = writeBucketizer.GetIoBucketDurationStdDevUsec(i) / 1000.0; done = false; } if (!done) { _Print("\n", bucketTimeInMs*(i + 1), r, w, r + w, r_min, r_max, r_avg, r_stddev, w_min, w_max, w_avg, w_stddev); } } } void XmlResultParser::_PrintOverallIops(const Results& results, UINT32 bucketTimeInMs) { IoBucketizer readBucketizer; IoBucketizer writeBucketizer; for (const auto& thread : results.vThreadResults) { for (const auto& target : thread.vTargetResults) { readBucketizer.Merge(target.readBucketizer); writeBucketizer.Merge(target.writeBucketizer); } } _PrintTargetIops(readBucketizer, writeBucketizer, bucketTimeInMs); } void XmlResultParser::_PrintLatencyPercentiles(const Results& results) { Histogram readLatencyHistogram; Histogram writeLatencyHistogram; Histogram totalLatencyHistogram; for (const auto& thread : results.vThreadResults) { for (const auto& target : thread.vTargetResults) { readLatencyHistogram.Merge(target.readLatencyHistogram); writeLatencyHistogram.Merge(target.writeLatencyHistogram); totalLatencyHistogram.Merge(target.writeLatencyHistogram); totalLatencyHistogram.Merge(target.readLatencyHistogram); } } _PrintInc("\n", readLatencyHistogram.GetSampleBuckets(), writeLatencyHistogram.GetSampleBuckets(), totalLatencyHistogram.GetSampleBuckets()); if (readLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", readLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", readLatencyHistogram.GetStandardDeviation() / 1000); } if (writeLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", writeLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", writeLatencyHistogram.GetStandardDeviation() / 1000); } if (totalLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", totalLatencyHistogram.GetAvg() / 1000); _Print("%.3f\n", totalLatencyHistogram.GetStandardDeviation() / 1000); } _PrintInc("\n"); _Print("0\n"); if (readLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", readLatencyHistogram.GetMin() / 1000); } if (writeLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", writeLatencyHistogram.GetMin() / 1000); } if (totalLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", totalLatencyHistogram.GetMin() / 1000); } _PrintDec("\n"); // Construct vector of percentiles and decimal precision to squelch trailing zeroes. This is more // detailed than summary text output, and does not contain the decorated names (15th, etc.) vector> vPercentiles; for (int p = 1; p <= 99; p++) { vPercentiles.push_back(make_pair(0, p)); } vPercentiles.push_back(make_pair(1, 99.9)); vPercentiles.push_back(make_pair(2, 99.99)); vPercentiles.push_back(make_pair(3, 99.999)); vPercentiles.push_back(make_pair(4, 99.9999)); vPercentiles.push_back(make_pair(5, 99.99999)); vPercentiles.push_back(make_pair(6, 99.999999)); vPercentiles.push_back(make_pair(7, 99.9999999)); for (auto p : vPercentiles) { _PrintInc("\n"); _Print("%.*f\n", p.first, p.second); if (readLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", readLatencyHistogram.GetPercentile(p.second / 100) / 1000); } if (writeLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", writeLatencyHistogram.GetPercentile(p.second / 100) / 1000); } if (totalLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", totalLatencyHistogram.GetPercentile(p.second / 100) / 1000); } _PrintDec("\n"); } _PrintInc("\n"); _Print("100\n"); if (readLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", readLatencyHistogram.GetMax() / 1000); } if (writeLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", writeLatencyHistogram.GetMax() / 1000); } if (totalLatencyHistogram.GetSampleSize() > 0) { _Print("%.3f\n", totalLatencyHistogram.GetMax() / 1000); } _PrintDec("\n"); _PrintDec("\n"); } string XmlResultParser::ParseProfile(const Profile& profile) { _sResult = profile.GetXml(0); return _sResult; } void XmlResultParser::_PrintWaitStats(const ThreadResults &threadResult) { _PrintInc("\n"); _Print("%llu\n", threadResult.WaitStats.Wait); _Print("%llu\n", threadResult.WaitStats.ThrottleWait); _Print("%llu\n", threadResult.WaitStats.ThrottleSleep); _Print("%llu\n", threadResult.WaitStats.Lookaside); _Print("%llu %llu %llu %llu %llu %llu %llu %llu\n", threadResult.WaitStats.LookasideCompletion[0], threadResult.WaitStats.LookasideCompletion[1], threadResult.WaitStats.LookasideCompletion[2], threadResult.WaitStats.LookasideCompletion[3], threadResult.WaitStats.LookasideCompletion[4], threadResult.WaitStats.LookasideCompletion[5], threadResult.WaitStats.LookasideCompletion[6], threadResult.WaitStats.LookasideCompletion[7]); _PrintDec("\n"); } string XmlResultParser::ParseResults(const Profile& profile, const SystemInformation& system, vector vResults) { _sResult.clear(); _PrintInc("\n"); _sResult += system.GetXml(_indent); _sResult += profile.GetXml(_indent); for (size_t iResults = 0; iResults < vResults.size(); iResults++) { const Results& results = vResults[iResults]; const TimeSpan& timeSpan = profile.GetTimeSpans()[iResults]; _PrintInc("\n"); double fTime = PerfTimer::PerfTimeToSeconds(results.ullTimeCount); //test duration if (fTime >= 0.0000001) { // There either is a fixed number of threads for all files to share (GetThreadCount() > 0) or a number of threads per file. // In the latter case vThreadResults.size() == number of threads per file * file count size_t ulThreadCnt = (timeSpan.GetThreadCount() > 0) ? timeSpan.GetThreadCount() : results.vThreadResults.size(); _Print("%.2f\n", fTime); _Print("%u\n", ulThreadCnt); _Print("%u\n", timeSpan.GetRequestCount()); _Print("%u\n", system.processorTopology._ulProcessorCount); _PrintCpuUtilization(results, system); if (timeSpan.GetMeasureLatency()) { _PrintLatencyPercentiles(results); } if (timeSpan.GetCalculateIopsStdDev()) { _PrintOverallIops(results, timeSpan.GetIoBucketDurationInMilliseconds()); } if (results.fUseETW) { _PrintETW(results.EtwMask, results.EtwEventCounters); _PrintETWSessionInfo(results.EtwSessionInfo); } for (size_t iThread = 0; iThread < results.vThreadResults.size(); iThread++) { const ThreadResults& threadResults = results.vThreadResults[iThread]; _PrintInc("\n"); _Print("%u\n", iThread); for (const auto& targetResults : threadResults.vTargetResults) { _PrintInc("\n"); _PrintTargetResults(targetResults); if (timeSpan.GetMeasureLatency()) { _PrintTargetLatency(targetResults); } if (timeSpan.GetCalculateIopsStdDev()) { _PrintTargetIops(targetResults.readBucketizer, targetResults.writeBucketizer, timeSpan.GetIoBucketDurationInMilliseconds()); } _PrintDec("\n"); } if (profile.GetVerboseStats()) { _PrintWaitStats(threadResults); } _PrintDec("\n"); } } else { _Print("The test was interrupted before the measurements began. No results are displayed.\n"); } _PrintDec("\n"); } _PrintDec(""); return _sResult; }