public static void main(String[] args) { new LookAtMe((System.currentTimeMillis() % 3000) + 100).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 300).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 500).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 700).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 900).start(); } }
다음 화면과 같이 컴파일한다.
Remote site 에 TPTP 4.4.1 설치하고 실행하기
Eclipse 내에서 실행되는 Application 을 profiling 하기 위해서는 Integrated Agent Controller 를 쓰면 되기 때문에 Eclipse 외에 별도의 설치가 필요없다.
하지만, Remote site 에서 실행되는 Application 을 Profiling 하기 위해서는 Remote site 에 별도의 TPTP Agent Controller 를 설치해줘야 한다. (이 문서에서는 하나의 컴퓨터에서 모두 설정하지만, Eclipse 가 실행되는 환경과 Remote site 는 별개의 컴퓨터라고 샘각해야 한다.)
Remote site 에 TPTP Agent Controller 를 설치하려면, 다음 URL 에서 Remote site 의 환경에 맞는 TPTP 를 설치한다.
@(#)JVMTI Agent version 1.0.0.1 Usage: -agentlib:JPIBootLoader=JPIAgent[:[help]|[<option>=<value>, ...]];<profiler>
Where: help Displays this message <option>=<value> Command line options (see below) <profiler> The profiler to launch: CGProf Execution time analysis HeapProf Memory analysis ThreadProf Thread analysis
Supported option names and values: server=standalone|enabled|controlled file=<file> Output file (default is trace.trcxml) Only applicable when server=standalone filters=<file> Filter definition file (default is filters.txt) Only applicable when server=standalone profiler=<file> Profiling options file (default is jvmti.pro) Only applicable when server=standalone
Examples
Execution time analysis in standalone mode: java -agentlib:JPIBootLoader=JPIAgent:server=standalone,file=log.trcxml;CGProf < Java class file>
Memory analysis in controlled mode: java -agentlib:JPIBootLoader=JPIAgent:server=controlled;HeapProf <Java class fil e>
Error occurred during initialization of VM agent library failed to init: JPIBootLoader
이렇게 안내문이 출력되면 설정은 잘 된것이다.
추가로, 다음과 같이 Eclipse 없이 독자적으로 Profiling 을 하는 Standalong 모드로 실행해서 Profiling 이 잘 되는지를 확인해본다.
우선, 메너에서 Help > Software Updates > Find and Install 을 선택해서 "Install/Update" 창을 띄운 후, "Search for new features to install" 옵션을 선택하고 Next 버튼을 누른다.
그 다음, "Europa Discovery Site" 을 선택하고 Next 버튼을 누르고, "Update site mirrors" 창에서 적절한 미러 사이트를 선택한다. (이 글을 쓰는 시점에서 Daum 측 미러사이트는 EMF 업데이트가 안되는 문제가 있어 KAIST 측 미러사이트로 진행했다.)
이제 다음 화면과 같이 Updates 창에서 "Testing and Performance" 과 "Select Required" 버튼을 누르고 Next 버튼을 누른다.
이후 안내를 따라 진행하다가 설치가 끝난 후 Eclipse 를 재시작시킨다.
Profiliing 할 Java 프로젝트 준비하기
먼저, Integrated Agent Controller 는 기본으로 비활성화되어 있다.
이를 활성화하기 위해 다음 그림과 같이 Preferences - Agent Controller - Integrated Agent Controller 화면에서 Enable 을 선택하고 OK 버튼을 누른다.
이제, 다음과 같이 LookAtMe 라는 Java 프로젝트를 만든다.
소스코드는 다음과 같다.
package lookatme;
public class LookAtMe extends Thread { private long sleepTime;
public static void main(String[] args) { new LookAtMe((System.currentTimeMillis() % 3000) + 100).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 300).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 500).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 700).start(); new LookAtMe((System.currentTimeMillis() % 3000) + 900).start(); } }
Window - Profile... 메뉴를 선택해서 다음 화면과 같이 LookAtMe 라는 Profile Configuration 을 만든다.
다음 화면과 같이 Monitor 탭에서 3가지 Profiling 모드중에서 하나를 선택할 수 있다. 우선은 Execution Time Analysis 를 선택해둔다.
위 화면에서 Profile 버튼을 누르거나, 다음 화면과 같이 Profile 실행버튼에서 LookAtMe Configuration 을 선택해서 Profiling 을 시작한다.
Profiling 하기 - Execution Time Analysis
이전에 만든 LookAtMe_remote 라는 Profile Configuration 을 실행하면 Profiling and Logging Perspective 로 바뀌면서 Monitor 탭에서 설정했던 대로 Execution Time Analysis 를 할 수 있다.
다음 화면은 Execution Time Analysis 를 한 직후의 모습이다.
왼쪽 트리에서 방금 실행한 Profile 세션에 있는 Execution Time Analysis 를 더블클릭하면 다음 화면과 같이 Session summary 를 볼 수 있다.
하단에 있는 탭을 이용하면 다른 정보들을 얻을 수 있는데, 우선, Filter 설정을 없애야 모든 정보를 볼 수 있으므로 다음 화면과 같이 Execution Statistics 에서 No Filter 설정을 한다.
다음 화면은 No Filter 설정이 된 Execution Statistics 이다.
다음 화면은 Call Tree 에서 LookAtMe(long) 생성자를 선택한 모습이다.
다음 화면은 Method Invacation Details 에서 LookAtMe(long) 생성자를 보는 모습이다.
다음 화면은 Method Invation 에서 getCount() 메소드를 보는 모습이다.
왼쪽 트리에서 방금 실행한 Profile 세션에 있는 Execution Time Analysis 를 더블클릭하지 않고, 오른쪽 마우스버튼을 이용하면 다른 형식으로 화면을 열 수도 있다.
다음 화면은 Execution Flow 를 보는 모습이다.
다음 화면은 UML2 Class Interactions 를 보는 모습이다.
UML2 Class Interactions 화면에서 빨간 색 부분에 마우스 포인터를 대면 다음 화면가 같이 실행시간이 표시된다. 빨간 색이 짙을 수록 실행시간이 긴 것을 나타낸다.
다음 화면은 Class Thread Interactions 화면을 보는 모습이다.
이 모든 결과는 현재 Profiling 되는 실시간 값이며, Profiling 을 중지하면 중지한 순간까지의 결과를 볼 수 있다.
Profiling 하기 - Memory Analysis
다음 화면은 LookAtMe Configuration 의 Monitor 탭에서 Memory Analysis 를 선택하고 실행한 뒤, lookatme.LookAtMe 클래스에 대한 Memory Statistics 를 보는 모습이다. (오른쪽 위에서 클래스 대신 패키지 기준으로 보도록 선택했다.)
다음 화면은 이전 화면에서 lookatme.LookAtMe 클래스를 더블클릭하거나 이 클래스가 선택된 상태에서 하단 탭의 Allocation Details 를 선택한 모습이다.
이 화면들에서 각 컬럼의 의미는 다음과 같다.
Live Instances
GC 되지 않고 살아있는 인스턴스
Active Size (bytes)
해당 인스턴스 자체가 Heap 에서 차지하고 있는 용량
Total Instances
GC 된 인스턴스와 GC 되지 않은 인스턴스의 총합
Total Size (bytes)
해당 인스턴스에 대해 GC 된 용량과 살아있는 용량을 합한 용량
Avg. Age
한 번의 GC 에서 살아남으면 Age 가 하나 증가한다.
테스트 프로그램에 대해 Profiling 하기 - Thread Analysis
다음 화면은 LookAtMe_remote 의 Monitor 탭에서 Thread Analysis 를 선택하고 실행한 뒤, Thread Statistics 를 보는 모습이다. (상단의 Show Call Stack 버튼을 누른 상태이다.)