Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2008 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 android.util.cts;
     17 
     18 
     19 import android.support.test.filters.LargeTest;
     20 import android.support.test.runner.AndroidJUnit4;
     21 import android.util.TimingLogger;
     22 
     23 import org.junit.Test;
     24 import org.junit.runner.RunWith;
     25 
     26 @LargeTest
     27 @RunWith(AndroidJUnit4.class)
     28 public class TimingLoggerTest {
     29     private static final String LOG_TAG = "TimingLoggerTest";
     30     private static final int SLEEPING_MSEC = 100;
     31 
     32     @Test
     33     public void testTimingLogger() {
     34         TimingLogger timings = new TimingLogger(LOG_TAG, "testTimingLogger");
     35 
     36         for (int i = 0; i < 3; i++) {
     37             if (1 == i) {
     38                 timings.reset(LOG_TAG, "testReset");
     39             } else if (2 == i) {
     40                 timings.reset();
     41             }
     42 
     43             sleep();
     44             timings.addSplit("first sleep");
     45 
     46             sleep();
     47             timings.addSplit("second sleep");
     48 
     49             sleep();
     50             timings.addSplit("third sleep");
     51 
     52             timings.dumpToLog();
     53         }
     54     }
     55 
     56     private void sleep() {
     57         try {
     58             Thread.sleep(SLEEPING_MSEC);
     59         } catch (InterruptedException e) {
     60 
     61         }
     62     }
     63 }
     64