Skip to content
Snippets Groups Projects
Commit 8b3be3c1 authored by Florian Fittkau's avatar Florian Fittkau
Browse files

more improvements

parent f5d18b67
No related branches found
No related tags found
No related merge requests found
Showing
with 1009 additions and 211 deletions
......@@ -7,5 +7,6 @@
<attribute name="javadoc_location" value="jar:platform:/resource/worker/lib/disruptor-3.2.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/trove-3.0.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
File deleted
File added
This diff is collapsed.
The Trove library is licensed under the Lesser GNU Public License,
which is included with the distribution in a file called LICENSE.txt.
Other license arrangements are possible, for a fee: contact
ericdf@users.sourceforge.net for terms/pricing.
The PrimeFinder and HashFunctions classes in Trove are subject to the
following license restrictions:
Copyright (c) 1999 CERN - European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and
its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation. CERN makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without expressed or implied warranty.
package explorviz.hpc_monitoring.filter;
import com.lmax.disruptor.EventHandler;
import explorviz.hpc_monitoring.filter.reconstruction.TraceReconstructionFilter;
import explorviz.hpc_monitoring.reader.RecordEvent;
public class PipelineStartFilter implements EventHandler<RecordEvent> {
private static final TraceReconstructionFilter reconstructionFilter = new TraceReconstructionFilter(
5 * 1000 * 1000);
@Override
public void onEvent(final RecordEvent event, final long sequence,
final boolean endOfBatch) throws Exception {
reconstructionFilter.newEvent(event.getValue());
}
}
/***************************************************************************
* Copyright 2013 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package explorviz.hpc_monitoring.filter.counting;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
// import kieker.common.util.ImmutableEntry;
public final class CountingThroughputFilter {
private volatile long firstIntervalStart = -1;
private final TimeUnit timeunit;
private final long intervalSize;
private final AtomicLong currentCountForCurrentInterval = new AtomicLong(0);
private int currentCountForCurrentInterval = 0;
private volatile long firstTimestampInCurrentInterval = -1;
private volatile long lastTimestampInCurrentInterval = -1;
......@@ -35,58 +13,40 @@ public final class CountingThroughputFilter {
public CountingThroughputFilter(final String beforeOut) {
this.beforeOut = beforeOut;
timeunit = TimeUnit.NANOSECONDS;
intervalSize = timeunit.convert(1000000000, TimeUnit.NANOSECONDS);
intervalSize = 1 * 1000 * 1000;
}
private void processEvent(final Object event, final long currentTime) {
final long startOfTimestampsInterval = computeFirstTimestampInInterval(currentTime);
final long endOfTimestampsInterval = computeLastTimestampInInterval(currentTime);
synchronized (this) {
if (endOfTimestampsInterval > lastTimestampInCurrentInterval) {
if (firstTimestampInCurrentInterval >= 0) {
final long currentCount = currentCountForCurrentInterval
.get();
final long currentCount = currentCountForCurrentInterval;
System.out.println(beforeOut + ": " + currentCount);
}
firstTimestampInCurrentInterval = startOfTimestampsInterval;
lastTimestampInCurrentInterval = endOfTimestampsInterval;
currentCountForCurrentInterval.set(0);
currentCountForCurrentInterval = 0;
}
currentCountForCurrentInterval.incrementAndGet();
}
currentCountForCurrentInterval++;
}
public final void inputObjects(final Object object) {
processEvent(object, currentTime());
}
private long currentTime() {
return timeunit.convert(System.currentTimeMillis(),
TimeUnit.MILLISECONDS);
processEvent(object, System.currentTimeMillis() * 1000);
}
private long computeFirstTimestampInInterval(final long timestamp) {
final long referenceTimePoint;
if (firstIntervalStart == -1) {
firstIntervalStart = timestamp;
}
referenceTimePoint = 0;
return referenceTimePoint
+ (((timestamp - referenceTimePoint) / intervalSize) * intervalSize);
return ((timestamp / intervalSize) * intervalSize);
}
private long computeLastTimestampInInterval(final long timestamp) {
final long referenceTimePoint;
referenceTimePoint = 0;
return referenceTimePoint
+ (((((timestamp - referenceTimePoint) / intervalSize) + 1) * intervalSize) - 1);
return ((((timestamp / intervalSize) + 1) * intervalSize) - 1);
}
}
......@@ -18,23 +18,14 @@ public class TraceBuffer {
private boolean damaged;
private int openEvents;
private int maxOrderIndex = -1;
private long maxLoggingTimestamp = -1;
public TraceBuffer() {
// default empty constructor
}
public final long getMaxLoggingTimestamp() {
synchronized (this) {
return maxLoggingTimestamp;
}
}
public void insertEvent(final AbstractOperationEvent event) {
synchronized (this) {
public final void insertEvent(final AbstractOperationEvent event) {
setMaxLoggingTimestamp(event);
final int orderIndex = setMaxOrderIndex(event);
......@@ -52,13 +43,11 @@ public class TraceBuffer {
}
if (!events.add(event)) {
System.out.println("Duplicate entry for orderIndex "
+ orderIndex + " with traceId "
+ traceMetadata.getTraceId());
System.out.println("Duplicate entry for orderIndex " + orderIndex
+ " with traceId " + traceMetadata.getTraceId());
damaged = true;
}
}
}
private final void setMaxLoggingTimestamp(final AbstractOperationEvent event) {
final long loggingTimestamp = event.getLoggingTimestamp();
......@@ -76,7 +65,6 @@ public class TraceBuffer {
}
public void setTrace(final TraceMetadata trace) {
synchronized (this) {
if (traceMetadata != null) {
System.out.println("Duplicate Trace entry for traceId "
+ trace.getTraceId());
......@@ -85,23 +73,17 @@ public class TraceBuffer {
}
traceMetadata = trace;
}
}
public final boolean isFinished() {
synchronized (this) {
return !isInvalid() && closeable;
}
}
public final boolean isInvalid() {
synchronized (this) {
return (((maxOrderIndex + 1) != events.size()) || events.isEmpty()
|| (openEvents != 0) || (traceMetadata == null) || damaged);
}
}
public final Trace toTrace() { // TODO still very slow!
synchronized (this) {
public final Trace toTrace() { // TODO still slow?
final AbstractOperationEvent[] arrayEvents = new AbstractOperationEvent[events
.size()];
final Iterator<AbstractOperationEvent> iterator = events.iterator();
......@@ -113,7 +95,6 @@ public class TraceBuffer {
return new Trace(traceMetadata, arrayEvents);
}
}
/**
* @author Jan Waller
......
......
package explorviz.hpc_monitoring.filter.reconstruction;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import explorviz.hpc_monitoring.filter.counting.CountingThroughputFilter;
import explorviz.hpc_monitoring.record.IRecord;
import explorviz.hpc_monitoring.record.TraceMetadata;
import explorviz.hpc_monitoring.filter.reduction.TracePatternSummarizationFilter;
import explorviz.hpc_monitoring.reader.RecordEvent;
import explorviz.hpc_monitoring.record.*;
import explorviz.hpc_monitoring.record.events.AbstractOperationEvent;
import gnu.trove.iterator.TLongObjectIterator;
import gnu.trove.map.hash.TLongObjectHashMap;
public final class TraceReconstructionFilter {
public final class TraceReconstructionFilter implements
EventHandler<RecordEvent> {
private static final CountingThroughputFilter counter = new CountingThroughputFilter(
"Reconstructed traces per second");
private final long maxTraceTimeout;
private final ConcurrentMap<Long, TraceBuffer> traceId2trace = new ConcurrentHashMap<Long, TraceBuffer>(
128,
0.75f,
2);
private final TLongObjectHashMap<TraceBuffer> traceId2trace = new TLongObjectHashMap<TraceBuffer>(
1024);
private final RingBuffer<RecordEvent> ringBuffer;
@SuppressWarnings("unchecked")
public TraceReconstructionFilter(final long maxTraceTimeout) {
this.maxTraceTimeout = maxTraceTimeout;
final ExecutorService exec = Executors.newCachedThreadPool();
final Disruptor<RecordEvent> disruptor = new Disruptor<RecordEvent>(
RecordEvent.EVENT_FACTORY, 16384, exec);
final EventHandler<RecordEvent>[] eventHandlers = new EventHandler[1];
eventHandlers[0] = new TracePatternSummarizationFilter(5 * 1000 * 1000);
disruptor.handleEventsWith(eventHandlers);
ringBuffer = disruptor.start();
}
public void periodicTimeSignal(final long timestamp) {
......@@ -30,72 +44,73 @@ public final class TraceReconstructionFilter {
private void checkForTimeouts(final long timestamp) {
final long traceTimeout = timestamp - maxTraceTimeout;
for (final Iterator<Entry<Long, TraceBuffer>> iterator = traceId2trace
.entrySet().iterator(); iterator.hasNext();) {
final TraceBuffer traceBuffer = iterator.next().getValue();
for (final TLongObjectIterator<TraceBuffer> iterator = traceId2trace
.iterator(); iterator.hasNext(); iterator.advance()) {
final TraceBuffer traceBuffer = iterator.value();
if (traceBuffer.getMaxLoggingTimestamp() <= traceTimeout) {
sentOutTrace(traceBuffer);
sendOutInvalidTrace(traceBuffer.toTrace());
iterator.remove();
}
}
}
public void newEvent(final IRecord record) {
private void sendOutValidTrace(final Trace trace) {
counter.inputObjects(trace);
// putInRingBuffer(trace);
}
private void sendOutInvalidTrace(final Trace trace) {
counter.inputObjects(trace);
// putInRingBuffer(trace);
}
private void putInRingBuffer(final IRecord record) {
final long hiseq = ringBuffer.next();
final RecordEvent valueEvent = ringBuffer.get(hiseq);
valueEvent.setValue(record);
ringBuffer.publish(hiseq);
}
@Override
public void onEvent(final RecordEvent event, final long sequence,
final boolean endOfBatch) throws Exception {
final IRecord record = event.getValue();
if (record instanceof TraceMetadata) {
final TraceMetadata traceMetadata = ((TraceMetadata) record);
final Long traceId = traceMetadata.getTraceId();
final long traceId = traceMetadata.getTraceId();
final TraceBuffer traceBuffer = getBufferForTraceId(traceId);
traceBuffer.setTrace(traceMetadata);
}
else if (record instanceof AbstractOperationEvent) {
final AbstractOperationEvent abstractOperationEvent = ((AbstractOperationEvent) record);
final Long traceId = abstractOperationEvent.getTraceId();
final long traceId = abstractOperationEvent.getTraceId();
final TraceBuffer traceBuffer = getBufferForTraceId(traceId);
traceBuffer.insertEvent(abstractOperationEvent);
if (traceBuffer.isFinished()) {
synchronized (this) {
traceId2trace.remove(traceId);
}
sentOutTrace(traceBuffer);
sendOutValidTrace(traceBuffer.toTrace());
}
}
}
private TraceBuffer getBufferForTraceId(final Long traceId) {
private TraceBuffer getBufferForTraceId(final long traceId) {
TraceBuffer traceBuffer = traceId2trace.get(traceId);
if (traceBuffer == null) { // first record for this id!
synchronized (this) {
traceBuffer = traceId2trace.get(traceId);
if (traceBuffer == null) { // NOCS (DCL)
if (traceBuffer == null) {
traceBuffer = new TraceBuffer();
traceId2trace.put(traceId, traceBuffer);
}
}
}
return traceBuffer;
}
public void terminate() {
synchronized (this) {
for (final Entry<Long, TraceBuffer> entry : traceId2trace
.entrySet()) {
sentOutTrace(entry.getValue());
}
traceId2trace.clear();
for (final Object entry : traceId2trace.values()) {
if (entry instanceof TraceBuffer) {
sendOutInvalidTrace(((TraceBuffer) entry).toTrace());
}
}
private void sentOutTrace(final TraceBuffer traceBuffer) {
if (traceBuffer.isInvalid()) {
// TODO invalid out
counter.inputObjects(traceBuffer.toTrace());
}
else {
// TODO valid out
counter.inputObjects(traceBuffer.toTrace());
}
traceId2trace.clear();
}
}
\ No newline at end of file
package explorviz.hpc_monitoring.filter.reduction;
import explorviz.hpc_monitoring.record.Trace;
import explorviz.hpc_monitoring.record.events.AbstractOperationEvent;
public class TraceAggregationBuffer {
private Trace accumulator;
private final long bufferCreatedTimestamp;
public TraceAggregationBuffer(final long bufferCreatedTimestamp) {
this.bufferCreatedTimestamp = bufferCreatedTimestamp;
}
public long getBufferCreatedTimestamp() {
return bufferCreatedTimestamp;
}
public Trace getAggregatedTrace() {
return accumulator;
}
public void insertTrace(final Trace trace) {
aggregate(trace);
}
private void aggregate(final Trace trace) {
if (accumulator == null) {
accumulator = trace;
}
else {
final AbstractOperationEvent[] aggregatedRecords = accumulator
.getTraceEvents();
final AbstractOperationEvent[] records = trace.getTraceEvents();
for (int i = 0; i < aggregatedRecords.length; i++) {
aggregatedRecords[i].getRuntime()
.merge(records[i].getRuntime());
}
accumulator.getRuntime().merge(trace.getRuntime());
}
}
}
\ No newline at end of file
package explorviz.hpc_monitoring.filter.reduction;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.lmax.disruptor.EventHandler;
import explorviz.hpc_monitoring.reader.RecordEvent;
import explorviz.hpc_monitoring.record.IRecord;
import explorviz.hpc_monitoring.record.Trace;
import explorviz.hpc_monitoring.record.events.AbstractOperationEvent;
public class TraceEventRecordAggregationFilter {
private final TimeUnit timeunit;
public class TracePatternSummarizationFilter implements
EventHandler<RecordEvent> {
private final long maxCollectionDuration;
private final Map<Trace, TraceAggregationBuffer> trace2buffer;
public TraceEventRecordAggregationFilter() {
timeunit = TimeUnit.NANOSECONDS;
maxCollectionDuration = timeunit.convert(50000000L, timeunit);
trace2buffer = new TreeMap<Trace, TraceAggregationBuffer>(
private final Map<Trace, TraceAggregationBuffer> trace2buffer = new TreeMap<Trace, TraceAggregationBuffer>(
new TraceComperator());
}
public void newEvent(final Trace event) {
synchronized (this) {
insertIntoBuffer(event);
}
public TracePatternSummarizationFilter(final long maxCollectionDuration) {
this.maxCollectionDuration = maxCollectionDuration;
}
private void insertIntoBuffer(final Trace trace) {
TraceAggregationBuffer traceBuffer;
traceBuffer = trace2buffer.get(trace);
if (traceBuffer == null) { // first record for this id!
synchronized (this) {
traceBuffer = trace2buffer.get(trace);
if (traceBuffer == null) { // NOCS (DCL)
traceBuffer = new TraceAggregationBuffer(System.nanoTime());
trace2buffer.put(trace, traceBuffer);
}
}
}
synchronized (this) {
traceBuffer.insertTrace(trace);
}
}
public void newEvent(final Long timestamp) {
synchronized (this) {
public void periodicTimeSignal(final Long timestamp) {
processTimeoutQueue(timestamp);
}
}
public void terminate(final boolean error) {
synchronized (this) {
// for (final TraceAggregationBuffer traceBuffer : trace2buffer
// .values()) {
// // super.deliver(OUTPUT_PORT_NAME_TRACES,
// // traceBuffer.getAggregatedTrace());
// }
trace2buffer.clear();
}
}
private void processTimeoutQueue(final long timestamp) {
final long bufferTimeout = timestamp - maxCollectionDuration;
final List<Trace> toRemove = new ArrayList<Trace>();
for (final TraceAggregationBuffer traceBuffer : trace2buffer.values()) {
if (traceBuffer.getBufferCreatedTimestamp() <= bufferTimeout) {
final Trace aggregatedTrace = traceBuffer
.getAggregatedTrace();
// super.deliver(OUTPUT_PORT_NAME_TRACES, aggregatedTrace);
final Trace aggregatedTrace = traceBuffer.getAggregatedTrace();
sendOutTrace(aggregatedTrace);
toRemove.add(aggregatedTrace);
}
}
......@@ -78,56 +36,42 @@ public class TraceEventRecordAggregationFilter {
}
}
private static final class TraceAggregationBuffer {
private Trace accumulator;
private final long bufferCreatedTimestamp;
public TraceAggregationBuffer(final long bufferCreatedTimestamp) {
this.bufferCreatedTimestamp = bufferCreatedTimestamp;
private void sendOutTrace(final Trace aggregatedTrace) {
// TODO
}
public long getBufferCreatedTimestamp() {
return bufferCreatedTimestamp;
@Override
public void onEvent(final RecordEvent event, final long sequence,
final boolean endOfBatch) throws Exception {
final IRecord value = event.getValue();
if (value instanceof Trace) {
insertIntoBuffer((Trace) value);
}
public Trace getAggregatedTrace() {
return accumulator;
}
public void insertTrace(final Trace trace) {
aggregate(trace);
private void insertIntoBuffer(final Trace trace) {
TraceAggregationBuffer traceAggregationBuffer = trace2buffer.get(trace);
if (traceAggregationBuffer == null) {
traceAggregationBuffer = new TraceAggregationBuffer(
System.nanoTime());
trace2buffer.put(trace, traceAggregationBuffer);
}
private void aggregate(final Trace trace) {
if (accumulator == null) {
accumulator = trace;
}
else {
final AbstractOperationEvent[] aggregatedRecords = accumulator
.getTraceOperations();
final AbstractOperationEvent[] records = trace
.getTraceOperations();
for (int i = 0; i < aggregatedRecords.length; i++) {
aggregatedRecords[i].getRuntime().merge(
records[i].getRuntime());
traceAggregationBuffer.insertTrace(trace);
}
accumulator.getRuntime().merge(trace.getRuntime());
}
public void terminate(final boolean error) {
for (final TraceAggregationBuffer traceBuffer : trace2buffer.values()) {
sendOutTrace(traceBuffer.getAggregatedTrace());
}
trace2buffer.clear();
}
private static final class TraceComperator implements
Comparator<Trace> {
public TraceComperator() {}
private static final class TraceComperator implements Comparator<Trace> {
@Override
public int compare(final Trace t1,
final Trace t2) {
final AbstractOperationEvent[] recordsT1 = t1.getTraceOperations();
final AbstractOperationEvent[] recordsT2 = t2.getTraceOperations();
public int compare(final Trace t1, final Trace t2) {
final AbstractOperationEvent[] recordsT1 = t1.getTraceEvents();
final AbstractOperationEvent[] recordsT2 = t2.getTraceEvents();
if ((recordsT1.length - recordsT2.length) != 0) {
return recordsT1.length - recordsT2.length;
......@@ -143,5 +87,4 @@ public class TraceEventRecordAggregationFilter {
return 0;
}
}
}
package explorviz.hpc_monitoring.reader;
import java.util.concurrent.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import explorviz.hpc_monitoring.byteaccess.UnsafeBits;
import explorviz.hpc_monitoring.filter.PipelineStartFilter;
import explorviz.hpc_monitoring.filter.counting.CountingThroughputFilter;
import explorviz.hpc_monitoring.filter.reconstruction.TraceReconstructionFilter;
import explorviz.hpc_monitoring.record.IRecord;
import explorviz.hpc_monitoring.record.TraceMetadata;
import explorviz.hpc_monitoring.record.events.normal.*;
import gnu.trove.map.hash.TIntObjectHashMap;
public class MessageDistributer implements EventHandler<ByteArrayEvent> {
private final ConcurrentMap<Integer, String> stringRegistry = new ConcurrentHashMap<Integer, String>(
16,
0.75f,
2);
private static final CountingThroughputFilter counter = new CountingThroughputFilter(
"Records per second");
private final TIntObjectHashMap<String> stringRegistry = new TIntObjectHashMap<String>(
64);
private byte[] unreadBytes = null;
......@@ -28,7 +32,7 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
RecordEvent.EVENT_FACTORY, 32768, exec);
final EventHandler<RecordEvent>[] eventHandlers = new EventHandler[1];
eventHandlers[0] = new PipelineStartFilter();
eventHandlers[0] = new TraceReconstructionFilter(5 * 1000 * 1000);
disruptor.handleEventsWith(eventHandlers);
ringBuffer = disruptor.start();
}
......@@ -77,13 +81,13 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
final long traceId = UnsafeBits.getLong(b, offset);
offset += 8;
final Integer hostnameId = UnsafeBits.getInt(b, offset);
final int hostnameId = UnsafeBits.getInt(b, offset);
offset += 4;
final long parentTraceId = UnsafeBits.getLong(b, offset);
offset += 8;
final int parentOrderId = UnsafeBits.getInt(b, offset);
offset += 4;
final Integer applicationId = UnsafeBits.getInt(b, offset);
final int applicationId = UnsafeBits.getInt(b, offset);
offset += 4;
record = new TraceMetadata(traceId,
......@@ -102,7 +106,7 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
offset += 8;
final int orderIndex = UnsafeBits.getInt(b, offset);
offset += 4;
final Integer operationId = UnsafeBits.getInt(b, offset);
final int operationId = UnsafeBits.getInt(b, offset);
offset += 4;
record = new BeforeOperationEvent(timestamp, traceId,
......@@ -120,9 +124,9 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
offset += 8;
final int orderIndex = UnsafeBits.getInt(b, offset);
offset += 4;
final Integer operationId = UnsafeBits.getInt(b, offset);
final int operationId = UnsafeBits.getInt(b, offset);
offset += 4;
final Integer causeId = UnsafeBits.getInt(b, offset);
final int causeId = UnsafeBits.getInt(b, offset);
offset += 4;
record = new AfterFailedOperationEvent(timestamp, traceId,
......@@ -141,7 +145,7 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
offset += 8;
final int orderIndex = UnsafeBits.getInt(b, offset);
offset += 4;
final Integer operationId = UnsafeBits.getInt(b, offset);
final int operationId = UnsafeBits.getInt(b, offset);
offset += 4;
record = new AfterOperationEvent(timestamp, traceId,
......@@ -153,7 +157,7 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
return createUnreadBytesArray(b, readSize, offset, true);
}
final Integer mapId = UnsafeBits.getInt(b, offset);
final int mapId = UnsafeBits.getInt(b, offset);
offset += 4;
final int stringLength = UnsafeBits.getInt(b, offset);
offset += 4;
......@@ -197,13 +201,14 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
}
private void putInRingBuffer(final IRecord record) {
counter.inputObjects(record);
final long hiseq = ringBuffer.next();
final RecordEvent valueEvent = ringBuffer.get(hiseq);
valueEvent.setValue(record);
ringBuffer.publish(hiseq);
}
public void addToRegistry(final Integer key, final String value) {
public void addToRegistry(final int key, final String value) {
stringRegistry.put(key, value);
synchronized (this) {
......@@ -211,7 +216,7 @@ public class MessageDistributer implements EventHandler<ByteArrayEvent> {
}
}
private String getStringFromRegistry(final Integer id) {
private String getStringFromRegistry(final int id) {
String result = stringRegistry.get(id);
while (result == null) {
try {
......
......
......@@ -12,7 +12,6 @@ import com.lmax.disruptor.dsl.Disruptor;
public final class TCPReader {
private static final int MESSAGE_BUFFER_SIZE = 65536;
private final byte[] messages = new byte[MESSAGE_BUFFER_SIZE];
private final int listeningPort;
......@@ -44,9 +43,11 @@ public final class TCPReader {
final BufferedInputStream bufferedInputStream = new BufferedInputStream(
socket.getInputStream(), MESSAGE_BUFFER_SIZE);
int readBytes = 0;
byte[] messages = new byte[MESSAGE_BUFFER_SIZE];
while ((readBytes = bufferedInputStream.read(messages, 0,
MESSAGE_BUFFER_SIZE)) != -1) {
putInRingBuffer(messages, readBytes);
messages = new byte[MESSAGE_BUFFER_SIZE];
}
socket.close();
......@@ -69,12 +70,10 @@ public final class TCPReader {
serversocket = new ServerSocket(listeningPort);
}
private void putInRingBuffer(final byte[] message, final int readBytes) {
private void putInRingBuffer(final byte[] messages, final int readBytes) {
final long hiseq = ringBuffer.next();
final ByteArrayEvent valueEvent = ringBuffer.get(hiseq);
final byte[] toSaveCopy = new byte[readBytes];
System.arraycopy(message, 0, toSaveCopy, 0, readBytes);
valueEvent.setValue(toSaveCopy);
valueEvent.setValue(messages);
valueEvent.setLength(readBytes);
ringBuffer.publish(hiseq);
}
......
......
......@@ -11,7 +11,6 @@ public final class TimeReader {
private ScheduledFuture<?> result;
public TimeReader(final long periodInNanoSec) {
// period = 10 * 1000 * 1000;
period = periodInNanoSec;
executorService = new ScheduledThreadPoolExecutor(1);
}
......
......
......@@ -33,8 +33,7 @@ public final class RuntimeStatisticInformation implements Serializable {
private long count = 0;
private long min = Long.MAX_VALUE;
private long max = Long.MIN_VALUE;
// Using doubles to handle numbers above Integer.MAX_VALUE. Overflows are
// much worse than losing precision here.
private double sum;
private double squareSum;
......
......
......@@ -22,7 +22,7 @@ public final class Trace implements Serializable, IRecord {
return traceMetadata;
}
public AbstractOperationEvent[] getTraceOperations() {
public AbstractOperationEvent[] getTraceEvents() {
return traceEvents;
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment