Skip to content

Commit

Permalink
Merge pull request worstcase#10 from newbrough/feature/ui-toolbar
Browse files Browse the repository at this point in the history
Feature/ui toolbar
  • Loading branch information
newbrough committed May 4, 2016
2 parents d4249d7 + 0b7b728 commit 8f43658
Show file tree
Hide file tree
Showing 41 changed files with 1,648 additions and 427 deletions.
93 changes: 93 additions & 0 deletions bin/inspector
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#! /bin/sh
#

## where is gumshoe installed? probably right here
if [ -z "$GUMSHOE_HOME" ]
then
bindir="`dirname $0`"
if [ . = "$bindir" ]
then
bindir="`pwd`"
fi
GUMSHOE_HOME="`dirname $bindir`"
fi

## make sure jar is built
jarfile="$GUMSHOE_HOME/gumshoe-tools/target/inspector.jar"
if [ ! -f "$jarfile" ]
then
echo 'ERROR: gumshoe inspector executable jar not found (project not built?)' 1>&2
echo 'First build with: mvn install' 1>&2
exit 1
fi

## default 5min reporting period for any probes enabled
period=300000 # 5min

## add args for probes
opts="-Xmx1g"
needhook=false
while [ $# -gt 0 ]
do
case "$1" in
## by default, probe is not enabled unless there is some other "main" to trace
## using this option, investigator can monitor stats on itself (demo purposes?)
-force)
opts="$opts -Dgumshoe.probe.enabled=true "
;;
-cpu)
opts="$opts -Dgumshoe.cpu-usage.period=$period "
opts="$opts -Dgumshoe.cpu-usage.sample=5000"
opts="$opts -Dgumshoe.cpu-usage.filter.none=true"
;;
-file-io)
opts="$opts -Dgumshoe.file-io.period=$period"
opts="$opts -Dgumshoe.file-io.filter.none=true"
needhook=true
;;
-socket-io)
opts="$opts -Dgumshoe.socket-io.period=$period"
opts="$opts -Dgumshoe.socket-io.filter.none=true"
needhook=true
;;
-datagram-io)
opts="$opts -Dgumshoe.datagram-io.period=$period"
opts="$opts -Dgumshoe.datagram-io.filter.none=true"
;;
-unclosed)
opts="$opts -Dgumshoe.socket-unclosed.period=$period"
opts="$opts -Dgumshoe.socket-unclosed.filter.none=true"
;;
*)
break
;;
esac

shift
done

if $needhook
then
hookdir="$GUMSHOE_HOME/gumshoe-hooks/target"
hookcount="`ls $hookdir | grep -c '^gumshoe-hooks-*.jar'`"
case $hookcount in
0)
echo ERROR: gumshoe hook jar not found in $hookdir 1>&2
exit 1
;;
1)
## file and socket I/O probes need the sun.misc.SocketIo hook
hookfile="`ls $hookdir | grep '^gumshoe-hooks-*.jar'`"
opts="$opts -Xbootclasspath/p:$hookdir/$hookfile"
;;
*)
## could get fancy here, but i don't expect people to leave stray jars around
echo 'ERROR: more than one gumshoe hook jar found $hookdir !' 1>&2
echo 'Rebuild with: mvn clean install' 1>&2
exit 1
;;
esac
fi

