• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.ahat;
18 
19 import com.android.tools.perflib.heap.Instance;
20 import java.io.IOException;
21 import java.io.OutputStream;
22 import java.io.PrintStream;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import org.junit.Test;
26 
27 public class PerformanceTest {
28   private static class NullOutputStream extends OutputStream {
write(int b)29     public void write(int b) throws IOException {
30     }
31   }
32 
33   @Test
bigArray()34   public void bigArray() throws IOException {
35     // It should not take more than 1 second to load the default object view
36     // for any object, including big arrays.
37     TestDump dump = TestDump.getTestDump();
38 
39     Instance bigArray = (Instance)dump.getDumpedThing("bigArray");
40     assertNotNull(bigArray);
41 
42     AhatSnapshot snapshot = dump.getAhatSnapshot();
43     AhatHandler handler = new ObjectHandler(snapshot);
44 
45     PrintStream ps = new PrintStream(new NullOutputStream());
46     HtmlDoc doc = new HtmlDoc(ps, DocString.text("bigArray test"), DocString.uri("style.css"));
47     String uri = "http://localhost:7100/object?id=" + bigArray.getId();
48     Query query = new Query(DocString.uri(uri));
49 
50     long start = System.currentTimeMillis();
51     handler.handle(doc, query);
52     long time = System.currentTimeMillis() - start;
53     assertTrue("bigArray took too long: " + time + "ms", time < 1000);
54   }
55 }
56