Skip to content

Commit

Permalink
Close Sigar before exiting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinhard Nägele committed Jul 31, 2013
1 parent 7d43c99 commit ced9a94
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/mgmtp/perfload/perfmon/PerfMon.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,16 @@ public static void main(final String[] args) {
CommandLine cmd = parseArgs(args);

if (cmd != null) {
final Sigar sigar = new Sigar();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
sigar.close();
}
});

if (cmd.hasOption('s')) {
shutdown();
shutdown(sigar);
return;
}

Expand All @@ -219,7 +227,7 @@ public static void main(final String[] args) {
// See https://github.com/mgm-tp/perfload/issues/3
Sigar.load();

SigarProxy sigarProxy = SigarProxyCache.newInstance(new Sigar());
SigarProxy sigarProxy = SigarProxyCache.newInstance(sigar);
List<BasePerfMonCommand> commands = createCommandsList(csv, java, tcp, normalizeTcp, netstat, normalizeIo);
final PerfMon perfMon = new PerfMon(sigarProxy, interval, csv, commands, outputHandler);

Expand All @@ -240,10 +248,9 @@ public void run() {
}
}

static void shutdown() {
static void shutdown(final Sigar sigar) {
LOG.info("Shutting down perfMon...");

Sigar sigar = new Sigar();
String[] type = new String[] { "State.Name.sw=java,Args.*.re=perf(m|M)on" };

try {
Expand Down

0 comments on commit ced9a94

Please sign in to comment.