{"id":17,"date":"2004-04-18T14:01:13","date_gmt":"2004-04-18T04:01:13","guid":{"rendered":"http:\/\/www.thunderguy.com\/plusplus\/20050421\/profiling-a-java-program-easily\/"},"modified":"2015-11-06T10:57:16","modified_gmt":"2015-11-05T21:57:16","slug":"profiling-a-java-program-easily","status":"publish","type":"post","link":"https:\/\/thunderguy.com\/semicolon\/2004\/04\/18\/profiling-a-java-program-easily\/","title":{"rendered":"Profiling a Java program easily"},"content":{"rendered":"<p>Profiling is an excellent way to find resource bottlenecks in a program. Java has built-in profiling tools that you can use to easily view a profile of a program&#8217;s runtime execution.<\/p>\n<p>To generate a profiling report for a Java program, add the <cite>hprof<\/cite> profiler to the program&#8217;s command line as follows.<\/p>\n<pre class=\"code\">\r\n<code>java -Xrunhprof:cpu=samples,depth=30,file=myprogram.hprof <em>other arguments...<\/em><\/code>\r\n<\/pre>\n<p>When the program terminates, it writes a profile report to myprogram.hprof. <a href=\"http:\/\/java.sun.com\/developer\/TechTips\/\">JDC Tech Tips<\/a> has an article on <a href=\"http:\/\/replay.waybackmachine.org\/20090327151858\/http:\/\/java.sun.com\/developer\/TechTips\/2000\/tt0124.html#tip2\">Using HPROF to Tune Performance<\/a> [Wayback Machine link, as the <a href=\"http:\/\/java.sun.com\/developer\/TechTips\/2000\/tt0124.html#tip2\">original link<\/a> is broken], which explains the format of the profile file. But you&#8217;ll probably want to skip straight ahead to using a GUI program to view the file, so&#8230;<\/p>\n<p>There is a free tool with the unfortunate name of PerfAnal that analyses profile files and presents them using a graphical interface. <a href=\"http:\/\/www.oracle.com\/technetwork\/articles\/javase\/perfanal-137231.html\">PerfAnal: A Performance Analysis Tool<\/a> on <del>Sun<\/del> Oracle&#8217;s Java site contains instructions and a link to download the tool. A few minutes&#8217; tinkering with this can yield valuable insights into the workings of a program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Profiling is an excellent way to find resource bottlenecks in a program. Java has built-in profiling tools that you can use to easily view a profile of a program&#8217;s runtime execution. To generate a profiling report for a Java program, add the hprof profiler to the program&#8217;s command line as follows. java -Xrunhprof:cpu=samples,depth=30,file=myprogram.hprof other arguments&#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4,7],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-general","tag-java","tag-testing"],"_links":{"self":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":3,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":724,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/17\/revisions\/724"}],"wp:attachment":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}