1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package org.cybertaxonomy.utis.utils;
|
11
|
|
12
|
import java.io.PrintStream;
|
13
|
|
14
|
/**
|
15
|
* @author a.kohlbecker
|
16
|
* @date Oct 22, 2015
|
17
|
*
|
18
|
*/
|
19
|
public class Profiler {
|
20
|
|
21
|
// private Controller yourkit;
|
22
|
private boolean yjp = false;
|
23
|
private boolean cpu = false;
|
24
|
private long start;
|
25
|
|
26
|
private Profiler() {
|
27
|
|
28
|
}
|
29
|
|
30
|
public static Profiler newCpuProfiler(boolean yjp) {
|
31
|
Profiler p = new Profiler();
|
32
|
p.yjp = yjp;
|
33
|
p.cpu = true;
|
34
|
if(yjp) {
|
35
|
// https://www.yourkit.com/docs/java/api/com/yourkit/api/Controller.html
|
36
|
try {
|
37
|
// p.yourkit = new Controller();
|
38
|
// p.yourkit.enableStackTelemetry();
|
39
|
// p.yourkit.startCPUTracing(null);
|
40
|
} catch (Exception e) {
|
41
|
e.printStackTrace();
|
42
|
}
|
43
|
}
|
44
|
|
45
|
p.start = System.currentTimeMillis();
|
46
|
|
47
|
return p;
|
48
|
}
|
49
|
|
50
|
public void end(PrintStream err) {
|
51
|
|
52
|
Long time = System.currentTimeMillis() - start;
|
53
|
|
54
|
try {
|
55
|
err.append(time.toString()).append(" ms\n");
|
56
|
if(yjp) {
|
57
|
if(cpu) {
|
58
|
// yourkit.stopCPUProfiling();
|
59
|
// String fileLocation = yourkit.captureSnapshot(com.yourkit.api.Controller.SNAPSHOT_WITHOUT_HEAP);
|
60
|
// err.append("Snapshot stored at: ").append(fileLocation).append("\n");
|
61
|
}
|
62
|
}
|
63
|
// } catch (IOException e) {
|
64
|
// e.printStackTrace();
|
65
|
} catch (Exception e) {
|
66
|
e.printStackTrace();
|
67
|
}
|
68
|
}
|
69
|
}
|