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.content.Context; 19import com.android.os.StatsLog.StatsdStatsReport; 20import com.android.internal.os.StatsdConfigProto.TimeUnit; 21 22public class StatsdStatsRecorder extends PerfDataRecorder { 23 private static final String TAG = "loadtest.StatsdStatsRecorder"; 24 25 private final LoadtestActivity mLoadtestActivity; 26 27 public StatsdStatsRecorder(LoadtestActivity loadtestActivity, boolean placebo, int replication, 28 TimeUnit bucket, long periodSecs, int burst, boolean includeCountMetric, 29 boolean includeDurationMetric, boolean includeEventMetric, boolean includeValueMetric, 30 boolean includeGaugeMetric) { 31 super(placebo, replication, bucket, periodSecs, burst, includeCountMetric, 32 includeDurationMetric, includeEventMetric, includeValueMetric, includeGaugeMetric); 33 mLoadtestActivity = loadtestActivity; 34 } 35 36 @Override 37 public void startRecording(Context context) { 38 // Nothing to do. 39 } 40 41 @Override 42 public void onAlarm(Context context) { 43 // Nothing to do. 44 } 45 46 @Override 47 public void stopRecording(Context context) { 48 StatsdStatsReport metadata = mLoadtestActivity.getMetadata(); 49 if (metadata != null) { 50 int numConfigs = metadata.getConfigStatsCount(); 51 StringBuilder sb = new StringBuilder(); 52 StatsdStatsReport.ConfigStats configStats = metadata.getConfigStats(numConfigs - 1); 53 sb.append("metric_count,") 54 .append(configStats.getMetricCount() + "\n") 55 .append("condition_count,") 56 .append(configStats.getConditionCount() + "\n") 57 .append("matcher_count,") 58 .append(configStats.getMatcherCount() + "\n"); 59 writeData(context, "statsdstats_", "stat,value", sb); 60 } 61 } 62} 63