.bash_profiler 파일 수정#

다음 설정을 추가한다. 단 JAVA_HOME과 JPROFILER_HOME는 설치에 따라 유동적인 값을 가진다.

JAVA_HOME=/home/fromm0/env/java
JPROFILER_HOME=/home/fromm0/env/jprofiler5/bin/linux-x86

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JPROFILER_HOME
export PATH=$PATH:$JAVA_HOME/bin

catalina.sh 파일 수정#

<div class="warning"> 아래 설정은 catalina.sh파일에 가장 상단에 셋팅하도록 한다. </div> <div class="information"> 세션 id에 해당되는 id값은 config파일내 session으로 존재하는 값이어야 한다. </div>

CATALINA_OPTS="$CATALINA_OPTS -agentlib:jprofilerti=offline,id=147,config=/home/fromm0/env/jprofiler5/config/config.xml \ 
-Xbootclasspath/a:/home/fromm0/env/jprofiler5/bin/agent.jar"

-agentpath:/home/fromm0/env/jprofiler7/bin/linux-x86/libjprofilerti.so=offline 

tomcat로그#

JProfiler> Protocol version 25
JProfiler> Using JVMTI
JProfiler> 32-bit library
JProfiler> Offline profiling mode.
JProfiler> Using config file C:\Documents and Settings\fromm0\.jprofiler5\config.xml (id: 149)
JProfiler> Listening on port: 8849.
JProfiler> Native library initialized
JProfiler> Using dynamic instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
JProfiler> Hotspot compiler enabled
JProfiler> Starting org/apache/catalina/startup/Bootstrap ...

프로파일링 데이터를 가져오기 위한 프로그래밍#

ant_common.xml

설정내용중 변경할 필요가 있는 값은 bin.dir 정도이다.

