Trace.java revision 93a35b93dc582e38ff8ee5979754a16b4bf4da0c
1/* 2 * Copyright (C) 2013 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.bitmap.util; 18 19import java.lang.reflect.Method; 20 21public class Trace { 22 23 private static Method sBegin; 24 private static Method sEnd; 25 26 public static void init() { 27 if (sBegin != null && sEnd != null) { 28 return; 29 } 30 try { 31 final Class<?> cls = Class.forName("android.os.Trace"); 32 sBegin = cls.getMethod("beginSection", String.class); 33 sEnd = cls.getMethod("endSection"); 34 } catch (Exception e) { 35 e.printStackTrace(); 36 } 37 } 38 39 public static void beginSection(String tag) { 40 if (sBegin == null) { 41 return; 42 } 43 try { 44 sBegin.invoke(null, tag); 45 } catch (Exception e) { 46 e.printStackTrace(); 47 } 48 } 49 50 public static void endSection() { 51 if (sEnd == null) { 52 return; 53 } 54 try { 55 sEnd.invoke(null, (Object[]) null); 56 } catch (Exception e) { 57 e.printStackTrace(); 58 } 59 } 60} 61