use of org.spf4j.perf.MeasurementRecorder in project spf4j by zolyfarkas.
the class CpuUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder cpuUsage = RecorderFactory.createDirectRecorder("cpu-time", "ns", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private long lastValue = 0;
@Override
public void doRun() {
long currTime = getProcessCpuTimeNanos();
cpuUsage.record(currTime - lastValue);
lastValue = currTime;
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("Cpu time Sampling already started " + samplingFuture);
}
}
use of org.spf4j.perf.MeasurementRecorder in project spf4j by zolyfarkas.
the class GCUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder gcUsage = RecorderFactory.createDirectRecorder("gc-time", "ms", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private final TObjectLongMap lastValues = new TObjectLongHashMap();
@Override
public void doRun() {
synchronized (lastValues) {
gcUsage.record(getGCTimeDiff(MBEANS, lastValues));
}
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("GC usage sampling already started " + samplingFuture);
}
}
use of org.spf4j.perf.MeasurementRecorder in project spf4j by zolyfarkas.
the class ThreadUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime, @JmxExport("withStackTraces") final boolean withStackTraces) {
if (samplingFuture == null) {
final MeasurementRecorder cpuUsage = RecorderFactory.createDirectRecorder("peak-thread-count", "count", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private int maxThreadsNr = 0;
@Override
public void doRun() {
final int peakThreadCount = TH_BEAN.getPeakThreadCount();
cpuUsage.record(peakThreadCount);
if (peakThreadCount > maxThreadsNr) {
Thread[] ths = Threads.getThreads();
if (ths.length > PEAK_THREAD_NAMES.size()) {
if (withStackTraces) {
StackTraceElement[][] stackTraces = Threads.getStackTraces(ths);
PEAK_THREAD_TRACES.clear();
PEAK_THREAD_TRACES.addAll(Arrays.asList(stackTraces));
}
PEAK_THREAD_NAMES.clear();
int i = 0;
for (Thread th : ths) {
PEAK_THREAD_NAMES.add(th.getName());
if (th.isDaemon()) {
PEAK_THREAD_DAEMON.set(i);
} else {
PEAK_THREAD_DAEMON.clear(i);
}
i++;
}
}
maxThreadsNr = peakThreadCount;
}
TH_BEAN.resetPeakThreadCount();
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("Thread sampling already started " + samplingFuture);
}
}
use of org.spf4j.perf.MeasurementRecorder in project spf4j by zolyfarkas.
the class DirectRecorderSourceTest method testDirectRecorder.
@Test
public void testDirectRecorder() throws IOException {
MeasurementRecorderSource recorderSource = RecorderFactory.createDirectRecorderSource("test", "description");
MeasurementRecorder recorder = recorderSource.getRecorder("A");
long time = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
recorder.recordAt(time + (long) i * 1000, i);
}
MeasurementRecorder recorder2 = recorderSource.getRecorder("B");
for (int i = 0; i < 100; i++) {
recorder2.recordAt(time + (long) i * 1000, i);
}
recorderSource.close();
org.spf4j.perf.RecorderFactoryTest.assertData("test,A", 4950);
org.spf4j.perf.RecorderFactoryTest.assertData("test,B", 4950);
}
use of org.spf4j.perf.MeasurementRecorder in project spf4j by zolyfarkas.
the class GraphiteUdpStoreTest method testStore.
@Test
@SuppressFBWarnings("MDM_THREAD_YIELD")
public void testStore() throws InterruptedException, IOException {
MeasurementRecorder recorder = RecorderFactory.createScalableQuantizedRecorder("test measurement", "ms", 1000, 10, 0, 6, 10);
for (int i = 0; i < 100; i++) {
recorder.record(i);
Thread.sleep(100);
}
recorder.close();
RecorderFactory.MEASUREMENT_STORE.flush();
// RecorderFactory.MEASUREMENT_STORE.close();
List<String> lines = Files.readAllLines(TSDB_TXT.toPath(), StandardCharsets.UTF_8);
LOG.debug("measurements = {}", lines);
Assert.assertThat(lines, Matchers.hasItem(Matchers.allOf(Matchers.containsString("Q6_7"), Matchers.containsString("test measurement"))));
String line = QUEUE.poll(5, TimeUnit.SECONDS);
Assert.assertThat(line, Matchers.containsString("test-measurement"));
}
Aggregations