<!-- Common helper targets for all samples for starting a profiling session -->
<project>

  <property name="bin.dir" value="C:/Program Files/jprofiler5/bin"/>

  <target name="prepare" depends="setNativeLibDir, setNativeLibEnvVar, checkJava, copyLicenseKey"/>

  <target name="checkJava">
    <condition property="java14OrLower">
      <or>
        <equals arg1="${ant.java.version}" arg2="1.2"/>
        <equals arg1="${ant.java.version}" arg2="1.3"/>
        <equals arg1="${ant.java.version}" arg2="1.4"/>
      </or>
    </condition>
    <fail if="java14OrLower">All samples require a Java 1.5 JRE or higher. Note that this is _not_ a general restriction for the JProfiler API and platform, they do work with Java 1.2 and higher.</fail>
  </target>

  <target name="setNativeLibDir" depends="setPlatform">
    <property name="nativelib.dir" location="${bin.dir}/${platform}"/>
  </target>

  <target name="setPlatform" unless="platform">
    <condition property="platform" value="windows">
      <os family="windows" arch="x86"/>
    </condition>

    <condition property="platform" value="windows-x64">
      <os family="windows" arch="amd64"/>
    </condition>

    <condition property="platform" value="macos">
      <os family="mac"/>
    </condition>

    <condition property="platform" value="linux-x86">
      <os name="linux" arch="x86"/>
    </condition>
    <condition property="platform" value="linux-x64">
      <os name="linux" arch="amd64"/>
    </condition>

    <condition property="platform" value="solaris-sparc">
      <os name="sunos" arch="sparc"/>
    </condition>
    <condition property="platform" value="solaris-sparcv9">
      <os name="sunos" arch="sparcv9"/>
    </condition>
    <condition property="platform" value="solaris-x86">
      <os name="sunos" arch="x86"/>
    </condition>
    <condition property="platform" value="solaris-x64">
      <os name="sunos" arch="x64"/>
    </condition>

    <condition property="platform" value="hpux-parisc">
      <os name="hp-ux" arch="pa_risc2.0"/>
    </condition>
    <condition property="platform" value="hpux-parisc64">
      <os name="hp-ux" arch="pa_risc2.0w"/>
    </condition>

    <condition property="platform" value="aix-ppc64">
      <os name="aix" arch="ppc64"/>
    </condition>
    <condition property="platform" value="aix-ppc">
      <os name="aix" arch="ppc"/>
    </condition>

    <fail unless="platform">Could not determine native library directory. Please pass the -Dplatform=...  property manually to this ant script.</fail>
  </target>

  <target name="setNativeLibEnvVar">

    <property environment="env"/>

    <condition property="nativelib.envvar" value="Path">
      <and>
        <os family="windows"/>
        <isset property="env.Path"/>
      </and>
    </condition>

    <condition property="nativelib.envvar" value="PATH">
      <and>
        <os family="windows"/>
        <not>
          <isset property="nativelib.envvar"/>
        </not>
      </and>
    </condition>

    <condition property="nativelib.envvar" value="DYLD_LIBRARY_PATH">
      <os family="mac"/>
    </condition>

    <condition property="nativelib.envvar" value="SHLIB_PATH">
      <os name="hp-ux"/>
    </condition>

    <condition property="nativelib.envvar" value="LIBPATH">
      <os name="aix"/>
    </condition>

    <condition property="nativelib.envvar" value="LD_LIBRARY_PATH">
      <not>
        <isset property="nativelib.envvar"/>
      </not>
    </condition>

    <setEnvvarValue varname="${nativelib.envvar}"/>

  </target>

  <macrodef name="setEnvvarValue">
    <attribute name="varname"/>
    <sequential>
      <property environment="env"/>
      <property name="nativelib.envvarValue" value="${env.@{varname}}"/>
    </sequential>
  </macrodef>

  <target name="copyLicenseKey">

    <property name="userConfigFile" location="${user.home}/.jprofiler5/config.xml"/>
    <property name="sampleConfigFile" location="common/config.xml" />

    <available file="${userConfigFile}" type="file" property="configFileExists"/>
    <fail unless="configFileExists">Config file ${userConfigFiledoes not exist. Please run JProfiler and enter your license key.</fail>

    <available file="${sampleConfigFile}" type="file" property="sampleConfigFileExists"/>
    <fail unless="sampleConfigFileExists">Cannot find the sample config file ${sampleConfigFile}</fail>

    <loadfile property="licenseKey" srcFile="${userConfigFile}" encoding="UTF-8">
      <filterchain>
        <linecontains>
          <contains value="&lt;licenseKey"/>
        </linecontains>
        <striplinebreaks/>
        <tokenfilter>
          <filetokenizer/>
          <containsregex pattern=".*key=&quot;(.*[#|:].*)&quot;.*" replace="\1"/>
        </tokenfilter>
      </filterchain>
    </loadfile>

    <fail unless="licenseKey">No license key was found in the config file ${userConfigFile}. Please run JProfiler and enter your license key.</fail>

    <echo>Copying license key from ${userConfigFileto ${sampleConfigFile}</echo>

    <replaceregexp file="${sampleConfigFile}" encoding="UTF-8" match="&lt;licenseKey key=&quot;.*&quot;" replace="&lt;licenseKey key=&quot;${licenseKey}&quot;" />

  </target>


</project>

build.xml

<!--
  Compile and run the offline profiling sample code. See src/TestProgram.java for more information.

  Note: A 1.5 JRE is required for compiling and running this sample
  1.2-1.4 JREs can be used by replacing "-agentlib:jprofilerti=" with "-Xrunjprofiler:", porting the Java code
  to the Java 1.4 syntax and using the retroweaved platform_java_14.jar instead of platform.jar.
-->
<project name="offline" default="run">

  <import file="common/ant_common.xml"/>

  <target name="compile" depends="prepare" description="Compile the offline profiling sample">

    <!-- The controller API classes are contained in agent.jar -->
    <javac srcdir="src">
      <classpath>
        <fileset dir="${bin.dir}">
          <include name="agent.jar"/>
        </fileset>
      </classpath>
    </javac>

  </target>

  <target name="clean" description="Delete all compiled classes and saved snapshot files">
    <delete>
      <fileset dir=".">
        <include name="src/**/*.class"/>
        <include name="*.jps"/>
      </fileset>
    </delete>
  </target>

  <target name="run" depends="compile,setNativeLibDir" description="Run the offline profiling sample">

    <java classname="com.nhn.TestProgram" fork="true">

      <!-- If you change this parameter to "true", the test programm will trigger heap dumps for the snapshot files -->
      <arg value="false"/>

      <!-- VM parameter that loads native profiling agent for Java 1.5+ and activate offline profiling mode -->
      <jvmarg value="-agentlib:jprofilerti=offline,id=149,config=C:\Documents and Settings\fromm0\.jprofiler5\config.xml"></jvmarg>

      <!-- The agent JAR file is added to the boot classpath -->
      <jvmarg value="-Xbootclasspath/a:${bin.dir}/agent.jar"></jvmarg>

      <!-- the native library path environment variable has to be modified to include the platform-specific native library directory
           of the JProfiler distribution -->
      <env key="${nativelib.envvar}" path="${nativelib.dir}:${nativelib.envvarValue}"/>

      <classpath>
        <pathelement path="src"/>
      </classpath>
    </java>
  </target>

</project>

TestProgram.java

package com.nhn;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.jprofiler.api.agent.Controller;

public class TestProgram {

  private static final int COUNT = 100000;

  // These lists hold objects to illustate memory profiling
  private static List<Double> sines = new ArrayList<Double>(COUNT);
  private static List<Double> squareRoots = new ArrayList<Double>(COUNT);
  private static List<Double> logs = new ArrayList<Double>(COUNT);

  private static boolean triggerHeapdumps = false;

  public static void main(String[] args) {

    // Pass "true" as the first parameter to trigger heap dumps
    if (args.length > && Boolean.parseBoolean(args[0])) {
      triggerHeapdumps = true;
    }

    // On startup, JProfiler does not record any data. The various recording
    // subsystems have to be
    // switched on programatically.
    Controller.startCPURecording(true);
    Controller.startAllocRecording(true);
    Controller.startThreadProfiling();
    Controller.startVMTelemetryRecording();

    // This is observer method
    calculateStuff();

    // You can switch off recording at any point. Recording can be switched
    // on again.
    Controller.stopCPURecording();
    Controller.stopAllocRecording();
    Controller.stopThreadProfiling();
    Controller.stopVMTelemetryRecording();

  }

  private static void calculateStuff() {

    // Bookmarks can be added with the API.
    Controller.addBookmark("Start calculating sines");
    calculateSines();
    if (triggerHeapdumps) {
      // If you would like to use the heap walker for saved snapshots, you
      // have to trigger a heap dump at some point.
      // The last heap dump will be saved in the snapshot file. This makes
      // snapshot files much larger and creates
      // significant memory overhead.
      Controller.triggerHeapDump(true, true, true);
    }
    // Now we save a snapshot with all recorded profiling data
    Controller.saveSnapshot(new File("after_sines.jps"));

    // The same sequence with a different method
    Controller.addBookmark("Start calculating square roots");
    calculateSquareRoots();
    if (triggerHeapdumps) {
      Controller.triggerHeapDump(true, true, true);
    }
    Controller.saveSnapshot(new File("after_square_roots.jps"));

    // And a third time
    Controller.addBookmark("Start calculating logs");
    calculateLogs();
    if (triggerHeapdumps) {
      Controller.triggerHeapDump(true, true, true);
    }
    Controller.saveSnapshot(new File("after_logs.jps"));

  }

  private static void calculateSines() {
    double increment = (Math.PI / 2/ COUNT;
    for (int i = 0; i < COUNT; i++) {
      sines.add(Math.sin(increment * i));
    }
  }

  private static void calculateSquareRoots() {
    for (int i = 0; i < COUNT; i++) {
      squareRoots.add(Math.sqrt(i));
    }
  }

  private static void calculateLogs() {
    for (int i = 0; i < COUNT; i++) {
      logs.add(Math.log(i + 1));
    }
  }
}

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 08-Oct-2012 20:10 by DongGukLee