blob: dc50ada09c3540e910d380163d2266084036c337 [file] [log] [blame]
Sanna Catherine de Treville Wager80448082017-07-11 14:07:59 -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#define LOG_TAG "ReportPerformance"
18
19#include <fstream>
20#include <iostream>
21#include <queue>
22#include <stdarg.h>
23#include <stdint.h>
24#include <stdio.h>
25#include <string.h>
26#include <sys/prctl.h>
27#include <utility>
28#include <media/nbaio/NBLog.h>
29#include <media/nbaio/PerformanceAnalysis.h>
30#include <media/nbaio/ReportPerformance.h>
31// #include <utils/CallStack.h> // used to print callstack
32#include <utils/Log.h>
33#include <utils/String8.h>
34
35namespace android {
36
37namespace ReportPerformance {
38
39// Writes outlier intervals, timestamps, and histograms spanning long time intervals to a file.
40// TODO: format the data efficiently and write different types of data to different files
41void writeToFile(std::deque<std::pair<outlierInterval, timestamp>> &outlierData,
42 std::deque<std::pair<timestamp, Histogram>> &hists,
43 const char * kName,
44 bool append) {
45 ALOGD("writing performance data to file");
46 if (outlierData.empty() || hists.empty()) {
47 return;
48 }
49
50 std::ofstream ofs;
51 ofs.open(kName, append ? std::ios::app : std::ios::trunc);
52 if (!ofs.is_open()) {
53 ALOGW("couldn't open file %s", kName);
54 return;
55 }
56 ofs << "Outlier data: interval and timestamp\n";
57 for (const auto &outlier : outlierData) {
58 ofs << outlier.first << ": " << outlier.second << "\n";
59 }
60 ofs << "Histogram data\n";
61 for (const auto &hist : hists) {
62 ofs << "\ttimestamp\n";
63 ofs << hist.first << "\n";
64 ofs << "\tbuckets and counts\n";
65 for (const auto &bucket : hist.second) {
66 ofs << bucket.first << ": " << bucket.second << "\n";
67 }
68 }
69 ofs.close();
70}
71
72} // namespace ReportPerformance
73
74} // namespace android