I have a Java Spring application that is running on my PC (I can attach debugger), I am looking for a way to profile a single method, preferably one that does have an UI to drilldown the child methods that consume the most time.
I tried JDK mission control and IntelliJ 's default profiler which I believe both are based off Java Flight Recorder. The issue is that most of the time it does not sample my method and my method spend lots of time waitting for (async?) I/O which cause the profiling result to be unusable
Why does the Java flight recorder take too few samples?
How to include IO-bound methods in Java Flight Recorder sampling?
What should I do in this case? Given that
I can already debug the method
I want to profile a single run on that single method only
I can get the drill down of child methods (Flame/Icicle chart) like what Google Chrome can do, including time when function is pending IO?
Preferably, without changing source code.
As supplemental detail, I already looked at some questions here that does not address the issue I mentioned: Some require to update to source code and some is dependent on JFR method sampling which I do not know how/if can profile a single specific method run and include the async I/O in the drill-down view
Any recommended Java profiling tutorial?
Profiling a Java Spring application
Related
I am developing a Java application that reads data from a Redis Database, I use Lettuce library to connect to Redis which in turn uses 'Netty' library to communicate with Redis
I suspect that the execution time of my application is greater than expected, so a conducted a profiling experiment using JProfiler, I was surprised that a FastThreadLocalRunnable takes a significant portion of the execution time with no justification as the tree shows no function calls taking time:
So, is it a bug in Lettuce library?, or is it a problem in the profiler measuring the execution time?
Any help is appreciated
Edit:
Thanks to Ingo's answer I can now expand the tree but it turns out that the java NIO is consuming my processor:
Any idea?
The call tree in JProfiler only shows classes that are included in the call tree filters that you define in the profiling settings:
By default, this excludes a lot of common frameworks and libraries so that you can get started without configuring anything. It is better if you delete these filters and add your own profiled packages here.
In addition to the profiled classes, JProfiler shows the thread entry point even it is not a profiled class, such as io.netty.util.concurrent.FastThreadLocalRunnable. Also, the first call into non-profiled classes is always shown at any level in the call tree.
In your case there are call chains to non-profiled classes below io.netty.util.concurrent.FastThreadLocalRunnable that never call a profiled class. They could belong to some framework or to some part of your code that is not included in the profiled classes. This time has to go somewhere, so it is attributed to the io.netty.util.concurrent.FastThreadLocalRunnable node.
An easy way to check is to disable filtering in the profiling settings, then you see all classes.
More information about call tree filters can be found at
https://www.ej-technologies.com/resources/jprofiler/help/doc/main/methodCallRecording.html
Please suggest an Application performance tool for Spring boot, I am using Jamon API right now but I need the logs at very granular level like graph and all instead of AVG, Min, MAX time only. I don't want to deploy it as additional service, I am looking something integrated within Micro service (Via Maven or Jar). Thanks in advance.
<Monitor> monitorName = <MonitorFactory>.start("Function Name");
//Some code here
monitorName.stop();
What I need is EveryDetails for this function name : Every Time Stamp it invoked, how much time this function took at that timestamp.
Sounds like you want to monitor just java methods. If that is the case then Automon should work.
JAMon has lots of modules that monitor web hits, jdbc, garbage collector, and more. Automon doesn't do all that, but can monitor any java code (even 3rd party libraries) with a simple configuration file. Automon doesn't actually do the monitoring, but instead calls any monitoring code that either you provide and out of the box it works with well-known monitoring libraries (i.e. JAMon, JavaSimon, Yammer Metrics, new relic, StatsD, Micrometer). It is also easy to implement your own callback code that would log (using sl4j, log4j etc). In fact, a similar example referenced below does just that with calls to System.out.println. You could even have it both log messages and call jamon.
automon - https://github.com/stevensouza/automon
automon System.out.println implementation - https://github.com/stevensouza/automon/blob/master/automon/src/main/java/org/automon/implementations/SysOut.java
Here is sample output using SysOut, however if you implement it you could add anything else you want.
SysOut.start(..): execution(String com.stevesouza.helloworld.HelloWorld.getLastName())
SysOut.stop(..) ms.: 0
Full disclosure. I wrote both JAMon and Automon.
I'm writing scripts with a Java api which compile to class files and are executed out of my perspective on a virtual machine (I don't have access to this virtual machine and can't debug my class files from within.) These scripts require observable data to execute and don't run properly unless they've been executed within this virtual machine. As a consequence of the way that these class files are executed, to my knowledge, I can't debug them with my IDE's built-in debugger.
I don't really have the coding vocabulary to even search for answers to that last statement, so please correct me if I'm wrong.
Anyways, the only way which I've determined will allow me to debug these scripts is the classic print-statement method. It's horrible. But it works. And it seems that the entire community for the api uses this method.
I had the idea that I could use reflection to grab information from my classes as they're executing, but this still doesn't give me access to the line-by-line debugging that I'm looking for.
What I'd like to do is monitor the execution of my script step-by-step (every calculation the VM does) and store information about those calculations (variable "foo" in class "bar" becomes 4 on line "soandso") as a sort of running cache which dumps to the system console whenever an error occurs.
Is this possible?
You can take a look at dynamic proxies.
Here is a very good explanation of it.
With a dynamic proxy you can output (log, send as mail, ...) the method that is beeing called and the parameters that are passed to the method.
It's not exactly what you are looking for but maybe it will help you.
I've been looking for replacements for my companies current batch processing system(java SE + crontab), since there is a lot of java code/shell script duplication, most jobs are ETL and do very similar steps and also i want to provide platform independence instead of relying on crontab, to be more specific with our job role, the current job creation steps are this:
Develop a java program that meets a business requirement.
Test it in a production like enviroment until it meets the business requirement needs.
Pass it to a production server with a shell script that provides file maintenance, java prgram execution and error handling routines(avoid 2 processes of the same name running, mail log to support and developers in case of program error, check output file existence after java program ends if it's relevant for the interface), and specify recurrence data(how often will this program run).
Much of the same logic is being designed and developed into a system that contains generic routines that these programs or "interfaces"(thats how they call it there) do independently(using copy-pasted code usually since most routines are similar), but i am still missing a very important part which i need help with, this concerns the scheduler implementation that i use, and i need it to meet one of these two needs:
-I want to guarantee that whenever i stop the scheduling server for a system update(due to new jobs being added, etc) or whatever other reason, those jobs that could not run due to the system being down(example is 3 jobs that could not run at 3:00 P.M. because the system was down), get to run when the server gets back up, even though their respective scheduling time is gone.
OR in case that the first thing is not possible then:
-I need a way to update the scheduler with new jobs and also update the jars that provide these jobs without restarting the scheduler(sort of like OSGi).
Either of these conditions would satisfy my requirements, and would end my search for the replacement, i've looked into Quartz, Oddjob(theres a scheduler in production with this scheduler, but it needs restarting each time you add new jobs/libraries, does not satisfy my needs) and OSGi using an application server, but i am looking for better suggestions, in case you also know better options, they are also much appreciated.
You might also want to take a look at http://jcrontab.sourceforge.net/
Jcrontab is a scheduler written in Java. The project objective is to provide a fully functional schedules for Java projects.
Alright, found just what i wanted, Quartz does the trick, but i have to develop my own UI Management, FORTUNATELY, there's this project http://code.google.com/p/myschedule/ which contains all that i need(add, remove, resuming jobs), and it is cheap to run the webapp, since you can use tomcat. Now i can focus on designing reusable jobs :), thank god for Quartz!
I have a small test class that I want to run on a particular jvm that's already up and running (basically it's an web application running on Tomcat) . The reason I want to do this is I want to execute a small test class (with the main method and all) within that jvm so that I get the same environment (loaded and initialized classes) for my test class.
Is it possible to indicate that ,say through a jvm parameter, that it should not initialize a new vm to execute my class but instead go and execute on the remote vm and show me the result here, on my console. So the local jvm acts as a kind of thin proxy ?
I am not aware in case there are some tools that should make this possible .Also heard somewhere that java 6 jvm comes with an option like this , is that true ?
Please help me.
Thanks,
After reading this question and the answers, I decided to roll my own little utility: remoteJunit
It is lightweight and dynamically loads classes from the client to the server JVM. It uses HTTP for communication.
You might want to take a look at btrace. It allows you to run code in an already started JVM provided you don't change the state of the variables inside that JVM. With this kind of tracing, you might be able solve your problem in a different way. Not by running extra code in form of a new class but by adding safe code to and existing class running inside a JVM.
For instance, you might System.out.println the name of the file when there is a call to File.exists.
You might find JMX useful. Register an MBean in the server process. Invoke it with visualvm (or jconsole). (tutorial) Never tried it myself, mind.
RMI would also do the magic.
http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html
Make your web application start an RMI registry and register your service
beans there.
Then in other JVM you can run a program that queries the RMI registry
started by your web application for the services you want to verify
and you are done.
I assume "small test class" is basically some debugging code you want to run to monitor your real application, which is deployed remotely on a Tomcat. If this is the case, you should connect your Eclipse debugger remotely to the Tomcat instance, so you can set a breakpoint at interesting locations and then use the Display view of Eclipse to run any arbitrary code you might need to perform advanced debugging code. As java supports Hot Code Replacement using the debug mechanism, you can also change existing code on the remote side with new code at runtime.