2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package dalvik.system;
19 import dalvik.system.SamplingProfiler.ThreadSet;
20 import java.math.BigInteger;
21 import java.security.KeyPairGenerator;
22 import java.security.SecureRandom;
23 import javax.crypto.spec.DHParameterSpec;
24 import junit.framework.TestCase;
26 public class SamplingProfilerTest extends TestCase {
28 public void test_SamplingProfiler_basic() throws Exception {
29 ThreadSet threadSet = SamplingProfiler.newArrayThreadSet(Thread.currentThread());
30 SamplingProfiler profiler = new SamplingProfiler(12, threadSet);
35 profiler.writeHprofData(System.out);
38 private static final String P_STR =
39 "9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e3"
40 + "1db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b";
41 private static final String G_STR =
42 "98ab7c5c431479d8645e33aa09758e0907c78747798d0968576f9877421a9089"
43 + "756f7876e76590b76765645c987976d764dd4564698a87585e64554984bb4445"
44 + "76e5764786f875b4456c";
46 private static final byte[] P = new BigInteger(P_STR,16).toByteArray();
47 private static final byte[] G = new BigInteger(G_STR,16).toByteArray();
49 private static void toBeMeasured () throws Exception {
50 long start = System.currentTimeMillis();
51 for (int i = 0; i < 10000; i++) {
52 BigInteger p = new BigInteger(P);
53 BigInteger g = new BigInteger(G);
54 KeyPairGenerator gen = KeyPairGenerator.getInstance("DH");
55 gen.initialize(new DHParameterSpec(p, g), new SecureRandom());
57 long end = System.currentTimeMillis();