lttng: Update @since annotations for 3.0
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / CTFTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Initial API and implementation
12 * Simon Delisle - Replace LinkedList by TreeSet in callsitesByName attribute
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.ctf.core.trace;
16
17 import java.io.File;
18 import java.io.FileFilter;
19 import java.io.FileInputStream;
20 import java.io.IOException;
21 import java.io.Serializable;
22 import java.nio.ByteOrder;
23 import java.nio.MappedByteBuffer;
24 import java.nio.channels.FileChannel;
25 import java.nio.channels.FileChannel.MapMode;
26 import java.util.Arrays;
27 import java.util.Comparator;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Map.Entry;
34 import java.util.Set;
35 import java.util.TreeSet;
36 import java.util.UUID;
37
38 import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
39 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
40 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
41 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
42 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
43 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
44 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
45 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
46 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
47 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
48 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
49 import org.eclipse.linuxtools.internal.ctf.core.event.CTFCallsiteComparator;
50 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
51
52 /**
53 * A CTF trace on the file system.
54 *
55 * Represents a trace on the filesystem. It is responsible of parsing the
56 * metadata, creating declarations data structures, indexing the event packets
57 * (in other words, all the work that can be shared between readers), but the
58 * actual reading of events is left to TraceReader.
59 *
60 * @author Matthew Khouzam
61 * @version $Revision: 1.0 $
62 */
63 public class CTFTrace implements IDefinitionScope {
64
65 @SuppressWarnings("nls")
66 @Override
67 public String toString() {
68 /* Only for debugging, shouldn't be externalized */
69 return "CTFTrace [path=" + path + ", major=" + major + ", minor="
70 + minor + ", uuid=" + uuid + "]";
71 }
72
73 /**
74 * The trace directory on the filesystem.
75 */
76 private final File path;
77
78 /**
79 * Major CTF version number
80 */
81 private Long major;
82
83 /**
84 * Minor CTF version number
85 */
86 private Long minor;
87
88 /**
89 * Trace UUID
90 */
91 private UUID uuid;
92
93 /**
94 * Trace byte order
95 */
96 private ByteOrder byteOrder;
97
98 /**
99 * Packet header structure declaration
100 */
101 private StructDeclaration packetHeaderDecl = null;
102
103 /**
104 * The clock of the trace
105 */
106 private CTFClock singleClock;
107
108 /**
109 * Packet header structure definition
110 *
111 * This is only used when opening the trace files, to read the first packet
112 * header and see if they are valid trace files.
113 */
114 private StructDefinition packetHeaderDef;
115
116 /**
117 * Collection of streams contained in the trace.
118 */
119 private final Map<Long, Stream> streams = new HashMap<Long, Stream>();
120
121 /**
122 * Collection of environment variables set by the tracer
123 */
124 private final Map<String, String> environment = new HashMap<String, String>();
125
126 /**
127 * Collection of all the clocks in a system.
128 */
129 private final Map<String, CTFClock> clocks = new HashMap<String, CTFClock>();
130
131 /** FileInputStreams to the streams */
132 private final List<FileInputStream> fileInputStreams = new LinkedList<FileInputStream>();
133
134 /** Handlers for the metadata files */
135 private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter();
136 private static final Comparator<File> METADATA_COMPARATOR = new MetadataComparator();
137
138 /** map of all the event types */
139 private final Map<Long, HashMap<Long, IEventDeclaration>> eventDecs = new HashMap<Long, HashMap<Long, IEventDeclaration>>();
140
141 /** Callsite helpers */
142 private CTFCallsiteComparator ctfCallsiteComparator = new CTFCallsiteComparator();
143
144 private Map<String, TreeSet<CTFCallsite>> callsitesByName = new HashMap<String, TreeSet<CTFCallsite>>();
145
146 /** Callsite helpers */
147 private TreeSet<CTFCallsite> callsitesByIP = new TreeSet<CTFCallsite>();
148
149 // ------------------------------------------------------------------------
150 // Constructors
151 // ------------------------------------------------------------------------
152
153 /**
154 * Trace constructor.
155 *
156 * @param path
157 * Filesystem path of the trace directory
158 * @throws CTFReaderException
159 * If no CTF trace was found at the path
160 */
161 public CTFTrace(String path) throws CTFReaderException {
162 this(new File(path));
163
164 }
165
166 /**
167 * Trace constructor.
168 *
169 * @param path
170 * Filesystem path of the trace directory.
171 * @throws CTFReaderException
172 * If no CTF trace was found at the path
173 */
174 public CTFTrace(File path) throws CTFReaderException {
175 this.path = path;
176 final Metadata metadata = new Metadata(this);
177
178 /* Set up the internal containers for this trace */
179 if (!this.path.exists()) {
180 throw new CTFReaderException("Trace (" + path.getPath() + ") doesn't exist. Deleted or moved?"); //$NON-NLS-1$ //$NON-NLS-2$
181 }
182
183 if (!this.path.isDirectory()) {
184 throw new CTFReaderException("Path must be a valid directory"); //$NON-NLS-1$
185 }
186
187 /* Open and parse the metadata file */
188 metadata.parse();
189
190 /* Open all the trace files */
191 /* Create the definitions needed to read things from the files */
192 if (packetHeaderDecl != null) {
193 packetHeaderDef = packetHeaderDecl.createDefinition(this, "packet.header"); //$NON-NLS-1$
194 }
195
196 /* List files not called metadata and not hidden. */
197 File[] files = path.listFiles(METADATA_FILE_FILTER);
198 Arrays.sort(files, METADATA_COMPARATOR);
199 /* Try to open each file */
200 for (File streamFile : files) {
201 openStreamInput(streamFile);
202 }
203
204 /* Create their index */
205 for (Map.Entry<Long, Stream> stream : streams.entrySet()) {
206 Set<StreamInput> inputs = stream.getValue().getStreamInputs();
207 for (StreamInput s : inputs) {
208 /*
209 * Copy the events
210 */
211 Iterator<Entry<Long, IEventDeclaration>> it = s.getStream()
212 .getEvents().entrySet().iterator();
213 while (it.hasNext()) {
214 Entry<Long, IEventDeclaration> pairs = it.next();
215 Long eventNum = pairs.getKey();
216 IEventDeclaration eventDec = pairs.getValue();
217 getEvents(s.getStream().getId()).put(eventNum, eventDec);
218 }
219
220 /*
221 * index the trace
222 */
223 s.setupIndex();
224 }
225 }
226 }
227
228 /**
229 * Dispose the trace
230 *
231 * @since 2.0
232 */
233 public void dispose() {
234 for (FileInputStream fis : fileInputStreams) {
235 if (fis != null) {
236 try {
237 fis.close();
238 } catch (IOException e) {
239 // do nothing it's ok, we tried to close it.
240 }
241 }
242 }
243 // Invoke GC to release MappedByteBuffer objects (Java bug JDK-4724038)
244 System.gc();
245 }
246
247 // ------------------------------------------------------------------------
248 // Getters/Setters/Predicates
249 // ------------------------------------------------------------------------
250
251 /**
252 * Gets an event declaration hash map for a given streamID
253 *
254 * @param streamId
255 * The ID of the stream from which to read
256 * @return The Hash map with the event declarations
257 * @since 2.0
258 */
259 public Map<Long, IEventDeclaration> getEvents(Long streamId) {
260 return eventDecs.get(streamId);
261 }
262
263 /**
264 * Gets an event Declaration hashmap for a given StreamInput
265 *
266 * @param id
267 * the StreamInput
268 * @return an empty hashmap, please see deprecated
269 * @since 2.0
270 * @deprecated You should be using
271 * {@link StreamInputReader#getEventDefinitions()} instead.
272 */
273 @Deprecated
274 public Map<Long, EventDefinition> getEventDefs(StreamInput id) {
275 return new HashMap<Long, EventDefinition>();
276 }
277
278 /**
279 * Get an event by it's ID
280 *
281 * @param streamId
282 * The ID of the stream from which to read
283 * @param id
284 * the ID of the event
285 * @return the event declaration
286 * @since 2.0
287 */
288 public IEventDeclaration getEventType(long streamId, long id) {
289 return getEvents(streamId).get(id);
290 }
291
292 /**
293 * Method getStream gets the stream for a given id
294 *
295 * @param id
296 * Long the id of the stream
297 * @return Stream the stream that we need
298 * @since 2.0
299 */
300 public Stream getStream(Long id) {
301 return streams.get(id);
302 }
303
304 /**
305 * Method nbStreams gets the number of available streams
306 *
307 * @return int the number of streams
308 */
309 public int nbStreams() {
310 return streams.size();
311 }
312
313 /**
314 * Method setMajor sets the major version of the trace (DO NOT USE)
315 *
316 * @param major
317 * long the major version
318 */
319 public void setMajor(long major) {
320 this.major = major;
321 }
322
323 /**
324 * Method setMinor sets the minor version of the trace (DO NOT USE)
325 *
326 * @param minor
327 * long the minor version
328 */
329 public void setMinor(long minor) {
330 this.minor = minor;
331 }
332
333 /**
334 * Method setUUID sets the UUID of a trace
335 *
336 * @param uuid
337 * UUID
338 */
339 public void setUUID(UUID uuid) {
340 this.uuid = uuid;
341 }
342
343 /**
344 * Method setByteOrder sets the byte order
345 *
346 * @param byteOrder
347 * ByteOrder of the trace, can be little-endian or big-endian
348 */
349 public void setByteOrder(ByteOrder byteOrder) {
350 this.byteOrder = byteOrder;
351 }
352
353 /**
354 * Method setPacketHeader sets the packet header of a trace (DO NOT USE)
355 *
356 * @param packetHeader
357 * StructDeclaration the header in structdeclaration form
358 */
359 public void setPacketHeader(StructDeclaration packetHeader) {
360 this.packetHeaderDecl = packetHeader;
361 }
362
363 /**
364 * Method majorIsSet is the major version number set?
365 *
366 * @return boolean is the major set?
367 * @since 3.0
368 */
369 public boolean majorIsSet() {
370 return major != null;
371 }
372
373 /**
374 * Method minorIsSet. is the minor version number set?
375 *
376 * @return boolean is the minor set?
377 */
378 public boolean minorIsSet() {
379 return minor != null;
380 }
381
382 /**
383 * Method UUIDIsSet is the UUID set?
384 *
385 * @return boolean is the UUID set?
386 * @since 2.0
387 */
388 public boolean uuidIsSet() {
389 return uuid != null;
390 }
391
392 /**
393 * Method byteOrderIsSet is the byteorder set?
394 *
395 * @return boolean is the byteorder set?
396 */
397 public boolean byteOrderIsSet() {
398 return byteOrder != null;
399 }
400
401 /**
402 * Method packetHeaderIsSet is the packet header set?
403 *
404 * @return boolean is the packet header set?
405 */
406 public boolean packetHeaderIsSet() {
407 return packetHeaderDecl != null;
408 }
409
410 /**
411 * Method getUUID gets the trace UUID
412 *
413 * @return UUID gets the trace UUID
414 */
415 public UUID getUUID() {
416 return uuid;
417 }
418
419 /**
420 * Method getMajor gets the trace major version
421 *
422 * @return long gets the trace major version
423 */
424 public long getMajor() {
425 return major;
426 }
427
428 /**
429 * Method getMinor gets the trace minor version
430 *
431 * @return long gets the trace minor version
432 */
433 public long getMinor() {
434 return minor;
435 }
436
437 /**
438 * Method getByteOrder gets the trace byte order
439 *
440 * @return ByteOrder gets the trace byte order
441 */
442 public final ByteOrder getByteOrder() {
443 return byteOrder;
444 }
445
446 /**
447 * Method getPacketHeader gets the trace packet header
448 *
449 * @return StructDeclaration gets the trace packet header
450 */
451 public StructDeclaration getPacketHeader() {
452 return packetHeaderDecl;
453 }
454
455 /**
456 * Method getTraceDirectory gets the trace directory
457 *
458 * @return File the path in "File" format.
459 */
460 public File getTraceDirectory() {
461 return path;
462 }
463
464 /**
465 * Method getStreams get all the streams in a map format.
466 *
467 * @return Map<Long,Stream> a map of all the streams.
468 */
469 public Map<Long, Stream> getStreams() {
470 return streams;
471 }
472
473 /**
474 * Method getPath gets the path of the trace directory
475 *
476 * @return String the path of the trace directory, in string format.
477 * @see java.io.File#getPath()
478 */
479 @Override
480 public String getPath() {
481 return path.getPath();
482 }
483
484 // ------------------------------------------------------------------------
485 // Operations
486 // ------------------------------------------------------------------------
487
488 /**
489 * Tries to open the given file, reads the first packet header of the file
490 * and check its validity.
491 *
492 * @param streamFile
493 * A trace file in the trace directory.
494 * @param index
495 * Which index in the class' streamFileChannel array this file
496 * must use
497 * @throws CTFReaderException
498 */
499 private void openStreamInput(File streamFile) throws CTFReaderException {
500 MappedByteBuffer byteBuffer;
501 BitBuffer streamBitBuffer;
502 Stream stream;
503 FileChannel fc;
504
505 if (!streamFile.canRead()) {
506 throw new CTFReaderException("Unreadable file : " //$NON-NLS-1$
507 + streamFile.getPath());
508 }
509
510 try {
511 /* Open the file and get the FileChannel */
512 FileInputStream fis = new FileInputStream(streamFile);
513 fileInputStreams.add(fis);
514 fc = fis.getChannel();
515
516 /* Map one memory page of 4 kiB */
517 byteBuffer = fc.map(MapMode.READ_ONLY, 0, (int) Math.min(fc.size(), 4096L));
518 } catch (IOException e) {
519 /* Shouldn't happen at this stage if every other check passed */
520 throw new CTFReaderException(e);
521 }
522
523 /* Create a BitBuffer with this mapping and the trace byte order */
524 streamBitBuffer = new BitBuffer(byteBuffer, this.getByteOrder());
525
526 if (packetHeaderDef != null) {
527 /* Read the packet header */
528 packetHeaderDef.read(streamBitBuffer);
529
530 /* Check the magic number */
531 IntegerDefinition magicDef = (IntegerDefinition) packetHeaderDef
532 .lookupDefinition("magic"); //$NON-NLS-1$
533 int magic = (int) magicDef.getValue();
534 if (magic != Utils.CTF_MAGIC) {
535 throw new CTFReaderException("CTF magic mismatch"); //$NON-NLS-1$
536 }
537
538 /* Check UUID */
539 ArrayDefinition uuidDef = (ArrayDefinition) packetHeaderDef
540 .lookupDefinition("uuid"); //$NON-NLS-1$
541 if (uuidDef != null) {
542 byte[] uuidArray = new byte[Utils.UUID_LEN];
543
544 for (int i = 0; i < Utils.UUID_LEN; i++) {
545 IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
546 .getElem(i);
547 uuidArray[i] = (byte) uuidByteDef.getValue();
548 }
549
550 UUID otheruuid = Utils.makeUUID(uuidArray);
551
552 if (!this.uuid.equals(otheruuid)) {
553 throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
554 }
555 }
556
557 /* Read the stream ID */
558 Definition streamIDDef = packetHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
559
560 if (streamIDDef instanceof IntegerDefinition) { // this doubles as a
561 // null check
562 long streamID = ((IntegerDefinition) streamIDDef).getValue();
563 stream = streams.get(streamID);
564 } else {
565 /* No stream_id in the packet header */
566 stream = streams.get(null);
567 }
568
569 } else {
570 /* No packet header, we suppose there is only one stream */
571 stream = streams.get(null);
572 }
573
574 if (stream == null) {
575 throw new CTFReaderException("Unexpected end of stream"); //$NON-NLS-1$
576 }
577
578 /* Create the stream input */
579 StreamInput streamInput = new StreamInput(stream, fc, streamFile);
580
581 /* Add a reference to the streamInput in the stream */
582 stream.addInput(streamInput);
583 }
584
585 /**
586 * Looks up a definition from packet
587 *
588 * @param lookupPath
589 * String
590 * @return Definition
591 * @see org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope#lookupDefinition(String)
592 */
593 @Override
594 public Definition lookupDefinition(String lookupPath) {
595 if (lookupPath.equals("trace.packet.header")) { //$NON-NLS-1$
596 return packetHeaderDef;
597 }
598 return null;
599 }
600
601 /**
602 * Adds a new stream to the trace.
603 *
604 * @param stream
605 * A stream object.
606 * @throws ParseException
607 * If there was some problem reading the metadata
608 * @since 2.0
609 */
610 public void addStream(Stream stream) throws ParseException {
611
612 /*
613 * If there is already a stream without id (the null key), it must be
614 * the only one
615 */
616 if (streams.get(null) != null) {
617 throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$
618 }
619
620 /*
621 * If the stream we try to add has the null key, it must be the only
622 * one. Thus, if the streams container is not empty, it is not valid.
623 */
624 if ((stream.getId() == null) && (streams.size() != 0)) {
625 throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$
626 }
627
628 /* If a stream with the same ID already exists, it is not valid. */
629 if (streams.get(stream.getId()) != null) {
630 throw new ParseException("Stream id already exists"); //$NON-NLS-1$
631 }
632
633 /* It should be ok now. */
634 streams.put(stream.getId(), stream);
635 eventDecs.put(stream.getId(), new HashMap<Long, IEventDeclaration>());
636 }
637
638 /**
639 * gets the Environment variables from the trace metadata (See CTF spec)
640 *
641 * @return the environment variables in a map form (key value)
642 * @since 2.0
643 */
644 public Map<String, String> getEnvironment() {
645 return environment;
646 }
647
648 /**
649 * Look up a specific environment variable
650 *
651 * @param key
652 * the key to look for
653 * @return the value of the variable, can be null.
654 */
655 public String lookupEnvironment(String key) {
656 return environment.get(key);
657 }
658
659 /**
660 * Add a variable to the environment variables
661 *
662 * @param varName
663 * the name of the variable
664 * @param varValue
665 * the value of the variable
666 */
667 public void addEnvironmentVar(String varName, String varValue) {
668 environment.put(varName, varValue);
669 }
670
671 /**
672 * Add a clock to the clock list
673 *
674 * @param nameValue
675 * the name of the clock (full name with scope)
676 * @param ctfClock
677 * the clock
678 */
679 public void addClock(String nameValue, CTFClock ctfClock) {
680 clocks.put(nameValue, ctfClock);
681 }
682
683 /**
684 * gets the clock with a specific name
685 *
686 * @param name
687 * the name of the clock.
688 * @return the clock
689 */
690 public CTFClock getClock(String name) {
691 return clocks.get(name);
692 }
693
694 /**
695 * gets the clock if there is only one. (this is 100% of the use cases as of
696 * June 2012)
697 *
698 * @return the clock
699 */
700 public final CTFClock getClock() {
701 if (clocks.size() == 1) {
702 singleClock = clocks.get(clocks.keySet().iterator().next());
703 return singleClock;
704 }
705 return null;
706 }
707
708 /**
709 * gets the time offset of a clock with respect to UTC in nanoseconds
710 *
711 * @return the time offset of a clock with respect to UTC in nanoseconds
712 */
713 public final long getOffset() {
714 if (getClock() == null) {
715 return 0;
716 }
717 return singleClock.getClockOffset();
718 }
719
720 /**
721 * gets the time offset of a clock with respect to UTC in nanoseconds
722 *
723 * @return the time offset of a clock with respect to UTC in nanoseconds
724 */
725 private double getTimeScale() {
726 if (getClock() == null) {
727 return 1.0;
728 }
729 return singleClock.getClockScale();
730 }
731
732 /**
733 * Does the trace need to time scale?
734 *
735 * @return if the trace is in ns or cycles.
736 */
737 private boolean clockNeedsScale() {
738 if (getClock() == null) {
739 return false;
740 }
741 return singleClock.isClockScaled();
742 }
743
744 /**
745 * the inverse clock for returning to a scale.
746 *
747 * @return 1.0 / scale
748 */
749 private double getInverseTimeScale() {
750 if (getClock() == null) {
751 return 1.0;
752 }
753 return singleClock.getClockAntiScale();
754 }
755
756 /**
757 * @param cycles
758 * clock cycles since boot
759 * @return time in nanoseconds UTC offset
760 * @since 2.0
761 */
762 public long timestampCyclesToNanos(long cycles) {
763 long retVal = cycles + getOffset();
764 /*
765 * this fix is since quite often the offset will be > than 53 bits and
766 * therefore the conversion will be lossy
767 */
768 if (clockNeedsScale()) {
769 retVal = (long) (retVal * getTimeScale());
770 }
771 return retVal;
772 }
773
774 /**
775 * @param nanos
776 * time in nanoseconds UTC offset
777 * @return clock cycles since boot.
778 * @since 2.0
779 */
780 public long timestampNanoToCycles(long nanos) {
781 long retVal;
782 /*
783 * this fix is since quite often the offset will be > than 53 bits and
784 * therefore the conversion will be lossy
785 */
786 if (clockNeedsScale()) {
787 retVal = (long) (nanos * getInverseTimeScale());
788 } else {
789 retVal = nanos;
790 }
791 return retVal - getOffset();
792 }
793
794 /**
795 * Does a given stream contain any events?
796 *
797 * @param id
798 * the stream ID
799 * @return true if the stream has events.
800 */
801 public boolean hasEvents(Long id) {
802 return eventDecs.containsKey(id);
803 }
804
805 /**
806 * Add an event declaration map to the events map.
807 *
808 * @param id
809 * the id of a stream
810 * @return the hashmap containing events.
811 * @since 2.0
812 */
813 public Map<Long, IEventDeclaration> createEvents(Long id) {
814 HashMap<Long, IEventDeclaration> value = eventDecs.get(id);
815 if (value == null) {
816 value = new HashMap<Long, IEventDeclaration>();
817 eventDecs.put(id, value);
818 }
819 return value;
820 }
821
822 /**
823 * Adds a callsite
824 *
825 * @param eventName
826 * the event name of the callsite
827 * @param funcName
828 * the name of the callsite function
829 * @param ip
830 * the ip of the callsite
831 * @param fileName
832 * the filename of the callsite
833 * @param lineNumber
834 * the line number of the callsite
835 */
836 public void addCallsite(String eventName, String funcName, long ip,
837 String fileName, long lineNumber) {
838 final CTFCallsite cs = new CTFCallsite(eventName, funcName, ip,
839 fileName, lineNumber);
840 TreeSet<CTFCallsite> csl = callsitesByName.get(eventName);
841 if (csl == null) {
842 csl = new TreeSet<CTFCallsite>(ctfCallsiteComparator);
843 callsitesByName.put(eventName, csl);
844 }
845
846 csl.add(cs);
847
848 callsitesByIP.add(cs);
849 }
850
851 /**
852 * Gets the set of callsites associated to an event name. O(1)
853 *
854 * @param eventName
855 * the event name
856 * @return the callsite set can be empty
857 * @since 3.0
858 */
859 public TreeSet<CTFCallsite> getCallsiteCandidates(String eventName) {
860 TreeSet<CTFCallsite> retVal = callsitesByName.get(eventName);
861 if (retVal == null) {
862 retVal = new TreeSet<CTFCallsite>(ctfCallsiteComparator);
863 }
864 return retVal;
865 }
866
867 /**
868 * The I'm feeling lucky of getCallsiteCandidates O(1)
869 *
870 * @param eventName
871 * the event name
872 * @return the first callsite that has that event name, can be null
873 * @since 1.2
874 */
875 public CTFCallsite getCallsite(String eventName) {
876 TreeSet<CTFCallsite> callsites = callsitesByName.get(eventName);
877 if (callsites != null) {
878 return callsites.first();
879 }
880 return null;
881 }
882
883 /**
884 * Gets a callsite from the instruction pointer O(log(n))
885 *
886 * @param ip
887 * the instruction pointer to lookup
888 * @return the callsite just before that IP in the list remember the IP is
889 * backwards on X86, can be null if no callsite is before the IP.
890 * @since 1.2
891 */
892 public CTFCallsite getCallsite(long ip) {
893 CTFCallsite cs = new CTFCallsite(null, null, ip, null, 0L);
894 return callsitesByIP.ceiling(cs);
895 }
896
897 /**
898 * Gets a callsite using the event name and instruction pointer O(log(n))
899 *
900 * @param eventName
901 * the name of the event
902 * @param ip
903 * the instruction pointer
904 * @return the closest matching callsite, can be null
905 */
906 public CTFCallsite getCallsite(String eventName, long ip) {
907 final TreeSet<CTFCallsite> candidates = callsitesByName.get(eventName);
908 final CTFCallsite dummyCs = new CTFCallsite(null, null, ip, null, -1);
909 final CTFCallsite callsite = candidates.ceiling(dummyCs);
910 if (callsite == null) {
911 return candidates.floor(dummyCs);
912 }
913 return callsite;
914 }
915 }
916
917 class MetadataFileFilter implements FileFilter {
918
919 @Override
920 public boolean accept(File pathname) {
921 if (pathname.isDirectory()) {
922 return false;
923 }
924 if (pathname.isHidden()) {
925 return false;
926 }
927 if (pathname.getName().equals("metadata")) { //$NON-NLS-1$
928 return false;
929 }
930 return true;
931 }
932
933 }
934
935 class MetadataComparator implements Comparator<File>, Serializable {
936
937 private static final long serialVersionUID = 1L;
938
939 @Override
940 public int compare(File o1, File o2) {
941 return o1.getName().compareTo(o2.getName());
942 }
943 }
This page took 0.056156 seconds and 5 git commands to generate.