{"id":2785,"date":"2013-04-28T07:35:53","date_gmt":"2013-04-28T12:35:53","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2785"},"modified":"2013-04-28T07:35:53","modified_gmt":"2013-04-28T12:35:53","slug":"can-you-run-java-hprof-and-a-custom-agentlib-together","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/04\/28\/can-you-run-java-hprof-and-a-custom-agentlib-together\/","title":{"rendered":"Can you run java hprof and a custom agentlib together?"},"content":{"rendered":"<p>We run newrelic, which is an Advanced Performance Management (APM) software stack that will profile your java application from the browser all the way to the database.  It is really good software, affordable, and highly recommended.<\/p>\n<p>I also wanted to add the hprof JVM profiling utility to our runtime configuration, but didn&#8217;t know if this was even possible.  This is just a quick note that shows it is.  Using our previous <a href=\"http:\/\/appcrawler.com\/wordpress\/2013\/01\/02\/simple-byte-code-injection-example-with-javassist\" target=_blank>javassist byte code injection example<\/a>, we can see that we can also the load the hprof agent.<\/p>\n<pre lang=\"text\">\r\natllpecomodb01:oracle:atlecomp1:\/u01\/orahome>java -agentlib:hprof=cpu=samples -javaagent:myAgent.jar foo\r\nstarted method at Sun Apr 28 07:57:26 EDT 2013\r\nran doIt() method\r\nended method at Sun Apr 28 07:57:32 EDT 2013\r\nDumping CPU usage by sampling running threads ... done.\r\natllpecomodb01:oracle:atlecomp1:\/u01\/orahome>awk '{if ($0 ~ \"CPU SAMPLES BEGIN\") {l=1;print} else if (l == 1) {print}}' java.hprof.txt\r\nCPU SAMPLES BEGIN (total = 19) Sun Apr 28 07:57:32 2013\r\nrank   self  accum   count trace method\r\n   1 10.53% 10.53%       2 300145 java.lang.System.arraycopy\r\n   2 10.53% 21.05%       2 300167 java.lang.System.arraycopy\r\n   3  5.26% 26.32%       1 300001 java.lang.ClassLoader.findBootstrapClass\r\n   4  5.26% 31.58%       1 300023 java.io.UnixFileSystem.canonicalize0\r\n   5  5.26% 36.84%       1 300072 javassist.bytecode.ExceptionTable.<init>\r\n   6  5.26% 42.11%       1 300086 javassist.compiler.MemberResolver.<clinit>\r\n   7  5.26% 47.37%       1 300108 java.io.UnixFileSystem.getBooleanAttributes0\r\n   8  5.26% 52.63%       1 300131 sun.misc.URLClassPath$JarLoader.getClassPath\r\n   9  5.26% 57.89%       1 300139 java.io.BufferedInputStream.read\r\n  10  5.26% 63.16%       1 300144 javassist.bytecode.AttributeInfo.<init>\r\n  11  5.26% 68.42%       1 300161 javassist.bytecode.stackmap.TypeData.join\r\n  12  5.26% 73.68%       1 300170 javassist.bytecode.LongVector.addElement\r\n  13  5.26% 78.95%       1 300187 javassist.bytecode.Utf8Info.write\r\n  14  5.26% 84.21%       1 300196 java.lang.System.arraycopy\r\n  15  5.26% 89.47%       1 300203 sun.util.LocaleServiceProviderPool.<init>\r\n  16  5.26% 94.74%       1 300215 java.util.LinkedHashMap.createEntry\r\n  17  5.26% 100.00%       1 300216 java.util.ArrayList.<init>\r\nCPU SAMPLES END\r\natllpecomodb01:oracle:atlecomp1:\/u01\/orahome>\r\n<\/pre>\n<p>I realize this is overkill, as newrelic will profile this as well, but it has to be requested through the newrelic interface, and only for a period of time.  Loading the hprof agent will record the profile over the life of the JVM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We run newrelic, which is an Advanced Performance Management (APM) software stack that will profile your java application from the browser all the way to the database. It is really good software, affordable, and highly recommended. I also wanted to&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/04\/28\/can-you-run-java-hprof-and-a-custom-agentlib-together\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[24,25],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2785"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2785"}],"version-history":[{"count":11,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2785\/revisions"}],"predecessor-version":[{"id":2796,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2785\/revisions\/2796"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2785"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}