1/*
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 */
16package com.android.statsd.loadtest;
17
18import android.annotation.Nullable;
19import android.content.Context;
20import android.util.Log;
21import com.android.internal.os.StatsdConfigProto.TimeUnit;
22import java.text.ParseException;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25
26public class BatteryDataRecorder extends PerfDataRecorder {
27    private static final String TAG = "loadtest.BatteryDataRecorder";
28    private static final String DUMP_FILENAME = TAG + "_dump.tmp";
29
30    public BatteryDataRecorder(boolean placebo, int replication, TimeUnit bucket, long periodSecs,
31        int burst, boolean includeCountMetric, boolean includeDurationMetric,
32        boolean includeEventMetric,  boolean includeValueMetric, boolean includeGaugeMetric) {
33      super(placebo, replication, bucket, periodSecs, burst, includeCountMetric,
34          includeDurationMetric, includeEventMetric, includeValueMetric, includeGaugeMetric);
35    }
36
37    @Override
38    public void startRecording(Context context) {
39        // Reset batterystats.
40        runDumpsysStats(context, DUMP_FILENAME, "batterystats", "--reset");
41    }
42
43    @Override
44    public void onAlarm(Context context) {
45        // Nothing to do as for battery, the whole data is in the final dumpsys call.
46    }
47
48    @Override
49    public void stopRecording(Context context) {
50        StringBuilder sb = new StringBuilder();
51        // Don't use --checkin.
52        runDumpsysStats(context, DUMP_FILENAME, "batterystats");
53        readDumpData(context, DUMP_FILENAME, new BatteryStatsParser(), sb);
54        writeData(context, "battery_", "time,battery_level", sb);
55    }
56}
57