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 */ 16 package com.android.statsd.loadtest; 17 18 import android.content.Context; 19 import android.os.SystemClock; 20 import android.util.Log; 21 import com.android.internal.os.StatsdConfigProto.TimeUnit; 22 23 public class MemoryDataRecorder extends PerfDataRecorder { 24 private static final String TAG = "loadtest.MemoryDataDataRecorder"; 25 private static final String DUMP_FILENAME = TAG + "_dump.tmp"; 26 27 private long mStartTimeMillis; 28 private StringBuilder mSb; 29 30 public MemoryDataRecorder(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 mStartTimeMillis = SystemClock.elapsedRealtime(); 40 mSb = new StringBuilder(); 41 } 42 43 @Override 44 public void onAlarm(Context context) { 45 runDumpsysStats(context, DUMP_FILENAME, "meminfo"); 46 readDumpData(context, DUMP_FILENAME, new MemInfoParser(mStartTimeMillis), mSb); 47 } 48 49 @Override 50 public void stopRecording(Context context) { 51 writeData(context, "meminfo_", "time,pss", mSb); 52 } 53 } 54