blob: e5e444ea1637abc20f374816b2eeca8027c2727c [file] [log] [blame]
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#define LOG_TAG "PerformanceAnalysis"
19// #define LOG_NDEBUG 0
20
21#include <algorithm>
22#include <climits>
23#include <deque>
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -070024#include <iostream>
25#include <math.h>
26#include <numeric>
27#include <vector>
28#include <stdarg.h>
29#include <stdint.h>
30#include <stdio.h>
31#include <string.h>
32#include <sys/prctl.h>
33#include <time.h>
34#include <new>
35#include <audio_utils/roundup.h>
36#include <media/nbaio/NBLog.h>
37#include <media/nbaio/PerformanceAnalysis.h>
Sanna Catherine de Treville Wager80448082017-07-11 14:07:59 -070038#include <media/nbaio/ReportPerformance.h>
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -070039#include <utils/Log.h>
40#include <utils/String8.h>
41
42#include <queue>
43#include <utility>
44
45namespace android {
46
Sanna Catherine de Treville Wager80448082017-07-11 14:07:59 -070047namespace ReportPerformance {
48
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070049// Given a the most recent timestamp of a series of audio processing
50// wakeup timestamps,
51// buckets the time interval into a histogram, searches for
Sanna Catherine de Treville Wagera8a8a472017-07-11 09:41:25 -070052// outliers, analyzes the outlier series for unexpectedly
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070053// small or large values and stores these as peaks
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070054void PerformanceAnalysis::logTsEntry(timestamp ts) {
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070055 // after a state change, start a new series and do not
56 // record time intervals in-between
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070057 if (mBufferPeriod.mPrevTs == 0) {
58 mBufferPeriod.mPrevTs = ts;
Sanna Catherine de Treville Wagera80649a2017-07-21 16:16:38 -070059 return;
60 }
61
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070062 // calculate time interval between current and previous timestamp
63 const msInterval diffMs = static_cast<msInterval>(
64 deltaMs(mBufferPeriod.mPrevTs, ts));
65
66 const int diffJiffy = deltaJiffy(mBufferPeriod.mPrevTs, ts);
67
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070068 // old versus new weight ratio when updating the buffer period mean
69 static constexpr double exponentialWeight = 0.999;
70 // update buffer period mean with exponential weighting
71 mBufferPeriod.mMean = (mBufferPeriod.mMean < 0) ? diffMs :
72 exponentialWeight * mBufferPeriod.mMean + (1.0 - exponentialWeight) * diffMs;
73 // set mOutlierFactor to a smaller value for the fastmixer thread
74 const int kFastMixerMax = 10;
75 // NormalMixer times vary much more than FastMixer times.
76 // TODO: mOutlierFactor values are set empirically based on what appears to be
77 // an outlier. Learn these values from the data.
78 mBufferPeriod.mOutlierFactor = mBufferPeriod.mMean < kFastMixerMax ? 1.8 : 2.5;
79 // set outlier threshold
80 mBufferPeriod.mOutlier = mBufferPeriod.mMean * mBufferPeriod.mOutlierFactor;
81
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070082 // Check whether the time interval between the current timestamp
83 // and the previous one is long enough to count as an outlier
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070084 const bool isOutlier = detectAndStoreOutlier(diffMs);
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070085 // If an outlier was found, check whether it was a peak
86 if (isOutlier) {
87 /*bool isPeak =*/ detectAndStorePeak(
88 mOutlierData[0].first, mOutlierData[0].second);
89 // TODO: decide whether to insert a new empty histogram if a peak
90 // TODO: remove isPeak if unused to avoid "unused variable" error
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -070091 // occurred at the current timestamp
Sanna Catherine de Treville Wagera80649a2017-07-21 16:16:38 -070092 }
93
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -070094 // Insert a histogram to mHists if it is empty, or
95 // close the current histogram and insert a new empty one if
96 // if the current histogram has spanned its maximum time interval.
97 if (mHists.empty() ||
98 deltaMs(mHists[0].first, ts) >= kMaxLength.HistTimespanMs) {
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -070099 mHists.emplace_front(ts, std::map<int, int>());
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700100 // When memory is full, delete oldest histogram
101 // TODO: use a circular buffer
102 if (mHists.size() >= kMaxLength.Hists) {
103 mHists.resize(kMaxLength.Hists);
104 }
105 }
106 // add current time intervals to histogram
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700107 ++mHists[0].second[diffJiffy];
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700108 // update previous timestamp
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700109 mBufferPeriod.mPrevTs = ts;
Sanna Catherine de Treville Wagera8a8a472017-07-11 09:41:25 -0700110}
111
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700112
Sanna Catherine de Treville Wagera8a8a472017-07-11 09:41:25 -0700113// forces short-term histogram storage to avoid adding idle audio time interval
114// to buffer period data
Sanna Catherine de Treville Wager80448082017-07-11 14:07:59 -0700115void PerformanceAnalysis::handleStateChange() {
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700116 mBufferPeriod.mPrevTs = 0;
Sanna Catherine de Treville Wagera8a8a472017-07-11 09:41:25 -0700117 return;
118}
119
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700120
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700121// Checks whether the time interval between two outliers is far enough from
122// a typical delta to be considered a peak.
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700123// looks for changes in distribution (peaks), which can be either positive or negative.
124// The function sets the mean to the starting value and sigma to 0, and updates
125// them as long as no peak is detected. When a value is more than 'threshold'
126// standard deviations from the mean, a peak is detected and the mean and sigma
127// are set to the peak value and 0.
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700128bool PerformanceAnalysis::detectAndStorePeak(msInterval diff, timestamp ts) {
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700129 bool isPeak = false;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700130 if (mOutlierData.empty()) {
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700131 return false;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700132 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700133 // Update mean of the distribution
134 // TypicalDiff is used to check whether a value is unusually large
135 // when we cannot use standard deviations from the mean because the sd is set to 0.
136 mOutlierDistribution.mTypicalDiff = (mOutlierDistribution.mTypicalDiff *
137 (mOutlierData.size() - 1) + diff) / mOutlierData.size();
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700138
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700139 // Initialize short-term mean at start of program
140 if (mOutlierDistribution.mMean == 0) {
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700141 mOutlierDistribution.mMean = diff;
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700142 }
143 // Update length of current sequence of outliers
144 mOutlierDistribution.mN++;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700145
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700146 // Check whether a large deviation from the mean occurred.
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700147 // If the standard deviation has been reset to zero, the comparison is
148 // instead to the mean of the full mOutlierInterval sequence.
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700149 if ((fabs(diff - mOutlierDistribution.mMean) <
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700150 mOutlierDistribution.kMaxDeviation * mOutlierDistribution.mSd) ||
151 (mOutlierDistribution.mSd == 0 &&
152 fabs(diff - mOutlierDistribution.mMean) <
153 mOutlierDistribution.mTypicalDiff)) {
154 // update the mean and sd using online algorithm
155 // https://en.wikipedia.org/wiki/
156 // Algorithms_for_calculating_variance#Online_algorithm
157 mOutlierDistribution.mN++;
158 const double kDelta = diff - mOutlierDistribution.mMean;
159 mOutlierDistribution.mMean += kDelta / mOutlierDistribution.mN;
160 const double kDelta2 = diff - mOutlierDistribution.mMean;
161 mOutlierDistribution.mM2 += kDelta * kDelta2;
162 mOutlierDistribution.mSd = (mOutlierDistribution.mN < 2) ? 0 :
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700163 sqrt(mOutlierDistribution.mM2 / (mOutlierDistribution.mN - 1));
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700164 } else {
165 // new value is far from the mean:
166 // store peak timestamp and reset mean, sd, and short-term sequence
167 isPeak = true;
168 mPeakTimestamps.emplace_front(ts);
169 // if mPeaks has reached capacity, delete oldest data
170 // Note: this means that mOutlierDistribution values do not exactly
171 // match the data we have in mPeakTimestamps, but this is not an issue
172 // in practice for estimating future peaks.
173 // TODO: turn this into a circular buffer
174 if (mPeakTimestamps.size() >= kMaxLength.Peaks) {
175 mPeakTimestamps.resize(kMaxLength.Peaks);
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700176 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700177 mOutlierDistribution.mMean = 0;
178 mOutlierDistribution.mSd = 0;
179 mOutlierDistribution.mN = 0;
180 mOutlierDistribution.mM2 = 0;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700181 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700182 return isPeak;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700183}
184
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700185
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700186// Determines whether the difference between a timestamp and the previous
187// one is beyond a threshold. If yes, stores the timestamp as an outlier
188// and writes to mOutlierdata in the following format:
189// Time elapsed since previous outlier: Timestamp of start of outlier
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700190// e.g. timestamps (ms) 1, 4, 5, 16, 18, 28 will produce pairs (4, 5), (13, 18).
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700191// TODO: learn what timestamp sequences correlate with glitches instead of
192// manually designing a heuristic.
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700193bool PerformanceAnalysis::detectAndStoreOutlier(const msInterval diffMs) {
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700194 bool isOutlier = false;
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700195 if (diffMs >= mBufferPeriod.mOutlier) {
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700196 isOutlier = true;
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700197 mOutlierData.emplace_front(
198 mOutlierDistribution.mElapsed, mBufferPeriod.mPrevTs);
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700199 // Remove oldest value if the vector is full
200 // TODO: turn this into a circular buffer
201 // TODO: make sure kShortHistSize is large enough that that data will never be lost
202 // before being written to file or to a FIFO
203 if (mOutlierData.size() >= kMaxLength.Outliers) {
204 mOutlierData.resize(kMaxLength.Outliers);
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700205 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700206 mOutlierDistribution.mElapsed = 0;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700207 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700208 mOutlierDistribution.mElapsed += diffMs;
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700209 return isOutlier;
Sanna Catherine de Treville Wager41cad592017-06-29 14:57:59 -0700210}
211
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700212static int widthOf(int x) {
213 int width = 0;
214 if (x < 0) {
215 width++;
216 x = x == INT_MIN ? INT_MAX : -x;
217 }
218 // assert (x >= 0)
219 do {
220 ++width;
221 x /= 10;
222 } while (x > 0);
223 return width;
224}
225
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700226// computes the column width required for a specific histogram value
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700227inline int numberWidth(double number, int leftPadding) {
228 // Added values account for whitespaces needed around numbers, and for the
229 // dot and decimal digit not accounted for by widthOf
230 return std::max(std::max(widthOf(static_cast<int>(number)) + 3, 2), leftPadding + 1);
231}
232
233// rounds value to precision based on log-distance from mean
234inline double logRound(double x, double mean) {
235 // Larger values increase range of high resolution
236 constexpr double kBase = 2;
237 const double power = floor(
238 log(abs(x - mean) / mean) / log(kBase)) + 1;
239 // do not round values close to the mean
240 if (power < 1) {
241 return x;
242 }
243 const int factor = static_cast<int>(pow(10, power));
244 return (static_cast<int>(x) * factor) / factor;
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700245}
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700246
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700247// TODO Make it return a std::string instead of modifying body
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700248// TODO: move this to ReportPerformance, probably make it a friend function
249// of PerformanceAnalysis
250void PerformanceAnalysis::reportPerformance(String8 *body, int author, log_hash_t hash,
251 int maxHeight) {
Sanna Catherine de Treville Wagera80649a2017-07-21 16:16:38 -0700252 if (mHists.empty()) {
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700253 return;
254 }
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700255
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700256 // ms of active audio in displayed histogram
257 double elapsedMs = 0;
258 // starting timestamp of histogram
259 timestamp startingTs = mHists[0].first;
260
261 // histogram which stores .1 precision ms counts instead of Jiffy multiple counts
262 // TODO: when there is more data, print many histograms, possibly separated at peaks
263 std::map<double, int> buckets;
Sanna Catherine de Treville Wagera80649a2017-07-21 16:16:38 -0700264 for (const auto &shortHist: mHists) {
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700265 for (const auto &countPair : shortHist.second) {
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700266 const double ms = static_cast<double>(countPair.first) / kJiffyPerMs;
267 buckets[logRound(ms, mBufferPeriod.mMean)] += countPair.second;
268 elapsedMs += ms;
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700269 }
270 }
271
272 // underscores and spaces length corresponds to maximum width of histogram
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700273 static const int kLen = 200;
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700274 std::string underscores(kLen, '_');
275 std::string spaces(kLen, ' ');
276
277 auto it = buckets.begin();
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700278 double maxDelta = it->first;
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700279 int maxCount = it->second;
280 // Compute maximum values
281 while (++it != buckets.end()) {
282 if (it->first > maxDelta) {
283 maxDelta = it->first;
284 }
285 if (it->second > maxCount) {
286 maxCount = it->second;
287 }
288 }
289 int height = log2(maxCount) + 1; // maxCount > 0, safe to call log2
290 const int leftPadding = widthOf(1 << height);
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700291 const int bucketWidth = numberWidth(maxDelta, leftPadding);
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700292 int scalingFactor = 1;
293 // scale data if it exceeds maximum height
294 if (height > maxHeight) {
295 scalingFactor = (height + maxHeight) / maxHeight;
296 height /= scalingFactor;
297 }
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700298 body->appendFormat("\n%*s %3.2f %s", leftPadding + 11,
299 "Occurrences in", (elapsedMs / kMsPerSec), "seconds of audio:");
300 body->appendFormat("\n%*s%d, %lld, %lld\n", leftPadding + 11,
301 "Thread, hash, starting timestamp: ", author,
302 static_cast<long long int>(hash), static_cast<long long int>(startingTs));
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700303 // write histogram label line with bucket values
304 body->appendFormat("\n%s", " ");
305 body->appendFormat("%*s", leftPadding, " ");
306 for (auto const &x : buckets) {
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700307 const int colWidth = numberWidth(x.first, leftPadding);
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700308 body->appendFormat("%*d", colWidth, x.second);
309 }
310 // write histogram ascii art
311 body->appendFormat("\n%s", " ");
312 for (int row = height * scalingFactor; row >= 0; row -= scalingFactor) {
313 const int value = 1 << row;
314 body->appendFormat("%.*s", leftPadding, spaces.c_str());
315 for (auto const &x : buckets) {
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700316 const int colWidth = numberWidth(x.first, leftPadding);
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700317 body->appendFormat("%.*s%s", colWidth - 1,
318 spaces.c_str(), x.second < value ? " " : "|");
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700319 }
320 body->appendFormat("\n%s", " ");
321 }
322 // print x-axis
323 const int columns = static_cast<int>(buckets.size());
324 body->appendFormat("%*c", leftPadding, ' ');
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700325 body->appendFormat("%.*s", (columns + 1) * bucketWidth, underscores.c_str());
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700326 body->appendFormat("\n%s", " ");
327
328 // write footer with bucket labels
329 body->appendFormat("%*s", leftPadding, " ");
330 for (auto const &x : buckets) {
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700331 const int colWidth = numberWidth(x.first, leftPadding);
332 body->appendFormat("%*.*f", colWidth, 1, x.first);
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700333 }
Sanna Catherine de Treville Wager6ad40ee2017-07-28 10:10:55 -0700334 body->appendFormat("%.*s%s", bucketWidth, spaces.c_str(), "ms\n");
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700335
Sanna Catherine de Treville Wager316f1fd2017-06-23 09:10:15 -0700336 // Now report glitches
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700337 body->appendFormat("\ntime elapsed between glitches and glitch timestamps:\n");
Sanna Catherine de Treville Wager316f1fd2017-06-23 09:10:15 -0700338 for (const auto &outlier: mOutlierData) {
339 body->appendFormat("%lld: %lld\n", static_cast<long long>(outlier.first),
340 static_cast<long long>(outlier.second));
341 }
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700342}
343
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700344//------------------------------------------------------------------------------
345
346// writes summary of performance into specified file descriptor
Sanna Catherine de Treville Wager23f89d32017-07-24 18:24:48 -0700347void dump(int fd, int indent, PerformanceAnalysisMap &threadPerformanceAnalysis) {
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700348 String8 body;
Sanna Catherine de Treville Wagerf8c34282017-07-25 11:31:18 -0700349 const char* const kDirectory = "/data/misc/audioserver/";
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700350 for (auto & thread : threadPerformanceAnalysis) {
Sanna Catherine de Treville Wagerd0965172017-07-24 13:42:44 -0700351 for (auto & hash: thread.second) {
Sanna Catherine de Treville Wager23f89d32017-07-24 18:24:48 -0700352 PerformanceAnalysis& curr = hash.second;
Sanna Catherine de Treville Wager23f89d32017-07-24 18:24:48 -0700353 // write performance data to console
Sanna Catherine de Treville Wager2a6a9452017-07-28 11:02:01 -0700354 curr.reportPerformance(&body, thread.first, hash.first);
Sanna Catherine de Treville Wager0a3959e2017-07-25 16:08:17 -0700355 if (!body.isEmpty()) {
356 dumpLine(fd, indent, body);
357 body.clear();
358 }
Sanna Catherine de Treville Wager23f89d32017-07-24 18:24:48 -0700359 // write to file
Sanna Catherine de Treville Wagerf8c34282017-07-25 11:31:18 -0700360 writeToFile(curr.mHists, curr.mOutlierData, curr.mPeakTimestamps,
361 kDirectory, false, thread.first, hash.first);
Sanna Catherine de Treville Wagerd0965172017-07-24 13:42:44 -0700362 }
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700363 }
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700364}
365
Sanna Catherine de Treville Wager85768942017-07-26 20:17:30 -0700366
Sanna Catherine de Treville Wagercf6c75a2017-07-21 17:05:25 -0700367// Writes a string into specified file descriptor
368void dumpLine(int fd, int indent, const String8 &body) {
369 dprintf(fd, "%.*s%s \n", indent, "", body.string());
370}
371
Sanna Catherine de Treville Wager80448082017-07-11 14:07:59 -0700372} // namespace ReportPerformance
373
Sanna Catherine de Treville Wagerd0dfe432017-06-22 15:09:38 -0700374} // namespace android