TPTP Agent Controller使用说明

 

概述
本文本档主要说明独立运行的Agent Controller的安装和配置。为了调优一个运行于远程机器上的java程序或者在远程机器上运行TPTP测试,你首先需要在那台远程机器上安装一个独立的Agent Controller。如果只是在本地调优一个java程序或者运行TPTP测试,你可以选择在本地安装一个独立的Agent Controller或者使用集成的Agent Controller。如果使用集成的Agent Controller,则在进行调优时不需要安装和配置独立Agent Controller。


要求
1、安装JRE或者JDK1.5(或更高)或1.4。
2、删除或卸载先前安装的Agent Controller版本。
3、Agent Controller编译的时候使用了libstdc++-libc6.2-2.so.3共享库。因此请确认该共享库存在于/usr/lib目录。如果不存在,你需要安装RPM包compat-libstdc++.


注释
<install-dir>=Agent Controller解压后所在的目录的绝对路径。如/opt/tptpAC


安装Agent Controller
从TPTP的下载页面下载Agent Controller的运行包。安装的过程只是简单的创建一个目录,并把下载的包的内容解压到那个目录下。


设置Agent Controller

在安装好Agent Controller后,在启动前,你需要对Agent Controller进行一些配置。


配置AgentController
1、确定安装到<install-dir>/bin和<install-dir>/lib目录下的文件具有可执行的权限。
2、在命令行模式下运行<install-dir>/bin/SetConfig.sh脚本来生成Agent Controller的配置文件。脚本需要java虚拟机出现在的PATH的环境变量里。根据提示输入相应的配置参数。脚本会根据你输入的信息生成配置文件<install-dir>/config/serviceconfig.xml。
3、添加<install-dir>/bin目录到环境变量PATH里。
4、添加<install-dir>/lib到环境变更LD_LIBRARY_PATH里。如果是windows则把这个目录也同时添加到PATH环境变量里即可。
如果你需要对第一步生成的配置文件进行修改,你可以重新运行SetConfig.sh脚本,或者手工的编辑配置文件。配置文件的配置规则和说明可以在下面的文档里找到。http://www.eclipse.org/tptp/home/downloads/4.5.0/documents/installguide/agentcontroller_45/ref/ac/r_config_ovw.html。修改配置文件后,必须要重新启动Agent Controller才会生效。
如果linux下安装Agent Controller的时候用了root用户,如果非root用户要设置正确的文件权限才可以运行SetConfig.sh。
下面脚本是一些对相关文件进行权限设置的例子:
      #!/bin/sh
      chmod a+rwx org.eclipse.tptp.platform.ac.linux_ia32*/agent_controller/config
      chmod a+rw org.eclipse.tptp.platform.ac.linux_ia32*/agent_controller/config/*
      chmod a+rwx org.eclipse.hyades.execution*/config
      chmod a+rw org.eclipse.hyades.execution*/config/*
      chmod a+rwx org.eclipse.hyades.logging.core*/config
      chmod a+rw org.eclipse.hyades.logging.core*/config/*
      chmod a+rwx org.eclipse.hyades.test.core*/config
      chmod a+rw org.eclipse.hyades.test.core*/config/*
      chmod a+rwx org.eclipse.hyades.test.tools.core*/config
      chmod a+rw org.eclipse.hyades.test.tools.core*/config/*
      chmod a+rwx org.eclipse.tptp.monitoring.instrumentation*/config
      chmod a+rw org.eclipse.tptp.monitoring.instrumentation*/config/*
      chmod a+rwx org.eclipse.tptp.platform.collection.framework*/config
      chmod a+rw org.eclipse.tptp.platform.collection.framework*/config/*
      chmod a+rwx org.eclipse.tptp.platform.logging.events*/config
      chmod a+rw org.eclipse.tptp.platform.logging.events*/config/*
      chmod a+rwx org.eclipse.tptp.test.tools.junit.plugin*/config
      chmod a+rw org.eclipse.tptp.test.tools.junit.plugin*/config/*
      chmod a+rwx org.eclipse.tptp.trace.arm*/config
      chmod a+rw org.eclipse.tptp.trace.arm*/config/*
      chmod a+rwx org.mx4j.jmx*/config
      chmod a+rw org.mx4j.jmx*/config/*
      chmod a+rwx org.opengroup.arm*/config
      chmod a+rw org.opengroup.arm*/config/*
      chmod a+rwx org.eclipse.hyades.probekit*/config/
      chmod a+rw org.eclipse.hyades.probekit*/config/*
      chmod a+rwx org.eclipse.tptp.platform.jvmti.runtime*/config
      chmod a+rw org.eclipse.tptp.platform.jvmti.runtime*/config/*


启动Agent Controller
启动Agent Controller前,你需要改到你的工作目录为<install-dir>/bin,然后运行ACStart.sh。
Note:Agent Controller为了向前兼容,也可以通过RAStart.sh脚本来启动。


关闭Agent Controller
关闭Agent Controller前,你需要改变你的工作目录为<intall-dir>/bin,然后运行ACStop.sh。
Note:Agent Controller为了向前兼容,也可以通过RAStop.sh脚本来关闭。


查询Agent Controller的版本信息
为了查询Agent Controller的版本信息,你需要改变你的工作目录为<install-dir>/bin,然后运行下面的命令:
ACServer -v 或者 ACServer -version
Agent Controller将在终端上显示它的版本信息。
Note:Agent Controller为了向前兼容,你也可以通过RAServer来查询版本信息。


检查Agent Controller安装的正确性
如果需要,你可以通过Agent Controller运行包里带的SampleClient程序来检查安装的正确性。
执行下面的步聚:
1、启支Agent Controller。
2、打开一个命令窗口。
3、进入<install-dir>bin目录。
4、在命令窗口里输入下面的命令:
      SampleClient
5、观察SampleClient的控制台输出。它应该输出如下的内容:
------------------- SampleClient Console Output --------------------------------

Connected to the Agent Controller on "localhost" at port number #####

The Time Collector Agent ID: ###

Established a data channel with the agent.

Sending 5 Hello messages over data channel to TimeCollector ...

Start the TimeCollector ...

Incoming data: Hello from Time Collector Agent - Count 0

Incoming data: Hello from Time Collector Agent - Count 1

Incoming data: Hello from Time Collector Agent - Count 2

Incoming data: Hello from Time Collector Agent - Count 3

Incoming data: Hello from Time Collector Agent - Count 4


Stop the TimeCollector ...

Incoming data: Hello from Time Collector Agent - Count 5

Incoming data: Hello from Time Collector Agent - Count 6

Incoming data: Hello from Time Collector Agent - Count 7

Incoming data: Hello from Time Collector Agent - Count 8

Incoming data: Hello from Time Collector Agent - Count 9

Incoming data: Hello from Time Collector Agent - Count 10

All finished
Press any key to exit...

注意:上面的端口和Agent ID值通常情况下分别是10006和103,它依赖于Agent Controller的配置和SampleClient程序的运行次数。
服务器日志
所有的服务器日志都统一的存入到<install-dir>/config/servicelog.log文件里。

调优(Profiling)java程序
你能够通过Java Profiling Agent来调优一个java程序,它是一个附加到JVM上,用来搜集和记录java程序的一个库。agent的输出内容为XML片段。XML片段的格式的描述可以在http://www.eclipse.org/tptp/platform/documents/resources/profilingspec/XML4Profiling.htm上找到。
你也能够通过Eclipse的workbench或者独立的命令行模式来调用Java Profiling Agent。

从Eclipse Workbench上调用Java Profiler
通过Eclipse workbench,你可以启动并调试当前Eclipse工作区内的一个java应用,也可以启动并调试一个工作区外的文件系统上的java应用。如果是从eclipse workbench中调用Java Profiler,你必须在eclipse里安装Test and Performance Tools Platform(TPTP)。如果是调试一个本地的java应用,你可以采用集成的Agent Controller或在本地安装的独立的Agent Controller的方式在eclipse里进行调试。如果是调试远程应用,你必须在Java应用所在的机器上安装Agent Controller。

为了启动Java Profiler,通过Eclipse workbench的Profiling and Logging视图,使用Run->Open Profile Dialog...菜单或者使用工具栏上的Profile按钮。Profile的向导将为打开,简单的引导你完成一个应用的调试工作。

从命令行调用Java Profile
如果从命令行运行Java Profiler,则你不需要安装Test and Performance Tools Platform(TPTP),但你需求在java应用所在的机器上安装Agent Controller。

在java 1.4(或更低)的虚拟机下使用Java Profiler


使用-Xrun java参数来调用Java Profiler Agent。如下:
-XrunpiAgent[:agent_param[,agent_param]*]


例如调试PerformanceExample.java时,使用myFilters.txt文件里定义的过滤器,并且相关的调试数据直接写入到文件PEProfilingData时,运行下面的命令:
java -XrunpiAgent:server=standalone,filters=myFilters.txt,file=PEProfilingData.trcxml PerformanceExample

根据-XrunpiAgent参数,你能够指定profiling agent的不同运行模式。参数agent_param能够使用下面的一些值:

    *  server=[standalone | enabled | controlled | applicationControlled]

      standalone
          The Java Profiler is manually attached to a JVM instance and generates a stand-alone trace to a specified file based on the options and filters given on the command line. When this option is selected, the Java Profiler produces the enclosing traceRoot element to form a complete and valid XML document.
      enabled
          The Java Profiler is loaded, allows the application to run normally, but produces no trace until a Eclipse workbench attaches to the agent to give it instructions. When this option is selected, the Java Profiler only produces XML fragments instead of a complete XML document.
      controlled
          The Java Profiler is loaded, and the application is blocked from running until a client gives it instructions to continue. When this option is selected, the Java Profiler only produces XML fragments instead of a complete XML document.
      applicationControlled
          Profiling operations are controlled by the TPTP "Profiler" java class. The pluginconfig.xml file must be modified to use this mode. The pluginconfig.xml is located in the following directory:

          <install-dir>/plugins/org.eclipse.tptp.platform.collection.framework_<version>/config/pluginconfig.xml

          The following modification is required:

          <Agent client="DYNAMIC" configuration="default" dataChannelSize="64M" name="Java Profiling Agent" type="Profiler"/>

          should be modified to

          <Agent client="HEADLESS" configuration="default" dataChannelSize="64M" name="Java Profiling Agent" type="Profiler" logFile="<some_dir>/profile.trcxml"/>

          Note that the Agent client attribute has been changed to "HEADLESS" and that the "logFile" attribute has been added.
          The hcframe.jar file should also be included in the user's class path when profiling an application under this mode. For example:

           java -XrunpiAgent:server=applicationControlled -classpath .:<install-dir>/plugins/org.eclipse.tptp.platform.collection.framework_<version>/hcframe.jar TestClass

    * filters=filename

        Note: This parameter is only used when server=standalone is specified.

    Specifies the name of the file that contains the initial class filter definitions to be used during the trace. The default is filters.txt in the current directory.

    The format of the file is as follows:

        <classpattern> <methodpattern> <mode> where:

    classpattern
        is a string with no embedded blanks. The string may contain a single "*" either at the beginning of the string or at the end of the string. The "*" will match zero or more characters, thus making the pattern a generic prefix or suffix pattern. A single "*" can also be specified to represent all strings.
    methodpattern
        is a string with no embedded blanks. The string may contain a single "*" either at the beginning of the string or at the end of the string. The "*" will match zero or more characters, thus making the pattern a generic prefix or suffix pattern. A single "*" can also be specified to represent all strings.
    mode
        is one of INCLUDE or EXCLUDE. Filter patterns are processed in the order that they are specified until the first pattern match succeeds. If the class name does not match any of the specified filter patterns, the default is to INCLUDE the class.

    * file=filename

          Note: This parameter is only used when server=standalone is specified.

      Specifies the name of a file where the trace will be written. The default is trace.trcxml in the current directory.

    * help
      Displays a list of available agent options to standard out.

在java 1.5(或更高)的虚拟机下使用Java Profiler


使用-agentlib Java参数来调用Java Profiling Agent:

-agentlib:JPIBootLoader=JPIAgent[:[help]|[<option>=<value>,...]];<profiler>[:<option>=<value>,...]

命令行由于下的结构组成:

JPIBootLoader是载入的profiling agent库。
 
JPIAgent是一个Java 5.0+ profiling agent.通过JPIAgent的命令行附加的参数,你能够控制profiling agent的行为,下面是一些支持的参数值说明:

    * server=[standalone | enabled | controlled]

      standalone
          The profiling agent runs in a headless mode, which means it is not possible to interact with it from the workbench. Configuration information is provided as part of the command lineand profiling data is stored in a file directly by the profiling agent. The profiling file can then be imported into the workbench at a later date.
          The Java Profiling Agent is manually attached to a JVM instance and generates profiling data to an output file. The default output file is called trace.trcxml, but you can specify a different file name using the file= filename parameter. When this option is selected, the Java Profiling Agent produces an enclosing traceRoot element to form a complete and valid XML document.
      enabled (This is the default.)
          The profiling agent runs in the background of the JVM without consuming resources until it is connected to by the workbench and asked to start monitoring. Data is then streamed over the agent's data channel and consumed by the workbench. This mode allows the application to run normally, but produces no profiling data until a client attaches to the agent to give it instructions. When this option is selected, the Java Profiling Agent produces only XML fragments instead of a complete XML document.
      controlled
          The profiling agent preempts the JVM from initialization (the agent is loaded but it blocks the application from running) until it is attached to from the workbench and given instructions to start monitoring by a client. That is, when the profiling agent is launched in controlled mode, it will appear to hang the JVM until asked to start monitoring and it will produce only XML fragments instead of a complete XML document.

    * filters=filename
      Used only when server=standalone is specified.
      Specifies the name of the file that contains the initial class filter definitions to be used during the profiling session. The default file name is filters.txt in the current directory. See below for information about the file format.
    * file=filename
      Used only when server=standalone is specified.
      Specifies the name of a file that the profiling data will be written to. The default is trace.trcxml in the current directory.
    * help
      Displays a list of available agent options to STDOUT.

<Profiler> 是需要载入的Profiler库的名称. 下面是有效的profiler及对应的参数:

    * CGProf
      Execution time analysis. Supports the following options:

      execdetails=[true | false] : whether to collect execution flow/call-graph information (true) or not (false). Default is false.
    * HeapProf
      Object allocation/heap analysis. Supports the following options:

      allocsites=[true | false] : whether to collect object allocation site information (true) or not (false). Default is false.
    * ThreadProf
      Thread analysis.

在linux下运行独立模式的Java profiling,执行下面的步骤:

   1. 设置TPTP_AC_HOME=<<Agent Controller Home>>
   2. 设置JAVA_PROFILER_HOME=$TPTP_AC_HOME/plugins/org.eclipse.tptp.javaprofiler
   3. 添加到下面的目录到 LD_LIBRARY_PATH:

      $JAVA_PROFILER_HOME:$TPTP_AC_HOME/lib:$TPTP_AC_HOME/bin
   4. 通过-agentlib参数执行java程序。参数已在上面有描述。

注意: 确保你的整个-agentlib用单引号括起。否则,linux shell可能把profiler name前面的分号(;)解析成命令结束,导致java程序不能被启动。

例子:

   1. 为了在standalone模式下调试"HelloWorld"java应用程序的CPU性能,并且将结果写入到log.trcxml中:

      java '-agentlib:JPIBootLoader=JPIAgent:server=standalone,file=log.trcxml;CGProf' HelloWorld

   2. 为了在standalone下调试"HelloWorld" Java应用的Heap性能,使用myFilter.txt文件里定义的过滤器,并且将采集对角的分配的source location信息。

      java '-agentlib:JPIBootLoader=JPIAgent:server=standalone,filters=myFilter.txt;HeapProf:allocsites=true' HelloWorld

Class Filter 文件格式

过滤器文件必须指三个字段,package/class,method,mode,格式如下:
   package/class method mode

说明:

    package/class
    这个字段指定了package和class名称的匹配模式。匹配模式必须是一个不包含空格的字符串。字符串可以包含一个星号(*),星号可以出现在字符串的开始或者结尾,如*.mypackage or org.mycompany.*。*匹配零个或多个字符,因此可以构造一个前匹配或者后匹配的通用表达式。单独的一个*号可以匹配所有字符串。
     method
               这个字段用来指定方法名的匹配模式。匹配模式必须是一个不包含空格的字符串。其他的规则同class字段。
    mode
                这个字段指定了符合匹配规则的package或者class是包含(参与)profiling呢还是排除。它的值可以是
        INCLUDE或者EXCLUDE。

过滤器的处理顺序为找到第一个符合规则的匹配即结束。如果一个类名没有任务匹配的规则,默认是包含这个类。

控制Java Profiling Agent

当启动Java Profiling Agent时包含了server=enabled或者server=controlled参数, 和agent的通讯将通过客户端工作台和运行于主机上的Agent Controller的来完成。
关Java Profiler的注意事项

    * 如果你没有在命令行里指定过滤器定义文件,Java Profile Agent将试图从当前工作目录读取名为filters.txt的过滤器文件。如果filters.txt不存在,则在调试的过程中将不包含任务过滤器。如果你将你自己定义的过滤器命名为filters.txt,并且也放在当前目录,你则不需要在命令行里指定filters参数。
    * 如果你没有指定profiling数据的输出文件,则它将被保存到trace.trcxml。
    * 你不需要指定办出文件的扩展名。系统将自动采用.trcxml的扩展名。
    * 你不需要指定你的java程序的扩展名。

卸载agent controller:


   1. 停止agent controller:
   2. 删除<install-dir>.
   3. 从PATH环境变量里删除<install-dir>/bin目录。
   4. 从LD_LIBRARY_PATH环境变量里删除 <install-dir>/lib目录。


参考:

AgentController下载地址:http://www.eclipse.org/tptp/home/downloads/#agentController

官方英文AgentControoler安装手册

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值