## warning: can fail if orig cmdline contains quoted expressions like: java some.MainClass "first arg" second "third arg"
java $opts -jar "$jarfile" $*
7 changes: 6 additions & 1 deletion gumshoe-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -63,7 +68,7 @@
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dell.gumshoe.inspector.Inspector</mainClass>
<mainClass>com.dell.gumshoe.inspector.Main</mainClass>
</manifest>
</archive>
<finalName>inspector</finalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dell.gumshoe.stats.StatisticAdder;
import com.dell.gumshoe.stats.ValueReporter;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
Expand Down Expand Up @@ -34,17 +35,23 @@
*/
public class FileDataParser {
private final BidirectionalMap savedPositions = new BidirectionalMap();
private final RandomAccessFile file;
private final RandomAccessFile raf;
private Long lastPosition;
private final ValueReporter reporter = new ValueReporter("socket-io");
public FileDataParser(RandomAccessFile file) { this.file = file; }
private final String filename;
private final Map<Long,String> typeByPosition = new HashMap<>();
private boolean parsedWholeFile = false;

public FileDataParser(String text) throws Exception {
this(new RandomAccessFile(text, "r"));
raf = new RandomAccessFile(text, "r");
filename = text;
}
public FileDataParser(File file) throws Exception {
raf = new RandomAccessFile(file, "r");
filename = file.getName();
}

public void close() throws IOException {
file.close();
raf.close();
savedPositions.clear();
lastPosition = null;
}
Expand All @@ -68,19 +75,20 @@ public Map<Stack, StatisticAdder> getSample(Date date) throws Exception {
lastPosition = null;
return null;
}
file.seek(position);
raf.seek(position);
return getNextSample();
}

/////

/** return next sample found after current position in file */
public Map<Stack, StatisticAdder> getNextSample() throws Exception {
long positionBefore = file.getFilePointer();
long positionBefore = raf.getFilePointer();
Map<Stack, StatisticAdder> sample = read();
if(sample==null) {
parsedWholeFile = true;
lastPosition = null;
file.seek(0); // wrap around
raf.seek(0); // wrap around
} else {
lastPosition = savedPositions.getPositionAtOrAfter(positionBefore);
}
Expand All @@ -91,7 +99,7 @@ public Map<Stack, StatisticAdder> getNextSample() throws Exception {
public Map<Stack, StatisticAdder> getPreviousSample() throws Exception {
lastPosition = savedPositions.getPositionBefore(lastPosition);
if(lastPosition==null) { return null; }
file.seek(lastPosition);
raf.seek(lastPosition);
return read();
}

Expand All @@ -100,29 +108,32 @@ public Date getSampleTime() {
return savedPositions.getTime(lastPosition);
}

public String getSampleType() {
return typeByPosition.get(lastPosition);
}
private Map<Stack,StatisticAdder> read() throws Exception {
String line = null;

// read until find a start tag
long startPosition = file.getFilePointer();
long startPosition = raf.getFilePointer();
Date startTime = null;
String type = null;
DataTypeHelper helper = null;
while((line=file.readLine())!=null) {
while((line=raf.readLine())!=null) {
startTime = ValueReporter.parseStartTagTime(line);
if(startTime!=null) {
type = ValueReporter.parseStartTagType(line);
helper = DataTypeHelper.forType(type);
break;
}
startPosition = file.getFilePointer();
startPosition = raf.getFilePointer();
}
if(startTime==null) { return null; }

final Map<Stack,StatisticAdder> out = new HashMap<>();
StatisticAdder stats = null;
final List<StackTraceElement> stackFrames = new ArrayList<>();
while((line=file.readLine())!=null) {
while((line=raf.readLine())!=null) {
if(line.startsWith(Stack.FRAME_PREFIX)) {
if(stats==null) {
throw new IllegalStateException("stack line read but no stats");
Expand All @@ -134,6 +145,7 @@ private Map<Stack,StatisticAdder> read() throws Exception {
out.put(stack, stats);
}
savedPositions.put(startTime, startPosition);
typeByPosition.put(startPosition, type);
return out;
} else {
// parse first, make sure is expected format
Expand Down Expand Up @@ -192,4 +204,16 @@ public Long getPositionAtOrAfter(Long position) {
return timeByPosition.higherKey(position);
}
}

public String getFilename() {
return filename;
}

public boolean hasPrevious() {
return savedPositions.getPositionBefore(lastPosition)!=null;
}

public boolean hasNext() {
return (lastPosition!=null && savedPositions.getPositionAtOrAfter(lastPosition+1)!=null) || ! parsedWholeFile;
}
}
Loading

0 comments on commit 8f43658

Please sign in to comment.