Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8c34284 authored by Sanna Catherine de Treville Wager's avatar Sanna Catherine de Treville Wager
Browse files

Write peaks to file. Minor cleanup

Test: dumpsys media.log
Change-Id: Ie696cd904306997142f050cf842290aeacfb6636
parent 23f89d34
Loading
Loading
Loading
Loading
+6 −20
Original line number Diff line number Diff line
@@ -219,20 +219,6 @@ void PerformanceAnalysis::storeOutlierData(const std::vector<int64_t> &timestamp
    }
}

// FIXME: delete this temporary test code, recycled for various new functions
void PerformanceAnalysis::testFunction() {
    // produces values (4: 5000000), (13: 18000000)
    // ns timestamps of buffer periods
    const std::vector<int64_t>kTempTestData = {1000000, 4000000, 5000000,
                                               16000000, 18000000, 28000000};
    PerformanceAnalysis::storeOutlierData(kTempTestData);
    for (const auto &outlier: mOutlierData) {
        ALOGE("PerformanceAnalysis test %lld: %lld",
              static_cast<long long>(outlier.first), static_cast<long long>(outlier.second));
    }
    detectPeaks();
}

// TODO Make it return a std::string instead of modifying body --> is this still relevant?
// TODO consider changing all ints to uint32_t or uint64_t
// TODO: move this to ReportPerformance, probably make it a friend function of PerformanceAnalysis
@@ -319,15 +305,15 @@ void PerformanceAnalysis::reportPerformance(String8 *body, int maxHeight) {

}


// TODO: decide whether to use this or whether it is overkill, and it is enough
// to only treat as glitches single wakeup call intervals which are too long.
// Ultimately, glitch detection will be directly on the audio signal.
// Produces a log warning if the timing of recent buffer periods caused a glitch
// Computes sum of running window of three buffer periods
// Checks whether the buffer periods leave enough CPU time for the next one
// e.g. if a buffer period is expected to be 4 ms and a buffer requires 3 ms of CPU time,
// here are some glitch cases:
// 4 + 4 + 6 ; 5 + 4 + 5; 2 + 2 + 10
// TODO: develop this code to track changes in histogram distribution in addition
// to / instead of glitches.
void PerformanceAnalysis::alertIfGlitch(const std::vector<int64_t> &samples) {
    std::deque<int> periods(kNumBuff, kPeriodMs);
    for (size_t i = 2; i < samples.size(); ++i) { // skip first time entry
@@ -348,7 +334,7 @@ void PerformanceAnalysis::alertIfGlitch(const std::vector<int64_t> &samples) {
// writes summary of performance into specified file descriptor
void dump(int fd, int indent, PerformanceAnalysisMap &threadPerformanceAnalysis) {
    String8 body;
    const char* const kName = "/data/misc/audioserver/";
    const char* const kDirectory = "/data/misc/audioserver/";
    for (auto & thread : threadPerformanceAnalysis) {
        for (auto & hash: thread.second) {
            PerformanceAnalysis& curr = hash.second;
@@ -356,8 +342,8 @@ void dump(int fd, int indent, PerformanceAnalysisMap &threadPerformanceAnalysis)
            // write performance data to console
            curr.reportPerformance(&body);
            // write to file
            writeToFile(curr.mOutlierData, curr.mHists, kName, false,
                        thread.first, hash.first);
            writeToFile(curr.mHists, curr.mOutlierData, curr.mPeakTimestamps,
                        kDirectory, false, thread.first, hash.first);
        }
    }
    if (!body.isEmpty()) {
+33 −19
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ namespace ReportPerformance {

// Writes outlier intervals, timestamps, and histograms spanning long time intervals to a file.
// 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 * kDirectory,
                                    bool append, int author, log_hash_t hash) {
void writeToFile(const std::deque<std::pair<timestamp, Histogram>> &hists,
                 const std::deque<std::pair<outlierInterval, timestamp>> &outlierData,
                 const std::deque<timestamp> &peakTimestamps,
                 const char * directory, bool append, int author, log_hash_t hash) {
    if (outlierData.empty() || hists.empty()) {
        ALOGW("No data, returning.");
        return;
@@ -49,24 +49,14 @@ void writeToFile(const std::deque<std::pair<outlierInterval, timestamp>> &outlie

    std::stringstream outlierName;
    std::stringstream histogramName;
    std::stringstream peakName;

    outlierName << kDirectory << "outliers_" << author << "_" << hash;
    histogramName << kDirectory << "histograms_" << author << "_" << hash;

    std::ofstream ofs;
    ofs.open(outlierName.str().c_str(), append ? std::ios::app : std::ios::trunc);
    if (!ofs.is_open()) {
        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.close();
    histogramName << directory << "histograms_" << author << "_" << hash;
    outlierName << directory << "outliers_" << author << "_" << hash;
    peakName << directory << "peaks_" << author << "_" << hash;

    std::ofstream hfs;
    hfs.open(histogramName.str().c_str(), append ? std::ios::app : std::ios::trunc);
    hfs.open(histogramName.str(), append ? std::ios::app : std::ios::trunc);
    if (!hfs.is_open()) {
        ALOGW("couldn't open file %s", histogramName.str().c_str());
        return;
@@ -82,6 +72,30 @@ void writeToFile(const std::deque<std::pair<outlierInterval, timestamp>> &outlie
        hfs << "\n"; // separate histograms with a newline
    }
    hfs.close();

    std::ofstream ofs;
    ofs.open(outlierName.str(), append ? std::ios::app : std::ios::trunc);
    if (!ofs.is_open()) {
        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.close();

    std::ofstream pfs;
    pfs.open(peakName.str(), append ? std::ios::app : std::ios::trunc);
    if (!pfs.is_open()) {
        ALOGW("couldn't open file %s", peakName.str().c_str());
        return;
    }
    pfs << "Peak data: timestamp\n";
    for (const auto &peak : peakTimestamps) {
        pfs << peak << "\n";
    }
    pfs.close();
}

} // namespace ReportPerformance
+4 −5
Original line number Diff line number Diff line
@@ -79,11 +79,10 @@ public:
    // FIXME: move this data visualization to a separate class. Model/view/controller
    void reportPerformance(String8 *body, int maxHeight = 10);

    // TODO: delete this. temp for testing
    void testFunction();

    // This function used to detect glitches in a time series
    // TODO incorporate this into the analysis (currently unused)
    // This function detects glitches in a time series.
    // TODO: decide whether to use this or whether it is overkill, and it is enough
    // to only treat as glitches single wakeup call intervals which are too long.
    // Ultimately, glitch detection will be directly on the audio signal.
    void alertIfGlitch(const std::vector<timestamp_raw> &samples);

private:
+4 −3
Original line number Diff line number Diff line
@@ -56,9 +56,10 @@ static inline uint32_t log2(uint32_t x) {

// Writes outlier intervals, timestamps, and histograms spanning long time
// intervals to a file.
void writeToFile(const std::deque<std::pair<outlierInterval, timestamp>> &outlierData,
                 const std::deque<std::pair<timestamp, Histogram>> &hists,
                 const char * kName, bool append, int author, log_hash_t hash);
void writeToFile(const std::deque<std::pair<timestamp, Histogram>> &hists,
                 const std::deque<std::pair<outlierInterval, timestamp>> &outlierData,
                 const std::deque<timestamp> &peakTimestamps,
                 const char * kDirectory, bool append, int author, log_hash_t hash);

} // namespace ReportPerformance