Write thread and data to separate files
Each file name starts with either "histogram" or
"outlier" and contains thread and hash (source
file location) information.
Test: dumpsys media.log
Change-Id: I4bbea8b5265ac539e6fb2ce16207e4f5c89d21d4
diff --git a/media/libnbaio/ReportPerformance.cpp b/media/libnbaio/ReportPerformance.cpp
index 7d3869c..87c223b 100644
--- a/media/libnbaio/ReportPerformance.cpp
+++ b/media/libnbaio/ReportPerformance.cpp
@@ -23,12 +23,12 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
+#include <sstream>
#include <sys/prctl.h>
#include <utility>
#include <media/nbaio/NBLog.h>
#include <media/nbaio/PerformanceAnalysis.h>
#include <media/nbaio/ReportPerformance.h>
-// #include <utils/CallStack.h> // used to print callstack
#include <utils/Log.h>
#include <utils/String8.h>
@@ -40,34 +40,48 @@
// TODO: format the data efficiently and write different types of data to different files
void writeToFile(const std::deque<std::pair<outlierInterval, timestamp>> &outlierData,
const std::deque<std::pair<timestamp, Histogram>> &hists,
- const char * kName,
- bool append) {
- ALOGD("writing performance data to file");
+ const char * kDirectory,
+ bool append, int author, log_hash_t hash) {
if (outlierData.empty() || hists.empty()) {
+ ALOGW("No data, returning.");
return;
}
+ std::stringstream outlierName;
+ std::stringstream histogramName;
+
+ outlierName << kDirectory << "outliers_" << author << "_" << hash;
+ histogramName << kDirectory << "histograms_" << author << "_" << hash;
+
std::ofstream ofs;
- ofs.open(kName, append ? std::ios::app : std::ios::trunc);
+ ofs.open(outlierName.str().c_str(), append ? std::ios::app : std::ios::trunc);
if (!ofs.is_open()) {
- ALOGW("couldn't open file %s", kName);
+ ALOGW("couldn't open file %s", outlierName.str().c_str());
return;
}
ofs << "Outlier data: interval and timestamp\n";
for (const auto &outlier : outlierData) {
ofs << outlier.first << ": " << outlier.second << "\n";
}
- ofs << "Histogram data\n";
- for (const auto &hist : hists) {
- ofs << "\ttimestamp\n";
- ofs << hist.first << "\n";
- ofs << "\tbuckets and counts\n";
- for (const auto &bucket : hist.second) {
- ofs << bucket.first << ": " << bucket.second << "\n";
- }
- ofs << "\n"; // separate histograms with a newline
- }
ofs.close();
+
+ std::ofstream hfs;
+ hfs.open(histogramName.str().c_str(), append ? std::ios::app : std::ios::trunc);
+ if (!hfs.is_open()) {
+ ALOGW("couldn't open file %s", histogramName.str().c_str());
+ return;
+ }
+ hfs << "Histogram data\n";
+ for (const auto &hist : hists) {
+ hfs << "\ttimestamp\n";
+ hfs << hist.first << "\n";
+ hfs << "\tbuckets and counts\n";
+ for (const auto &bucket : hist.second) {
+ hfs << bucket.first << ": " << bucket.second << "\n";
+ }
+ hfs << "\n"; // separate histograms with a newline
+ }
+ hfs.close();
}
} // namespace ReportPerformance