-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
12,601 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>bren</groupId> | ||
<artifactId>bren</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>bren</name> | ||
|
||
<build> | ||
<resources> | ||
|
||
<!-- resource processsing with a different output directory for logback.xml --> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
<!-- relative to target/classes i.e. ${project.build.outputDirectory} --> | ||
<targetPath>..</targetPath> | ||
</resource> | ||
</resources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<!-- specify UTF-8, ISO-8859-1 or any other file encoding --> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<!-- Create Javadocs --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.6.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>install</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- all in one jar --> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>fully.qualified.MainClass</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</plugin> | ||
|
||
<!-- Package up the source --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.1.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javasources</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>jline</groupId> | ||
<artifactId>jline</artifactId> | ||
<version>2.12-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.tools.btrace</groupId> | ||
<artifactId>btrace-client</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.tools.btrace</groupId> | ||
<artifactId>btrace-boot</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.tools.btrace</groupId> | ||
<artifactId>btrace-agent</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.bren; | ||
|
||
import java.io.File; | ||
import java.net.URLDecoder; | ||
import java.security.CodeSource; | ||
|
||
import com.bren.console.CommandView; | ||
import com.bren.service.CommandListener; | ||
import com.bren.util.Constants; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws Exception { | ||
if(!initSettings(args)){ | ||
System.out.println("缺失参数"); | ||
return; | ||
} | ||
CommandView view=new CommandView(); | ||
CommandListener listener =new CommandListener(); | ||
view.addCommandListener(listener); | ||
view.start(); | ||
listener.start(); | ||
} | ||
|
||
public static boolean initSettings(String[] args) throws Exception{ | ||
if(args==null){ | ||
return false; | ||
} | ||
if(args.length<2){ | ||
return false; | ||
} | ||
Constants.BTRACE_PATH=getAbsolutePath(args[0]); | ||
Constants.SCRIPT_PATH=getAbsolutePath(args[1]); | ||
|
||
return true; | ||
} | ||
|
||
public static String getAbsolutePath(String path) throws Exception{ | ||
if(new File(path).isAbsolute()){ | ||
return new File(path).getCanonicalPath(); | ||
} | ||
return new File(getExecutedPath(Main.class)+path).getCanonicalPath(); | ||
} | ||
|
||
|
||
public static String getExecutedPath(Class<?> aclass) throws Exception { | ||
CodeSource codeSource = aclass.getProtectionDomain().getCodeSource(); | ||
|
||
File file; | ||
|
||
if (codeSource.getLocation() != null) { | ||
file = new File(codeSource.getLocation().toURI()); | ||
} else { | ||
String path = aclass.getResource(aclass.getSimpleName() + ".class") | ||
.getPath(); | ||
String filePath = path.substring(path.indexOf(":") + 1, | ||
path.indexOf("!")); | ||
filePath = URLDecoder.decode(filePath, "UTF-8"); | ||
file = new File(filePath); | ||
|
||
} | ||
if (file.isFile()) {//if executed with jar file | ||
return file.getParentFile().getCanonicalPath(); | ||
} else { | ||
return file.getCanonicalPath(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.bren.console; | ||
|
||
import java.awt.event.ActionListener; | ||
import java.io.IOException; | ||
|
||
import jline.console.ConsoleReader; | ||
|
||
import com.bren.service.CommandListener; | ||
import com.bren.service.Session; | ||
|
||
public class CommandView extends Thread { | ||
private ConsoleReader console; | ||
private CommandListener listener; | ||
private boolean running; | ||
|
||
public CommandView() { | ||
try { | ||
console = new ConsoleReader(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
usage(); | ||
if (listener == null) { | ||
return; | ||
} | ||
|
||
try { | ||
String line; | ||
String PID; | ||
do{ | ||
this.write("input the PID of Process you monitor "); | ||
PID = console.readLine("\u001B[0m$ "); | ||
} while (!PID.matches("^[0-9]+$")) ; | ||
Session.PID = Integer.parseInt(PID); | ||
|
||
while ((line = console.readLine("\u001B[0m$ ")) != null && running) { | ||
if((line=line.trim()).equals("")){ | ||
console.delete(); | ||
continue; | ||
} | ||
if (line.equalsIgnoreCase("quit") | ||
|| line.equalsIgnoreCase("exit")) { | ||
this.destroy(); | ||
listener.destroy(); | ||
System.exit(0); | ||
break; | ||
} | ||
listener.deal(line); | ||
} | ||
|
||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
|
||
public void write(String str) { | ||
try { | ||
this.console.println("\u001B[33m" + str); | ||
console.flush(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void usage() { | ||
this.write("\u001B[33mwelcome to use bren monitor,run \"help\" to display the usage\u001B[0m"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
new CommandView().start(); | ||
} | ||
|
||
public void addCommandListener(CommandListener listener) { | ||
this.listener = listener; | ||
listener.setCommandView(this); | ||
} | ||
|
||
public void bindKey(char key,ActionListener listener){ | ||
console.addTriggeredAction(key, listener); | ||
} | ||
|
||
@Override | ||
public void start(){ | ||
this.running=true; | ||
super.start(); | ||
} | ||
|
||
@Override | ||
public void destroy(){ | ||
this.running=false; | ||
} | ||
|
||
|
||
public int readCharacter() { | ||
try { | ||
return this.console.readCharacter(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
return -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bren.service; | ||
|
||
import com.bren.trace.AllCallsTracer; | ||
import com.bren.trace.IbatisTracer; | ||
import com.bren.trace.Tracer; | ||
|
||
public enum CommandHandler { | ||
CALL( new AllCallsTracer()),IBATIS(new IbatisTracer()); | ||
private Tracer tracer; | ||
|
||
CommandHandler(Tracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
|
||
public Tracer getTracer() { | ||
return tracer; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.bren.service; | ||
|
||
import com.bren.console.CommandView; | ||
|
||
public class CommandListener extends Thread { | ||
private CommandView view; | ||
private boolean running; | ||
private CommandHandler curCommandHandler; | ||
|
||
public void deal(String line) { | ||
String[] commandArr = line.split("\\s+"); | ||
|
||
if (commandArr.length < 1) { | ||
view.write("Illegal command"); | ||
} | ||
|
||
String commandName = commandArr[0]; | ||
commandName = commandName.toUpperCase(); | ||
try { | ||
curCommandHandler = CommandHandler.valueOf(commandName); | ||
curCommandHandler.getTracer().execute(commandArr);// 执行命令 | ||
|
||
this.waitForStop(); | ||
//stop command executing | ||
curCommandHandler.getTracer().stop(); | ||
} catch (IllegalArgumentException e) { | ||
view.write("Unsupported parameter,run help for usage detail "); | ||
} catch (Exception e) { | ||
view.write(e.getMessage()); | ||
} | ||
} | ||
|
||
private void waitForStop() { | ||
while (view.readCharacter() != 113){ | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (running) { | ||
String line = Session.getHandleResponse(); | ||
view.write(line); | ||
} | ||
} | ||
|
||
@Override | ||
public void start() { | ||
// view.bindKey('q', new ActionListener() { | ||
// @Override | ||
// public void actionPerformed(ActionEvent e) { | ||
// view.write("aha"); | ||
// if (curCommandHandler != null) | ||
// curCommandHandler.getTracer().stop(); | ||
// } | ||
// }); WAIT FOR NEW VERSION JLINE2 TO RESOLVE THIS | ||
|
||
this.running = true; | ||
super.start(); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
this.running = false; | ||
if (curCommandHandler != null) | ||
curCommandHandler.getTracer().stop(); | ||
} | ||
|
||
public void setCommandView(CommandView commandView) { | ||
this.view = commandView; | ||
} | ||
|
||
} |
Oops, something went wrong.