⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perf3.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
because it is allocated when the program first requests a default timezone. 
However, this same technique can be applied to analyzing your own application 
where you may be able to make some improvements

<H4>Where the Application Spends its Time</H4> 

Again, you can use the <CODE>-Xrunhprof</CODE> parameter to get information 
about the time the application spent processing a particular method.

<P>
You can use one of two CPU profiling options to achieve this. The first option 
is <CODE>cpu=samples</CODE>. This option reports the result of a sampling of 
the running threads of the Java VM to which a statistical count of the 
frequency of the occurrence of a particular method is used to find busy 
sections of the applications. The second option is <CODE>cpu=times</CODE>, 
which measures the time taken by individual methods and generates a sorted 
list ranked as a total percentage of the CPU time taken by the application.

<P>
By using the <CODE>cpu=times</CODE> option, you should see something similiar 
to this at the end of the output file

</FONT>

<PRE>
CPU TIME (ms) BEGIN (total = 11080) 
                       Fri Jan  8 16:40:59 1999
rank   self   accum   count  trace   method
 1   13.81%  13.81%       1   437   sun/
    awt/X11GraphicsEnvironment.initDisplay
 2    2.35%  16.16%       4   456   java/
    lang/ClassLoader$NativeLibrary.load
 3    0.99%  17.15%      46   401   java/
    lang/ClassLoader.findBootstrapClass
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

If you contrast this with the <CODE>cpu=samples</CODE> output, you see the 
difference between how often a method appears during the runtime of the 
application in the samples output compared to how long that method took in 
the times output.

</FONT>

<PRE>
CPU SAMPLES BEGIN (total = 14520) 
                   Sat Jan 09 17:14:47 1999
rank  self   accum   count  trace   method
 1    2.93%  2.93%   425    2532    sun/
    awt/windows/WGraphics.W32LockViewResources
 2    1.63%  4.56%   237     763    sun/
    awt/windows/WToolkit.eventLoop
 3    1.35%  5.91%   196    1347    java/
    text/DecimalFormat.&lt;init&gt;
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

The <CODE>W32LockView</CODE> method, which calls a native windows lock 
routine, is called 425 times. So when it is sampled it appears in the 
active runnings threads because it also takes time to complete. In contrast, 
the <CODE>initDisplay</CODE> method is only called once, but it is the method 
that takes the longest time to complete in real time.

<A NAME="os"></A>
<H3>Operating System Performance Tools</H3>

Sometimes the performance bottleneck occurs at the system or operating system 
level. This is because Java VM depends on many operating system libraries for 
functionality such as disk access or networking. However, what occurs in these 
libraries after the Java VM calls them is beyond the reach of most 
profiling tools for the Java platform.

<P>
Here is a list of tools you can use to analyze performance problems on some 
common operating systems.

<H4>Solaris Platform</H4>

System accounting reports, <CODE>sar</CODE>, reports the activity of the system 
in terms of disk IO, user program activity, and system level activity. If your 
application is using excessive amounts of memory, it may require disk swap 
space, which will show up as high percentages in the WIO column. User programs 
that get stuck in a busy loop show a high percentage in the user column:

</FONT>

<PRE>
developer$ sar 1 10

SunOS developer 5.6 Generic_105181-09 sun4u    
                                      02/05/99

11:20:29    %usr    %sys    %wio   %idle
11:20:30      30       6       9      55
11:20:31      27       0       3      70
11:20:32      25       1       1      73
11:20:33      25       1       0      74
11:20:34      27       0       1      72
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

The <CODE>truss</CODE> command traces and records the details of every system 
call called by the Java VM to the Solaris kernel. A common way to run 
<CODE>truss</CODE> is:

</FONT>

<PRE>
   truss -f -o /tmp/output -p &lt;process id&gt;
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

The <CODE>-f</CODE> parameter follows any child processes that are created, 
the <CODE>-o</CODE> parameter writes the output to the named file, and the 
<CODE>-p</CODE> parameter traces an already running program from its 
process ID. Alternately, you can replace <CODE>-p</CODE> &lt;process id&gt; 
with the Java VM, for example:

</FONT>

<PRE>
   truss -f -o /tmp/output java MyDaemon
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

The <CODE>/tmp/output</CODE> is used to store the <CODE>truss</CODE> output,
which should look similiar to the following:

</FONT>

<PRE>
15573:  execve("/usr/local/java/jdk1.2/solaris/
                bin/java", 0xEFFFF2DC,
	        0xEFFFF2E8)  argc                   = 4
15573:  open("/dev/zero", O_RDONLY)                 = 3
15573:  mmap(0x00000000, 8192, 
             PROT_READ|PROT_WRITE|PROT_EXEC,
	     MAP_PRIVATE, 3, 0) = 0xEF7C0000
15573:  open("/home/calvin/java/native4/libsocket.so.1", 
              O_RDONLY) Err#2 ENOENT
15573:  open("/usr/lib/libsocket.so.1", 
              O_RDONLY)                             = 4
15573:  fstat(4, 0xEFFFEF6C)                        = 0
15573:  mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, 
              MAP_SHARED, 4, 0) = 0xEF7B00 00
15573:  mmap(0x00000000, 122880, PROT_READ|PROT_EXEC, 
              MAP_PRIVATE, 4, 0) = 0xEF7 80000
