annotate src/org/dancres/blitz/stats/ThreadStat.java @ 34:6f68e94c1fb8 default tip

Add CondensedStats monitoring utility, equivalent to vmstat
author Dominic Cleal <dominic-cleal@cdo2.com>
date Thu, 05 Aug 2010 11:07:25 +0100
parents 3dc0c5604566
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
1 package org.dancres.blitz.stats;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
2
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
3 public class ThreadStat implements Stat, StatGenerator {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
4 private long theId = StatGenerator.UNSET_ID;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
5 private int theThreadCount = 0;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
6
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
7 ThreadStat() {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
8 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
9
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
10 ThreadStat(long anId, int aThreadCount) {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
11 theId = anId;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
12 theThreadCount = aThreadCount;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
13 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
14
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
15 public void setId(long anId) {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
16 theId = anId;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
17 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
18
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
19 public long getId() {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
20 return theId;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
21 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
22
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
23 public synchronized Stat generate() {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
24 ThreadGroup myGroup = Thread.currentThread().getThreadGroup();
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
25
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
26 int myActiveCount = myGroup.activeCount();
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
27
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
28 while ((!myGroup.getName().equals("main")) &&
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
29 (myGroup = myGroup.getParent()) != null) {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
30 myActiveCount += myGroup.activeCount();
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
31 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
32
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
33 return new ThreadStat(theId, myActiveCount);
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
34 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
35
34
6f68e94c1fb8 Add CondensedStats monitoring utility, equivalent to vmstat
Dominic Cleal <dominic-cleal@cdo2.com>
parents: 0
diff changeset
36 public int getThreadCount() {
6f68e94c1fb8 Add CondensedStats monitoring utility, equivalent to vmstat
Dominic Cleal <dominic-cleal@cdo2.com>
parents: 0
diff changeset
37 return theThreadCount;
6f68e94c1fb8 Add CondensedStats monitoring utility, equivalent to vmstat
Dominic Cleal <dominic-cleal@cdo2.com>
parents: 0
diff changeset
38 }
6f68e94c1fb8 Add CondensedStats monitoring utility, equivalent to vmstat
Dominic Cleal <dominic-cleal@cdo2.com>
parents: 0
diff changeset
39
0
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
40 public String toString() {
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
41 return "Thread count: " + theThreadCount;
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
42 }
3dc0c5604566 Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff changeset
43 }