1/* 2 * Copyright (C) 2015 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 17package com.android.camera.stats.profiler; 18 19/** 20 * A guarding profiler creates new guarded profiles that 21 * will only write output messages if the profile time 22 * exceeds the threshold. 23 */ 24public class GuardingProfiler implements Profiler { 25 private static final int DEFAULT_GUARD_DURATION_MILLIS = 15; 26 private final Writer mGuardWriter; 27 private final Writer mVerboseWriter; 28 private final int mMaxDurationMillis; 29 30 /** Create a new GuardingProfiler */ 31 public GuardingProfiler(Writer writer, Writer verbose) { 32 this(writer, verbose, DEFAULT_GUARD_DURATION_MILLIS); 33 } 34 35 /** Create a new GuardingProfiler with a given max duration. */ 36 public GuardingProfiler(Writer writer, Writer verbose, int maxDurationMillis) { 37 mGuardWriter = writer; 38 mVerboseWriter = verbose; 39 mMaxDurationMillis = maxDurationMillis; 40 } 41 42 @Override 43 public Profile create(String name) { 44 return new GuardingProfile(mGuardWriter, mVerboseWriter, name, 45 mMaxDurationMillis); 46 } 47 48 /** Start a new profile, but override the maxDuration */ 49 public Profile create(String name, int maxDurationMillis) { 50 return new GuardingProfile(mGuardWriter, mVerboseWriter, name, 51 maxDurationMillis); 52 } 53} 54