15573:  munmap(0xEF78E000, 57344)                   = 0
15573:  mmap(0xEF79C000, 5393, 
              PROT_READ|PROT_WRITE|PROT_EXEC,
              MAP_PRIVATE|MAP_FIXED, 4, 49152) 
              = 0xEF79C000
15573:  close(4)                                    = 0
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

In the <CODE>truss</CODE> output, look for files that fail when opened due to 
access problems, such as error <CODE>ENOPERM</CODE>, or a missing file error 
<CODE>ENOENT</CODE>.  You can also track data read or written with the 
<CODE>truss</CODE> parameters <CODE>-rall</CODE> to log all data read 
or <CODE>-wall</CODE> to log all data written by the program. With these 
parameters, it is possible to anaylze data sent over a network or to a 
local disk.

<H4>Linux Platform</H4>

Linux has a trace command called <CODE>strace</CODE>. It traces 
systems calls to the underlying Linux kernel. This example traces the 
<CODE>SpreadSheet</CODE> example in the JDK demo directory.

</FONT>

<PRE>
$ strace -f -o /tmp/output 
                      java sun.applet.AppletViewer 
                      example1.html
$ cat /tmp/output

639   execve("/root/java/jdk117_v1at/java/
               jdk117_v1a/bin/java", ["java",
               "sun.applet.AppletViewer ", 
               "example1.html"], [/* 21 vars */]) = 0
639   brk(0)                              = 0x809355c
639   open("/etc/ld.so.preload", O_RDONLY)       = -1 
        ENOENT (No such file or directory)
639   open("/etc/ld.so.cache", O_RDONLY)          = 4
639   fstat(4, {st_mode=0, st_size=0, ...})       = 0
639   mmap(0, 14773, PROT_READ, MAP_PRIVATE, 
             4, 0) = 0x4000b000
639   close(4)                                    = 0
639   open("/lib/libtermcap.so.2", O_RDONLY)      = 4
639   mmap(0, 4096, PROT_READ, MAP_PRIVATE, 
             4, 0) = 0x4000f000
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

To obtain system information similar to the Solaris <CODE>sar</CODE>
command, read the contents of the file <CODE>/proc/stat</CODE>. The format 
of this file is described in the <CODE>proc</CODE> man page. Look at the 
<CODE>cpu</CODE> line to get the user and system time.

</FONT>

<PRE>
   cpu  4827 4 1636 168329
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

In the above example, the <CODE>cpu</CODE> line indicates 48.27 seconds 
in user space, 0.04 at nice priority, 16.36 seconds processing system 
calls, and 168 seconds idle. This is
a running total; individual entries for each process are available
in <CODE>/proc/&lt;process_id&gt;/stat</CODE>.

<H4>Windows95/98/NT Platforms</H4>

There are no standard performance analysis tools included on this platform,
but the following tools are available by way of freeware or shareware 
resources such as <A HREF="http://www.download.com">http://www.download.com</A> .

<P>
Runtime memory analysis: Memory meter

<P>
Network analysis: Traceplus

<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>

</FONT>
</TD>
</TR>
</TABLE>




<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->

</TD>
</TR>
</TABLE>

<!-- Copyright Insert -->

<BR CLEAR="ALL">

<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">   
  <TR>
    <TD VALIGN="TOP">
	
    <P ALIGN=CENTER>
    <FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
    [ This page was updated: <!-- new date --> 14-Oct-99 ]</font></P>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>
  
  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/products/">Products &amp; APIs</A> | 
    <A HREF="/developer/index.html">Developer Connection</A> | 
    <A HREF="/developer/infodocs/index.shtml">Docs &amp; Training</A> | 
    <A HREF="/developer/support/index.html">Online Support</A><BR>
    <A HREF="/developer/community/index.html">Community Discussion</A> |
    <A HREF="http://java.sun.com/industry/">Industry News</A> | 
    <A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> | 
    <A HREF="http://java.sun.com/casestudies">Case Studies</A>
    </FONT>
    </CENTER>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>

  <TR>
    <TD ALIGN="CENTER">
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> - 
    <A HREF="http://java.sun.com/applets/">Applets</A> - 
    <A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> - 
    <A HREF="http://java.sun.com/jobs/">Employment</A> - 
    <A HREF="http://java.sun.com/nav/business/">Business &amp; Licensing</A> - 
    <A HREF="http://java.sun.com/javastore/">Java Store</A> -
    <A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
    </FONT>
    </TD>
  </TR>

  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <a href="/siteinfo/faq.html">FAQ</a> |
    <a href="/feedback/index.html">Feedback</a> | 
    <a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> | 
    <A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
    </FONT>
    </CENTER>

    </TD>
  </TR>
  
  <TR>
    <TD>

    <TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
      <TR>
        <TD WIDTH="50%">
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        For more information on Java technology<BR>
        and other software from Sun Microsystems, call:<BR>
        </FONT>
        <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
        (800) 786-7638<BR></FONT>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Outside the U.S. and Canada, dial your country's 
        <A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&amp;T&nbsp;Direct&nbsp;Access&nbsp;Number</A> first.<BR>
        </FONT>
        </TD>

        <TD ALIGN="RIGHT" WIDTH="50%">
        <A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Copyright &copy; 1995-99
        <A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
        All Rights Reserved. 
        <a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>. 
        <A HREF="http://www.sun.com/privacy/">Privacy&nbsp;Policy</A>.
        </FONT>
        </TD>
      </TR>
    </TABLE>
	
    </TD>
  </TR> 
</TABLE>
</FORM>

<!-- End Copyright Insert -->


</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -