Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Fix exception thrown during column ordering for BMEM. Wrap HTML repor…
Browse files Browse the repository at this point in the history
…t generation in try/catch since if that fails we should still try to produce JSON report
  • Loading branch information
Stephen Foulds committed Aug 18, 2023
1 parent 07b1324 commit 5489cd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
20 changes: 8 additions & 12 deletions MemoryMetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ void MemoryMetric::SaveResults()
if (mPlatform == Platform::BROADCOM) {
for (const auto &measurement: mBroadcomBmemMeasurements) {
data.emplace_back(JsonReportGenerator::dataItems{
std::make_pair("Region", measurement.GetName()),
measurement});
std::make_pair("Region", measurement.first),
measurement.second});
}
mReportGenerator->addDataset("BMEM", data);

// Add all BMEM memory to accumulated total
long double bmemSum = 0;
std::for_each(mBroadcomBmemMeasurements.begin(), mBroadcomBmemMeasurements.end(), [&](const Measurement &m)
std::for_each(mBroadcomBmemMeasurements.begin(), mBroadcomBmemMeasurements.end(), [&](const auto &m)
{
bmemSum += m.GetAverage();
bmemSum += m.second.GetAverage();
});
mReportGenerator->addToAccumulatedMemoryUsage(bmemSum);
}
Expand Down Expand Up @@ -520,19 +520,15 @@ void MemoryMetric::GetBroadcomBmemUsage()
// Use KB for consistency with everything else
double usageKb = (regionSize * (regionUsage / 100.0)) * 1024;

auto itr = std::find_if(mBroadcomBmemMeasurements.begin(), mBroadcomBmemMeasurements.end(),
[&](const Measurement &m)
{
return m.GetName() == std::string(regionName);
});
auto itr = mBroadcomBmemMeasurements.find(std::string(regionName));

if (itr == mBroadcomBmemMeasurements.end()) {
// New region
Measurement measurement(regionName);
Measurement measurement("Memory Usage (KB)");
measurement.AddDataPoint(usageKb);
mBroadcomBmemMeasurements.emplace_back(measurement);
mBroadcomBmemMeasurements.insert(std::make_pair(std::string(regionName), measurement));
} else {
auto &measurement = *itr;
auto &measurement = itr->second;
measurement.AddDataPoint(usageKb);
}
}
Expand Down
2 changes: 1 addition & 1 deletion MemoryMetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class MemoryMetric : public IMetric
std::map<pid_t, gpuMeasurement> mGpuMeasurements;
std::map<std::string, Measurement> mContainerMeasurements;

std::vector<Measurement> mBroadcomBmemMeasurements;
std::map<std::string, Measurement> mBroadcomBmemMeasurements;

Measurement mCmaFree;
Measurement mCmaBorrowed;
Expand Down
16 changes: 10 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,18 @@ int main(int argc, char *argv[])
return ordered;
});

auto htmlTemplateString = std::string(g_templateHtml_data, g_templateHtml_data + g_templateHtml_size);
std::string result = env.render(htmlTemplateString, reportGenerator->getJson());
try {
auto htmlTemplateString = std::string(g_templateHtml_data, g_templateHtml_data + g_templateHtml_size);
std::string result = env.render(htmlTemplateString, reportGenerator->getJson());

std::filesystem::path htmlFilepath = gOutputDirectory / "report.html";
std::ofstream outputHtml(htmlFilepath, std::ios::trunc | std::ios::binary);
outputHtml << result;
std::filesystem::path htmlFilepath = gOutputDirectory / "report.html";
std::ofstream outputHtml(htmlFilepath, std::ios::trunc | std::ios::binary);
outputHtml << result;

LOG_INFO("Saved report to %s", htmlFilepath.string().c_str());
LOG_INFO("Saved report to %s", htmlFilepath.string().c_str());
} catch (std::exception& e) {
LOG_ERROR("Failed to save HTML report with exception %s", e.what());
}

if (gJson) {
std::filesystem::path jsonFilepath = gOutputDirectory / "report.json";
Expand Down

0 comments on commit 5489cd5

Please sign in to comment.