* Stats:
- Fix BufferedStatsLog so it works at all - Don't instantiate BufferedStatsLog unless stats.logFilters property is defined (restart now required to enable logging) This eliminates the StatLogWriter thread and a decent amount of memory. - Move two CLI classes out of the lib - Commment out places where getStatLog() isn't checked for null - Cleanups
This commit is contained in:
65
core/java/test/net/i2p/stat/SimpleStatDumper.java
Normal file
65
core/java/test/net/i2p/stat/SimpleStatDumper.java
Normal file
@ -0,0 +1,65 @@
|
||||
package net.i2p.stat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
public class SimpleStatDumper {
|
||||
private final static Log _log = new Log(SimpleStatDumper.class);
|
||||
|
||||
public static void dumpStats(I2PAppContext context, int logLevel) {
|
||||
if (!_log.shouldLog(logLevel)) return;
|
||||
|
||||
StringBuilder buf = new StringBuilder(4 * 1024);
|
||||
dumpFrequencies(context, buf);
|
||||
dumpRates(context, buf);
|
||||
_log.log(logLevel, buf.toString());
|
||||
}
|
||||
|
||||
private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) {
|
||||
Set frequencies = new TreeSet(ctx.statManager().getFrequencyNames());
|
||||
for (Iterator iter = frequencies.iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
FrequencyStat freq = ctx.statManager().getFrequency(name);
|
||||
buf.append('\n');
|
||||
buf.append(freq.getGroupName()).append('.').append(freq.getName()).append(": ")
|
||||
.append(freq.getDescription()).append('\n');
|
||||
long periods[] = freq.getPeriods();
|
||||
Arrays.sort(periods);
|
||||
for (int i = 0; i < periods.length; i++) {
|
||||
buf.append('\t').append(periods[i]).append(':');
|
||||
Frequency curFreq = freq.getFrequency(periods[i]);
|
||||
buf.append(" average interval: ").append(curFreq.getAverageInterval());
|
||||
buf.append(" min average interval: ").append(curFreq.getMinAverageInterval());
|
||||
buf.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void dumpRates(I2PAppContext ctx, StringBuilder buf) {
|
||||
Set rates = new TreeSet(ctx.statManager().getRateNames());
|
||||
for (Iterator iter = rates.iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
RateStat rate = ctx.statManager().getRate(name);
|
||||
buf.append('\n');
|
||||
buf.append(rate.getGroupName()).append('.').append(rate.getName()).append(": ")
|
||||
.append(rate.getDescription()).append('\n');
|
||||
long periods[] = rate.getPeriods();
|
||||
Arrays.sort(periods);
|
||||
for (int i = 0; i < periods.length; i++) {
|
||||
buf.append('\t').append(periods[i]).append(':');
|
||||
Rate curRate = rate.getRate(periods[i]);
|
||||
dumpRate(curRate, buf);
|
||||
buf.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void dumpRate(Rate curRate, StringBuilder buf) {
|
||||
buf.append(curRate.toString());
|
||||
}
|
||||
}
|
76
core/java/test/net/i2p/stat/StatLogSplitter.java
Normal file
76
core/java/test/net/i2p/stat/StatLogSplitter.java
Normal file
@ -0,0 +1,76 @@
|
||||
package net.i2p.stat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Simple CLI to splot the stat logs into per-stat files containing
|
||||
* #seconds since beginning and the value (ready for loading into your
|
||||
* favorite plotting tool)
|
||||
*/
|
||||
public class StatLogSplitter {
|
||||
private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss.SSS";
|
||||
private static SimpleDateFormat _fmt = new SimpleDateFormat(DATE_FORMAT);
|
||||
public static void main(String args[]) {
|
||||
if (args.length != 1) {
|
||||
System.err.println("Usage: StatLogSplitter filename");
|
||||
return;
|
||||
}
|
||||
splitLog(args[0]);
|
||||
}
|
||||
|
||||
private static void splitLog(String filename) {
|
||||
Map outputFiles = new HashMap(4);
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(filename));
|
||||
String line;
|
||||
long first = 0;
|
||||
while ( (line = in.readLine()) != null) {
|
||||
String date = line.substring(0, DATE_FORMAT.length()).trim();
|
||||
int endGroup = line.indexOf(' ', DATE_FORMAT.length()+1);
|
||||
int endStat = line.indexOf(' ', endGroup+1);
|
||||
int endValue = line.indexOf(' ', endStat+1);
|
||||
String group = line.substring(DATE_FORMAT.length()+1, endGroup).trim();
|
||||
String stat = line.substring(endGroup, endStat).trim();
|
||||
String value = line.substring(endStat, endValue).trim();
|
||||
String duration = line.substring(endValue).trim();
|
||||
//System.out.println(date + " " + group + " " + stat + " " + value + " " + duration);
|
||||
|
||||
try {
|
||||
Date when = _fmt.parse(date);
|
||||
if (first <= 0) first = when.getTime();
|
||||
long val = Long.parseLong(value);
|
||||
long time = Long.parseLong(duration);
|
||||
if (!outputFiles.containsKey(stat)) {
|
||||
outputFiles.put(stat, new FileWriter(stat + ".dat"));
|
||||
System.out.println("Including data to " + stat + ".dat");
|
||||
}
|
||||
FileWriter out = (FileWriter)outputFiles.get(stat);
|
||||
double s = (when.getTime()-first)/1000.0;
|
||||
//long s = when.getTime();
|
||||
out.write(s + " " + val + " [" + line + "]\n");
|
||||
out.flush();
|
||||
} catch (ParseException pe) {
|
||||
continue;
|
||||
} catch (NumberFormatException nfe){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
for (Iterator iter = outputFiles.values().iterator(); iter.hasNext(); ) {
|
||||
FileWriter out = (FileWriter)iter.next();
|
||||
try { out.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user