diff options
Diffstat (limited to 'tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator')
5 files changed, 15 insertions, 520 deletions
diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/event/TraceEventField.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/event/TraceEventField.java index 3bccfc8f8..304a838d0 100644 --- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/event/TraceEventField.java +++ b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/event/TraceEventField.java @@ -64,6 +64,9 @@ public class TraceEventField { long ts = 0; Double tso = optDouble(root, ITraceEventConstants.TIMESTAMP); + if (tso == Double.NaN) { + return null; + } if (Double.isFinite(tso)) { ts = (long) (tso * MICRO_TO_NANO); } @@ -72,7 +75,7 @@ public class TraceEventField { // FIXME: Easy way to avoid null warning phase = "I"; //$NON-NLS-1$ } - String name = String.valueOf(optString(root, ITraceEventConstants.NAME, TraceEventPhases.DURATION_END.equals(phase) ? "exit" : "unknown")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String name = String.valueOf(optString(root, ITraceEventConstants.NAME, TraceEventPhases.DURATION_END.equals(phase) ? "exit" : "unknown")); //$NON-NLS-1$ //$NON-NLS-2$ Integer tid = optInt(root, ITraceEventConstants.TID); if (tid == Integer.MIN_VALUE) { tid = null; diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/Messages.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/Messages.java deleted file mode 100644 index d066f3085..000000000 --- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/Messages.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.traceevent.core.trace; - -import org.eclipse.osgi.util.NLS; - -/** - * Messages - * - * @author Matthew Khouzam - * - */ -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.tracecompass.incubator.internal.traceevent.core.trace.messages"; //$NON-NLS-1$ - - /** - * Description - */ - public static String SortingJob_description; - - /** - * Merging phase - */ - public static String SortingJob_merging; - - /** - * Sorting phase - */ - public static String SortingJob_sorting; - - /** - * Splitting phase - */ - public static String SortingJob_splitting; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/SortingJob.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/SortingJob.java deleted file mode 100644 index 4c54dc2bf..000000000 --- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/SortingJob.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.traceevent.core.trace; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.PriorityQueue; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.common.core.log.TraceCompassLog; -import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils; -import org.eclipse.tracecompass.incubator.internal.traceevent.core.Activator; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; - -/** - * On-disk sorting job. It splits a trace into tracelets. Each tracelet is - * sorted in ram and written to disk, then the tracelets are merged into a big - * trace. - * - * @author Matthew Khouzam - */ -final class SortingJob extends Job { - - private static final int CHARS_PER_LINE_ESTIMATE = 50; - private static final @NonNull Logger LOGGER = TraceCompassLog.getLogger(SortingJob.class); - private static final int CHUNK_SIZE = 65535; - - private static final class Pair implements Comparable<Pair> { - private static final @NonNull BigDecimal MINUS_ONE = BigDecimal.valueOf(-1); - - public Pair(String string, int i) { - line = string; - String key = "\"ts\":"; //$NON-NLS-1$ - int indexOf = string.indexOf(key); - if (indexOf < 0) { - ts = MINUS_ONE; - } else { - int index = indexOf + key.length(); - int end = string.indexOf(',', index); - if (end == -1) { - end = string.indexOf('}', index); - } - String number = string.substring(index, end).trim(); - if (!number.isEmpty()) { - // This may be a bit slow, it can be optimized if need be. - ts = new BigDecimal(number); - } - pos = i; - } - } - - BigDecimal ts; - String line; - int pos; - - @Override - public int compareTo(Pair o) { - return ts.compareTo(o.ts); - } - } - - private final String fPath; - private final ITmfTrace fTrace; - - public SortingJob(ITmfTrace trace, String path) { - super(Messages.SortingJob_description); - fTrace = trace; - fPath = path; - - } - - @Override - protected IStatus run(IProgressMonitor monitor) { - ITmfTrace trace = fTrace; - IProgressMonitor subMonitor = SubMonitor.convert(monitor, 3); - if (trace == null) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Trace cannot be null"); //$NON-NLS-1$ - } - String dir = TmfTraceManager.getSupplementaryFileDir(trace); - subMonitor.beginTask(Messages.SortingJob_sorting, (int) (new File(fPath).length() / CHARS_PER_LINE_ESTIMATE)); - subMonitor.subTask(Messages.SortingJob_splitting); - File tempDir = new File(dir + ".tmp"); //$NON-NLS-1$ - tempDir.mkdirs(); - List<File> tracelings = new ArrayList<>(); - try (BufferedInputStream parser = new BufferedInputStream(new FileInputStream(fPath))) { - int data = parser.read(); - while (data != '[') { - data = parser.read(); - if (data == -1) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Missing symbol \'[\' or \']\' in " + fPath); //$NON-NLS-1$ - } - } - List<Pair> events = new ArrayList<>(CHUNK_SIZE); - String eventString = TraceEventTrace.readNextEventString(() -> (char) parser.read()); - if (eventString == null) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Empty event in " + fPath); //$NON-NLS-1$ - } - Pair line = new Pair(eventString, 0); - line.line = data + '"' + line.line; - int cnt = 0; - int filen = 0; - while (eventString != null) { - while (cnt < CHUNK_SIZE) { - events.add(line); - subMonitor.worked(1); - if (subMonitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - eventString = TraceEventTrace.readNextEventString(() -> (char) parser.read()); - if (eventString == null) { - break; - } - line = new Pair(eventString, 0); - cnt++; - } - events.sort((o1, o2) -> o1.ts.compareTo(o2.ts)); - cnt = 0; - File traceling = new File(tempDir + File.separator + "test" + filen + ".json"); //$NON-NLS-1$ //$NON-NLS-2$ - tracelings.add(traceling); - traceling.createNewFile(); - try (PrintWriter fs = new PrintWriter(traceling)) { - fs.println('['); - for (Pair sortedEvent : events) { - fs.println(sortedEvent.line + ','); - } - fs.println(']'); - } - events.clear(); - filen++; - subMonitor.worked(1); - if (subMonitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - - } - subMonitor.subTask(Messages.SortingJob_merging); - PriorityQueue<Pair> evs = new PriorityQueue<>(); - List<BufferedInputStream> parsers = new ArrayList<>(); - int i = 0; - for (File traceling : tracelings) { - - /* - * This resource is added to a priority queue and then removed at the very end. - */ - @SuppressWarnings("resource") - BufferedInputStream createParser = new BufferedInputStream(new FileInputStream(traceling)); - while (data != '{') { - data = (char) parser.read(); - if (data == (char) -1) { - break; - } - } - eventString = TraceEventTrace.readNextEventString(() -> (char) createParser.read()); - Pair parse = new Pair(eventString, i); - evs.add(parse); - i++; - parsers.add(createParser); - subMonitor.worked(1); - if (subMonitor.isCanceled()) { - break; - } - } - if (subMonitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - File file = new File(dir + File.separator + new File(trace.getPath()).getName()); - file.createNewFile(); - - try (PrintWriter tempWriter = new PrintWriter(file)) { - tempWriter.println('['); - while (!evs.isEmpty()) { - Pair sortedEvent = evs.poll(); - Pair parse = readNextEvent(parsers.get(sortedEvent.pos), sortedEvent.pos); - if (parse != null) { - tempWriter.println(sortedEvent.line.trim() + ','); - evs.add(parse); - } else { - tempWriter.println(sortedEvent.line.trim() + (evs.isEmpty() ? "" : ',')); //$NON-NLS-1$ - } - subMonitor.worked(1); - if (subMonitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - } - tempWriter.println(']'); - } - for (BufferedInputStream tmpParser : parsers) { - tmpParser.close(); - } - } catch (IOException e) { - TraceCompassLogUtils.traceInstant(LOGGER, Level.WARNING, "IOException in sorting job", "trace", fPath, "exception", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } finally { - for (File tl : tracelings) { - tl.delete(); - } - tempDir.delete(); - - subMonitor.done(); - } - return Status.OK_STATUS; - - } - - private static @Nullable Pair readNextEvent(BufferedInputStream parser, int i) throws IOException { - String event = TraceEventTrace.readNextEventString(() -> (char) parser.read()); - return event == null ? null : new Pair(event, i); - - } -}
\ No newline at end of file diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java index 1004b257f..5c12fe23c 100644 --- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java +++ b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/TraceEventTrace.java @@ -10,41 +10,30 @@ package org.eclipse.tracecompass.incubator.internal.traceevent.core.trace; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.incubator.internal.traceevent.core.Activator; import org.eclipse.tracecompass.incubator.internal.traceevent.core.event.TraceEventAspects; import org.eclipse.tracecompass.incubator.internal.traceevent.core.event.TraceEventEvent; import org.eclipse.tracecompass.incubator.internal.traceevent.core.event.TraceEventField; +import org.eclipse.tracecompass.incubator.jsontrace.core.trace.JsonTrace; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; -import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile; -import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider; import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceKnownSize; -import org.eclipse.tracecompass.tmf.core.trace.TmfContext; -import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; -import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable; import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; import org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation; @@ -56,7 +45,7 @@ import com.google.common.collect.Lists; * @author Matthew Khouzam * */ -public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexable, ITmfPropertiesProvider, ITmfTraceKnownSize { +public class TraceEventTrace extends JsonTrace { /** * Tid prefix to add to thread name @@ -103,19 +92,8 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab */ private static final String THREAD_SORT_INDEX = "thread_sort_index"; //$NON-NLS-1$ - private static final int CHECKPOINT_SIZE = 10000; - private static final int ESTIMATED_EVENT_SIZE = 90; - private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L); - private static final TmfContext INVALID_CONTEXT = new TmfContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK); - private static final int MAX_LINES = 100; - private static final int MAX_CONFIDENCE = 100; - private final @NonNull Map<@NonNull String, @NonNull String> fProperties = new LinkedHashMap<>(); private final @NonNull Map<Object, String> fPidNames = new HashMap<>(); private final @NonNull NavigableMap<Integer, String> fTidNames = new TreeMap<>(); - - private File fFile; - - private RandomAccessFile fFileInput; private final @NonNull Iterable<@NonNull ITmfEventAspect<?>> fEventAspects; /** @@ -166,7 +144,7 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab line = readNextEventString(() -> rafile.read()); } if (matches == 0) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Most assuredly NOT a traceevent trace"); //$NON-NLS-1$ + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Most assuredly NOT a Trace-Event trace"); //$NON-NLS-1$ } } catch (IOException e) { Activator.getInstance().logError("Error validating file: " + path, e); //$NON-NLS-1$ @@ -175,7 +153,8 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab return new TraceValidationStatus(confidence, Activator.PLUGIN_ID); } - private static void goToCorrectStart(RandomAccessFile rafile) throws IOException { + @Override + public void goToCorrectStart(RandomAccessFile rafile) throws IOException { // skip start if it's {"traceEvents": String readLine = rafile.readLine(); if (readLine == null) { @@ -189,88 +168,18 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab } @Override - public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException { - super.initTrace(resource, path, type); - fProperties.put("Type", "Trace-Event"); //$NON-NLS-1$ //$NON-NLS-2$ , value) - String dir = TmfTraceManager.getSupplementaryFileDir(this); - fFile = new File(dir + new File(path).getName()); - if (!fFile.exists()) { - Job sortJob = new SortingJob(this, path); - sortJob.schedule(); - while (sortJob.getResult() == null) { - try { - sortJob.join(); - } catch (InterruptedException e) { - throw new TmfTraceException(e.getMessage(), e); - } - } - IStatus result = sortJob.getResult(); - if (!result.isOK()) { - throw new TmfTraceException("Job failed " + result.getMessage()); //$NON-NLS-1$ - } - } - try { - fFileInput = new BufferedRandomAccessFile(fFile, "r"); //$NON-NLS-1$ - goToCorrectStart(fFileInput); - } catch (IOException e) { - throw new TmfTraceException(e.getMessage(), e); - } + public String getTraceType() { + return "Trace-Event"; //$NON-NLS-1$ } @Override - public synchronized void dispose() { - if (fFileInput != null) { - try { - fFileInput.close(); - } catch (IOException e) { - Activator.getInstance().logError("Error disposing trace. File: " + getPath(), e); //$NON-NLS-1$ - } - } - super.dispose(); - + public String getTsKey() { + return "\"ts\":"; //$NON-NLS-1$ } @Override - public double getLocationRatio(ITmfLocation location) { - return ((Long) getCurrentLocation().getLocationInfo()).doubleValue() / fFile.length(); - } - - @Override - public ITmfContext seekEvent(ITmfLocation location) { - if (fFile == null) { - return INVALID_CONTEXT; - } - final TmfContext context = new TmfContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK); - if (NULL_LOCATION.equals(location) || fFile == null) { - return context; - } - try { - if (location == null) { - fFileInput.seek(1); - } else if (location.getLocationInfo() instanceof Long) { - fFileInput.seek((Long) location.getLocationInfo()); - } - context.setLocation(new TmfLongLocation(fFileInput.getFilePointer())); - context.setRank(0); - return context; - } catch (final FileNotFoundException e) { - Activator.getInstance().logError("Error seeking event. File not found: " + getPath(), e); //$NON-NLS-1$ - return context; - } catch (final IOException e) { - Activator.getInstance().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$ - return context; - } - } - - @Override - public ITmfContext seekEvent(double ratio) { - File file = fFile; - if (file == null) { - return INVALID_CONTEXT; - } - long filePos = (long) (file.length() * ratio); - long estimatedRank = filePos / ESTIMATED_EVENT_SIZE; - return seekEvent(new TmfLongLocation(estimatedRank)); + public Integer getBracketsToSkip() { + return 1; } @Override @@ -359,127 +268,6 @@ public class TraceEventTrace extends TmfTrace implements ITmfPersistentlyIndexab } - @Override - public ITmfLocation getCurrentLocation() { - long temp = -1; - try { - temp = fFileInput.getFilePointer(); - } catch (IOException e) { - } - return new TmfLongLocation(temp); - } - - @Override - public @NonNull Map<@NonNull String, @NonNull String> getProperties() { - return fProperties; - } - - @Override - public ITmfLocation restoreLocation(ByteBuffer bufferIn) { - return new TmfLongLocation(bufferIn); - } - - @Override - public int getCheckpointSize() { - return CHECKPOINT_SIZE; - } - - /** - * Wrapper to get a character reader, allows to reconcile between java.nio and - * java.io - * - * @author Matthew Khouzam - * - */ - public static interface IReaderWrapper { - /** - * Read the next character - * - * @return the next char - * @throws IOException - * out of chars to read - */ - int read() throws IOException; - } - - /** - * Manually parse a string of JSON. High performance to extract one object - * - * @param parser - * the reader - * @return a String with a json object - * @throws IOException - * end of file, file not found or such - */ - public static @Nullable String readNextEventString(IReaderWrapper parser) throws IOException { - StringBuffer sb = new StringBuffer(); - int scope = -1; - int arrScope = 0; - boolean inQuotes = false; - int elem = parser.read(); - while (elem != -1) { - if (elem == '"') { - inQuotes = !inQuotes; - } else { - if (inQuotes) { - // do nothing - } else if (elem == '[') { - arrScope++; - } else if (elem == ']') { - if (arrScope > 0) { - arrScope--; - } else { - return null; - } - } else if (elem == '{') { - scope++; - } else if (elem == '}') { - if (scope > 0) { - scope--; - } else { - sb.append((char) elem); - return sb.toString(); - } - } - } - if (scope >= 0) { - sb.append((char) elem); - } - elem = parser.read(); - } - return null; - } - - @Override - public int size() { - RandomAccessFile fileInput = fFileInput; - if (fileInput == null) { - return 0; - } - long length = 0; - try { - length = fileInput.length(); - } catch (IOException e) { - // swallow it for now - } - return length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length; - } - - @Override - public int progress() { - RandomAccessFile fileInput = fFileInput; - if (fileInput == null) { - return 0; - } - long length = 0; - try { - length = fileInput.getFilePointer(); - } catch (IOException e) { - // swallow it for now - } - return length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length; - } - /** * Get the Process name */ diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/messages.properties b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/messages.properties deleted file mode 100644 index 9f748dc5c..000000000 --- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/trace/messages.properties +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -# Copyright (c) 2017 Ericsson -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# Ericsson - Initial API and implementation -############################################################################### - -SortingJob_description=Sorting Trace... -SortingJob_merging=Merging trace segments -SortingJob_sorting=Sorting -SortingJob_splitting=Splitting up trace into segments |