4

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

For example: a new performance counter for monitoring the number / duration of user actions.

I created such performance counters in C# and it was quite easy, however I couldn’t find anything helpful for creating it in Java…

1

3 Answers 3

3

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

You'll can plug your performance counter on the method(s) you want without modifying the main code.

Sign up to request clarification or add additional context in comments.

Comments

2

Not sure what you are expecting this tool to do but I would create some data structures to record these times and counts like

class UserActionStats { int count; long durationMS; long start = 0; public void startAction() { start = System.currentTimeMillis(); } public void endAction() { durationMS += System.currentTimeMillis() - start; count++; } } 

A collection for these could look like

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; } } 

2 Comments

Shouldn't your durationMS actually be incrementing: start - System.currentTimeMillis();
Thanks, but I don’t think it exactly what I meant. I want to view my performance counter in perfmon tool. A simple measurement of duration or number will not be updated there and will not be stored in the perfmon logs
1

Java does not immediately work with perfmon (but you should see DTrace under Solaris).

Please see this question for suggestions: Java app performance counters viewed in Perfmon

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.