/* 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 void XmlResultParser::_Print(const char *format, ...) { assert(nullptr != format); va_list listArg; va_start(listArg, format); char buffer[4096] = {}; vsprintf_s(buffer, _countof(buffer), format, listArg); va_end(listArg); _sResult += buffer; } 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); } 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) { _Print("\n"); IoBucketizer totalIoBucketizer; totalIoBucketizer.Merge(readBucketizer); totalIoBucketizer.Merge(writeBucketizer); if (readBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", readBucketizer.GetStandardDeviation() / (bucketTimeInMs / 1000.0)); } if (writeBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", writeBucketizer.GetStandardDeviation() / (bucketTimeInMs / 1000.0)); } if (totalIoBucketizer.GetNumberOfValidBuckets() > 0) { _Print("%.3f\n", totalIoBucketizer.GetStandardDeviation() / (bucketTimeInMs / 1000.0)); } _PrintIops(readBucketizer, writeBucketizer, bucketTimeInMs); _Print("\n"); } void XmlResultParser::_PrintETWSessionInfo(struct ETWSessionInfo sessionInfo) { _Print("\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("%15lu\n", sessionInfo.ulEventsLost); _Print("%10lu\n", sessionInfo.ulLogBuffersLost); _Print("%4lu\n", sessionInfo.ulRealTimeBuffersLost); _Print("\n"); } void XmlResultParser::_PrintETW(struct ETWMask ETWMask, struct ETWEventCounters EtwEventCounters) { _Print("\n"); if (ETWMask.bDiskIO) { _Print("\n"); _Print("%I64u\n", EtwEventCounters.ullIORead); _Print("%I64u\n", EtwEventCounters.ullIOWrite); _Print("\n"); } if (ETWMask.bImageLoad) { _Print("%I64u\n", EtwEventCounters.ullImageLoad); } if (ETWMask.bMemoryPageFaults) { _Print("\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); _Print("\n"); } if (ETWMask.bMemoryHardFaults && !ETWMask.bMemoryPageFaults) { _Print("%I64u\n", EtwEventCounters.ullMMHardPageFault); } if (ETWMask.bNetwork) { _Print("\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); _Print("\n"); } if (ETWMask.bProcess) { _Print("\n"); _Print("%I64u\n", EtwEventCounters.ullProcessStart); _Print("%I64u\n", EtwEventCounters.ullProcessEnd); _Print("\n"); } if (ETWMask.bRegistry) { _Print("\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.ullRegKcbDmp); _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); _Print("\n"); } if (ETWMask.bThread) { _Print("\n"); _Print("%I64u\n", EtwEventCounters.ullThreadStart); _Print("%I64u\n", EtwEventCounters.ullThreadEnd); _Print("\n"); } _Print("\n"); } void XmlResultParser::_PrintCpuUtilization(const Results& results) { size_t ulProcCount = results.vSystemProcessorPerfInfo.size(); double fTime = PerfTimer::PerfTimeToSeconds(results.ullTimeCount); _Print("\n"); double busyTime = 0; double totalIdleTime = 0; double totalUserTime = 0; double totalKrnlTime = 0; for (unsigned int x = 0; x\n"); _Print("%d\n", x); _Print("%.2f\n", thisTime); _Print("%.2f\n", userTime); _Print("%.2f\n", krnlTime - idleTime); _Print("%.2f\n", idleTime); _Print("\n"); busyTime += thisTime; totalIdleTime += idleTime; totalUserTime += userTime; totalKrnlTime += krnlTime; } _Print("\n"); _Print("%.2f\n", busyTime / ulProcCount); _Print("%.2f\n", totalUserTime / ulProcCount); _Print("%.2f\n", (totalKrnlTime - totalIdleTime) / ulProcCount); _Print("%.2f\n", totalIdleTime / ulProcCount); _Print("\n"); _Print("\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 w = 0.0; if (readBucketizer.GetNumberOfValidBuckets() > i) { r = readBucketizer.GetIoBucket(i) / (bucketTimeInMs / 1000.0); done = false; } if (writeBucketizer.GetNumberOfValidBuckets() > i) { w = writeBucketizer.GetIoBucket(i) / (bucketTimeInMs / 1000.0); done = false; } if (!done) { _Print("\n", bucketTimeInMs*(i + 1), r, w, r + w); } } } 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); } } _Print("\n"); 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); } _Print("\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); } _Print("\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)); for (auto p : vPercentiles) { _Print("\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); } _Print("\n"); } _Print("\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); } _Print("\n"); _Print("\n"); } int XmlResultParser::GetTotalScore() { return 0; } double XmlResultParser::GetAverageLatency() { return 0.0; } string XmlResultParser::ParseResults(Profile& profile, const SystemInformation& system, vector vResults) { _sResult.clear(); _Print("\n"); _sResult += system.GetXml(); _sResult += profile.GetXml(); for (size_t iResults = 0; iResults < vResults.size(); iResults++) { const Results& results = vResults[iResults]; const TimeSpan& timeSpan = profile.GetTimeSpans()[iResults]; _Print("\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(); size_t ulProcCount = results.vSystemProcessorPerfInfo.size(); _Print("%.2f\n", fTime); _Print("%u\n", ulThreadCnt); _Print("%u\n", ulProcCount); _PrintCpuUtilization(results); 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]; _Print("\n"); _Print("%u\n", iThread); for (const auto& targetResults : threadResults.vTargetResults) { _Print("\n"); _PrintTargetResults(targetResults); if (timeSpan.GetMeasureLatency()) { _PrintTargetLatency(targetResults); } if (timeSpan.GetCalculateIopsStdDev()) { _PrintTargetIops(targetResults.readBucketizer, targetResults.writeBucketizer, timeSpan.GetIoBucketDurationInMilliseconds()); } _Print("\n"); } _Print("\n"); } } else { _Print("The test was interrupted before the measurements began. No results are displayed.\n"); } _Print("\n"); } _Print(""); return _sResult; }