Creating performance counters in Java

Does anyone know how I can create a new performance counter (perfmon tool) in Java ?

For example: a new performance counter to control the number / duration of user actions.

I created such performance counters in C # and it was pretty simple, however I could not find anything useful to create it in Java ...

+3
source share
3 answers

If you want to develop your performance counter regardless of the main code, you should look at aspect programming ( AspectJ , Javassist ).

, , .

+3

, , ,

class UserActionStats {
   int count;
   long durationMS;
   long start = 0;

   public void startAction() {
       start = System.currentTimeMillis();
   }
   public void endAction() {
       durationMS += System.currentTimeMillis() - start;
       count++;
   }
}

private static final Map<String, UserActionStats> map = 
        new HashMap<String, UserActionStats>();

public static UserActionStats forUser(String userName) {
    synchronized(map) {
        UserActionStats uas = map.get(userName);
        if (uas == null)
            map.put(userName, uas = new UserActionStats());
        return uas;
    }
}
+1

Java does not work right away with perfmon (but you should see DTrace on Solaris).

Please refer to this question for suggestions: Java application performance counters viewed in Perfmon

+1
source

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


All Articles