Measurement of the "busyness" of the event sending the stream

I would like to measure the busyness of my Dispatching Thread event. One possible idea is to create a background thread that does something like:

while(true) { final long[] end = new long[1]; // Array to get stuff out from Runnable. long start = System.nanoTime(); EventQueue.invokeAndWait(new Runnable() { public void run() { end[0] = System.nanoTime(); } }); long queueTimeNs = end[0] - start; // Report the queue time somewhere. Thread.sleep(100); // Poll the EDT < 10 times/s. } 

The idea is to measure how long it takes to send an event to the EDT so that it is dispatched. This would give an approximate idea of ​​the responsiveness of the user interface.

It makes sense? Is there an even more standard way to do something like this?

0
source share
2 answers

I use a great tool for this: SwingExplorer. It allows you to inspect Swing components, see how they are drawn, detect EDT violations, and detect EDT hangs. Basically, you enter a duration value in milliseconds, and then play with your application. When the EDT freezes longer than this duration, the freeze is registered in the user interface of the tool.

The official site is https://swingexplorer.dev.java.net , but it seems that at the moment I'm writing this answer. You can find the plugin for Eclipse and NetBeans, and you can also find swingexplorer in the maven repository if you use maven (sorry, I can not find the link at the moment)

At least the repository is still available: cvs -d :pserver:guest: guest@cvs.dev.java.net :/shared/data/ccvs/repository co swingexplorer

Edit

I looked at the source code of the Swing explorer, and it seems like they wrote a custom EventQueue to test the behavior of the EDT. The code seems to be linked to another project, SwingHelper .

Edit 2

The project site will soon return to http://java.net/projects/swingexplorer

+1
source

I think your rating is close to the ideal of measuring responsiveness, because it takes into account both the actual amount of work done in the EDT (perhaps too much in a poorly designed application) and the ability of the machine to do this job.

By the way, I once tried to replace / redirect EDT, but after many hours I found that this is impossible, even if it is reckless to use reflection to access the private fields of the implementation classes. In the end, everything depended on the local object, which they were waiting for, which was impossible to keep.

I suspect that for the same reason it is not possible to intercept EDT to get information, such as the number of events processed (this was my first idea for a metric that you could use).

+1
source

Source: https://habr.com/ru/post/1210579/


All Articles