use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class Converter method loadLabeledDump.
/**
* Load samples forrm file containing multiple labeled stack samples.
* @param file the ssdump3 file.
* @return
* @throws IOException
*/
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
@Nullable
public static SampleNode loadLabeledDump(final File file, final String label) throws IOException {
try (InputStream bis = newInputStream(file)) {
final SpecificDatumReader<StackSampleElement> reader = new SpecificDatumReader<>(StackSampleElement.SCHEMA$);
final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(bis, null);
long nrItems = decoder.readMapStart();
StackSampleElement asmp = new StackSampleElement();
while (nrItems > 0) {
for (int i = 0; i < nrItems; i++) {
String key = decoder.readString();
if (label.equals(key)) {
return loadSamples(decoder, asmp, reader).get(0);
} else {
skipDump(decoder, reader, asmp);
}
}
nrItems = decoder.mapNext();
}
return null;
}
}
use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class Converter method loadLabeledDumps.
/**
* Load samples forrm file containing multiple labeled stack samples.
* @param file the ssdump3 file.
* @return
* @throws IOException
*/
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public static Map<String, SampleNode> loadLabeledDumps(final File file) throws IOException {
try (InputStream bis = newInputStream(file)) {
final SpecificDatumReader<StackSampleElement> reader = new SpecificDatumReader<>(StackSampleElement.SCHEMA$);
final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(bis, null);
long nrItems = decoder.readMapStart();
StackSampleElement asmp = new StackSampleElement();
Map<String, SampleNode> result = new HashMap<>((int) nrItems);
while (nrItems > 0) {
for (int i = 0; i < nrItems; i++) {
String key = decoder.readString();
TIntObjectMap<SampleNode> index = loadSamples(decoder, asmp, reader);
result.put(key, index.get(0));
}
nrItems = decoder.mapNext();
}
return result;
}
}
use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class Converter method convert.
@Nullable
public static SampleNode convert(final Iterator<StackSampleElement> samples) {
TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
while (samples.hasNext()) {
StackSampleElement asmp = samples.next();
SampleNode sn = new SampleNode(asmp.getCount());
SampleNode parent = index.get(asmp.getParentId());
if (parent != null) {
Method m = asmp.getMethod();
parent.put(m, sn);
}
index.put(asmp.getId(), sn);
}
return index.get(0);
}
use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class Converter method loadSamples.
// it's a private method, don't care about being generic
@SuppressFBWarnings("OCP_OVERLY_CONCRETE_PARAMETER")
private static TIntObjectMap<SampleNode> loadSamples(final Decoder decoder, final StackSampleElement pasmp, final SpecificDatumReader<StackSampleElement> reader) throws IOException {
TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
long nrArrayItems = decoder.readArrayStart();
while (nrArrayItems > 0) {
for (int j = 0; j < nrArrayItems; j++) {
StackSampleElement asmp = reader.read(pasmp, decoder);
SampleNode sn = new SampleNode(asmp.getCount());
SampleNode parent = index.get(asmp.getParentId());
if (parent != null) {
Method readMethod = asmp.getMethod();
Method m = new Method(readMethod.getDeclaringClass(), readMethod.getName());
parent.put(m, sn);
}
index.put(asmp.getId(), sn);
}
nrArrayItems = decoder.arrayNext();
}
return index;
}
use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class TextEntryPanel method displayActionPerformed.
@SuppressFBWarnings({ "UP_UNUSED_PARAMETER", "URLCONNECTION_SSRF_FD" })
private void displayActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_displayActionPerformed
try {
String text = jTextPane1.getText().trim();
if (text.startsWith("http")) {
URL url = new URL(text);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Accept", "application/avro");
conn.connect();
String contentType = conn.getContentType();
if (!"application/avro".equals(contentType)) {
throw new IOException("Unsupported content type " + contentType);
}
try (InputStream is = new BufferedInputStream(conn.getInputStream())) {
List<LogRecord> recs = (List<LogRecord>) readAvroBin(is, Schema.createArray(LogRecord.SCHEMA$));
for (LogRecord rec : recs) {
List<StackSampleElement> stackSamples = rec.getStackSamples();
if (!stackSamples.isEmpty()) {
nodeConsumer.accept(rec.getMsg() + "; with trId=" + rec.getTrId(), Converter.convert(stackSamples.iterator()));
}
}
}
} else if (text.startsWith("[")) {
Schema schema = Schema.createArray(StackSampleElement.getClassSchema());
DatumReader reader = new SpecificDatumReader(schema);
List<StackSampleElement> samples;
try {
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, text);
samples = (List<StackSampleElement>) reader.read(null, decoder);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
nodeConsumer.accept("SampleNode Array", Converter.convert(samples.iterator()));
} else {
nodeConsumer.accept("SampleNode Tree", SampleNode.parse(new StringReader(text)).getSecond());
}
} catch (IOException | RuntimeException ex) {
errorConsumer.accept(ex);
}
}
Aggregations