Skip to content
Snippets Groups Projects
Commit e764f802 authored by ael-mess's avatar ael-mess
Browse files

cleaning

parent 31bc3bfe
Branches
No related tags found
No related merge requests found
Showing
with 1381 additions and 0 deletions
Manifest-Version: 1.0
Package-Name: com
Main-Class: com.main
Class-Path: /usr/local/lib/w3c.jar /usr/local/lib/antlr-4.7.2-complete.jar /usr/local/lib/batik-1.10/lib/batik-all-1.10.jar
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public class clone_entry extends kernel_syscall {
protected Long clone_flag = null;
protected Long newsp = null;
protected Long parent_tid = null;
protected Long child_tid = null;
public clone_entry(time_trace time, Integer cpu_id, Integer pid, Integer tid, String flag, String newsp, String ptid, String ctid) {
this.time = time;
this.cpu_id = cpu_id;
this.pid = pid;
this.tid = tid;
this.clone_flag = Long.parseLong(flag.substring(2), 16);
this.newsp = Long.parseLong(newsp.substring(2), 16);
this.parent_tid = Long.parseLong(ptid.substring(2), 16);
this.child_tid = Long.parseLong(ctid.substring(2), 16);
}
public Long getClone_flag() {
return this.clone_flag;
}
public Long getNewsp() {
return this.newsp;
}
public Long getParent_tid() {
return this.parent_tid;
}
public Long getChild_tid() {
return this.child_tid;
}
public String description() {
return "["+super.time.getHour()+":"+super.time.getMinute()+":"+super.time.getSeconde()+"] (+"+super.time.getDelta()+") cpu id="+super.getCpu_id()+", pid="+super.getPid()+", tid="+super.getTid()+" "+this.getClone_flag()+" "+this.getNewsp()+" "+this.getChild_tid()+" "+this.getParent_tid();
}
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public class clone_exit extends kernel_syscall {
protected Integer ret = null;
public clone_exit(time_trace time, Integer cpu_id, Integer pid, Integer tid, Integer ret) {
this.time = time;
this.cpu_id = cpu_id;
this.pid = pid;
this.tid = tid;
this.ret = ret;
}
public Integer getRet() {
return this.ret;
}
public String description() {
return "["+super.time.getHour()+":"+super.time.getMinute()+":"+super.time.getSeconde()+"] (+"+super.time.getDelta()+") cpu id="+super.getCpu_id()+", pid="+super.getPid()+", tid="+super.getTid()+" "+this.getRet();
}
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public abstract class kernel_syscall extends trace {
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public abstract class kernel_tracepoint extends trace {
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
import java.math.BigInteger;
public class ptask_tracepoint extends userspace_tracepoint {
protected String flag = null;
protected String state = null;
protected Integer index = null;
protected Long times = null;
protected Integer prio = null;
protected Integer period = null;
protected Integer deadline = null;
public ptask_tracepoint(time_trace time, Integer cpu_id, Integer pid, Integer tid, String flag, String state, Integer idx, String tim, Integer prio, Integer peri, Integer dd) {
BigInteger bigInt = new BigInteger(tim);
this.time = time;
this.cpu_id = cpu_id;
this.pid = pid;
this.tid = tid;
this.flag = flag;
this.state = state;
this.index = idx;
if(bigInt.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) this.times = Long.valueOf(tim);
this.prio = prio;
this.period = peri;
this.deadline = dd;
}
public String getFlag() {
return this.flag;
}
public String getState() {
return this.state;
}
public Integer getIndex() {
return this.index;
}
public Long getTimes() {
return this.times;
}
public Integer getPrio() {
return this.prio;
}
public Integer getPeriod() {
return this.period;
}
public Integer getDeadline() {
return this.deadline;
}
public String description() {
return "["+super.time.getHour()+":"+super.time.getMinute()+":"+super.time.getSeconde()+"] (+"+super.time.getDelta()+") cpu id="+super.getCpu_id()+", pid="+super.getPid()+", tid="+super.getTid()+" "+this.getFlag()+" "+this.getState()+" "+this.getIndex()+" "+this.getTimes()+" "+this.getPrio()+" "+this.getPeriod()+" "+this.getDeadline();
}
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public class sched_switch extends kernel_tracepoint {
protected String prev_comm = null;
protected String next_comm = null;
protected Integer prev_tid = null;
protected Integer next_tid = null;
protected Integer prev_prio = null;
protected Integer next_prio = null;
protected Integer prev_state = null;
public sched_switch(time_trace time, Integer cpu_id, Integer pid, Integer tid, String pcomm, String ncomm, Integer ptid, Integer ntid, String pprio, String nprio, Integer ps) {
this.time = time;
this.cpu_id = cpu_id;
this.pid = pid;
this.tid = tid;
this.prev_comm = pcomm;
this.next_comm = ncomm;
this.prev_tid = ptid;
this.next_tid = ntid;
this.prev_prio = Integer.valueOf(pprio);
this.next_prio = Integer.valueOf(nprio);
this.prev_state = ps;
}
public String getPrev_comm() {
return this.prev_comm;
}
public String getNext_comm() {
return this.next_comm;
}
public Integer getPrev_tid() {
return this.prev_tid;
}
public Integer getNext_tid() {
return this.next_tid;
}
public Integer getPrev_prio() {
return this.prev_prio;
}
public Integer getNext_prio() {
return this.next_prio;
}
public Integer getPrev_state() {
return this.prev_state;
}
public String description() {
return "["+super.time.getHour()+":"+super.time.getMinute()+":"+super.time.getSeconde()+"] (+"+super.time.getDelta()+") cpu id="+super.getCpu_id()+ ", pid="+super.getPid()+", tid="+super.getTid()+" "+this.getPrev_comm()+" "+this.getNext_comm()+" "+this.getPrev_tid()+" "+this.getNext_tid()+" "+this.getPrev_prio()+" "+this.getNext_prio()+" "+this.getPrev_state();
}
}
/****************************************************************************
* Class: time_trace() *
* Parameters: the time trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for timing *
****************************************************************************/
package com.event;
public class time_trace {
protected Double hour = null;
protected Double minute = null;
protected Double seconde = null;
protected Double delta = null;
public time_trace(Integer h, Integer m, Integer s, String os, String d) {
this.hour = (double) h;
this.minute = (double) m;
this.seconde = (double) s + Double.valueOf("0."+os);
if(!d.equals("?.?????????")) this.delta = Double.valueOf(d);
}
public void setTime(Double h, Double m, Double s, Double d) {
this.hour = h;
this.minute = m;
this.seconde = s;
this.delta = d;
}
public Double getTime(String in) {
if(in.equals("minute")) return (this.hour*60 + this.minute + this.seconde/60);
else if(in.equals("hour")) return (this.hour + this.minute/60 + this.seconde/60);
else if(in.equals("seconde")) return (this.hour*60 + this.minute*60 + this.seconde);
else return -1.;
}
public Double getDelta() {
return this.delta;
}
public Double getHour() {
return this.hour;
}
public Double getMinute() {
return this.minute;
}
public Double getSeconde() {
return this.seconde;
}
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public abstract class trace {
protected Integer cpu_id = null;
protected Integer pid = null;
protected Integer tid = null;
protected time_trace time = null;
public Integer getCpu_id() {
return this.cpu_id;
}
public Integer getPid() {
return this.pid;
}
public Integer getTid() {
return this.tid;
}
public time_trace getTime() {
return this.time;
}
public abstract String description();
}
/****************************************************************************
* Class: trace() *
* Parameters: all the trace parameters *
* Autor: ael-mess *
* Description: represents the parameters required for tracing *
****************************************************************************/
package com.event;
public abstract class userspace_tracepoint extends trace {
}
/****************************************************************************
* Class: main() *
* Parameters: NA *
* Autor: ael-mess *
* Description: creates services to manage parser, tasks, and printer *
****************************************************************************/
package com;
import com.parser.*;
import com.event.*;
import com.task.*;
import com.printer.*;
import java.io.IOException;
import java.lang.IllegalArgumentException;
public class main {
public static void main(String[] args) throws IOException {
if(args.length == 7) {
parser_service parser = new parser_service(args[6]+"/build/"+args[0]+"_raw.txt");
System.out.println("[\u001B[32mOK\u001B[0m]");
System.out.println("\n> Analysing the data...");
task_service tasks = new task_service(parser.getTraces(), args);
System.out.println("[\u001B[32mOK\u001B[0m]");
System.out.println("\n> Generating the SVG...");
printer_service printer = new printer_service(tasks, args[6]+"/build/"+args[0]+".svg", args);
System.out.println("[\u001B[32mOK\u001B[0m]");
//System.out.println(parser.description());
//System.out.println(tasks.description());
//tasks.check();
}
else throw new IllegalArgumentException("Bad arguments or number of arguments");
}
}
/****************************************************************************
* Class: parser_service() *
* Parameters: trace file name of the trace *
* Autor: ael-mess *
* Description: import traces from file to this java list (of trace objt) *
****************************************************************************/
package com.parser;
import com.parser.java.*;
import com.event.*;
import org.antlr.v4.runtime.*;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.NullPointerException;
import java.lang.OutOfMemoryError;
public class parser_service {
protected List<trace> traces = new ArrayList<>();
protected String file_name = null;
public parser_service(String file_name) throws IOException, OutOfMemoryError {
try {
CharStream in = CharStreams.fromFileName(file_name);
traceLexer lexer = new traceLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
traceParser parser = new traceParser(tokens);
this.traces = parser.start().traces;
System.out.println(""+this.traces.size()+" events saved in the trace");
if(this.traces==null) throw new NullPointerException("Traces List null pointer");
} catch (IOException e) {
throw new FileNotFoundException("Trace file "+file_name+" not found");
} catch (OutOfMemoryError e) {
System.err.println("Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space: failed reallocation (too many events in the trace file)\n at com.parser.parser_service.<init>(parser_service.java:38)\n at com.main.main(main.java:21)");
System.exit(2);
}
}
public List<trace> getTraces() {
return this.traces;
}
public String description() {
String ret = "";
for(trace tr : this.traces) ret += tr.description()+"\n";
return ret;
}
}
lexer grammar traceLexer;
@lexer::header {package com.parser.java;}
EQ : '=';
PLUS : '+';
DOT : '.';
COL : ':';
COM : ',';
LBRA : '[';
RBRA : ']';
LPAR : '(';
RPAR : ')';
LCBRA : '{';
RCBRA : '}';
QUOT : '"';
PTASK_TRACEPOINT : 'ptask_provider:ptask_tracepoint';
SCHED_SWITCH : 'sched_switch';
EXIT_CLONE : 'syscall_exit_clone';
ENTRY_CLONE : 'syscall_entry_clone';
CPU_ID : 'cpu_id';
PID : 'pid';
TID : 'tid';
RET : 'ret';
CLONE_FLAG : 'clone_flags';
NEWSP : 'newsp';
PARENT_TID : 'parent_tid';
CHILD_TID : 'child_tid';
PREV_COMM : 'prev_comm';
PREV_TID : 'prev_tid';
PREV_PRIO : 'prev_prio';
PREV_STATE : 'prev_state';
NEXT_COMM : 'next_comm';
NEXT_TID : 'next_tid';
NEXT_PRIO : 'next_prio';
PTASK_FLAG_F : 'ptask_flag';
PTASK_STATE_F : 'ptask_state';
PTASK_PID : 'ptask_pid';
PTASK_TID : 'ptask_tid';
PTASK_INDEX : 'ptask_index';
PTASK_TIME : 'ptask_time';
PTASK_PRIORITY : 'ptask_priority';
PTASK_PERIOD : 'ptask_period';
PTASK_DEADLINE : 'ptask_deadline';
PTASK_STATE : QUOT('b_wait_period'|'e_wait_period'|'b_wait_activation'|'e_wait_activation'|'creation')QUOT;
PTASK_FLAG : QUOT('DEFERRED'|'NOW')QUOT;
DELTA : ([0-9]'.'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])|'?.?????????';
INT : [0-9]+;
SINT : '-'[0-9]+;
HEX : '0x'[0-9A-F]+;
ID : QUOT[A-Za-z0-9/:.)( _-]+QUOT;
HOSTNAME : [A-Za-z0-9-]+;
WS : [ \t\r\n]+ -> skip;
parser grammar traceParser;
@header {
package com.parser.java;
import com.event.*;
}
options {tokenVocab=traceLexer;}
start returns [ List<trace> traces ] : { $traces = new ArrayList<>(); } (trace { $traces.add($trace.tr); })* EOF;
trace returns [ trace tr ] :
timestamp HOSTNAME ENTRY_CLONE COL LCBRA header RCBRA COM LCBRA context RCBRA COM LCBRA CLONE_FLAG EQ clone_flag=HEX COM NEWSP EQ newsp=HEX COM PARENT_TID EQ ptid=HEX COM CHILD_TID EQ ctid=HEX RCBRA
{ $tr = new clone_entry($timestamp.t,$header.cpu_id,$context.cntx.get(0),$context.cntx.get(1),$clone_flag.text,$newsp.text,$ptid.text,$ctid.text); }
| timestamp HOSTNAME EXIT_CLONE COL LCBRA header RCBRA COM LCBRA context RCBRA COM LCBRA RET EQ ret=INT RCBRA
{ $tr = new clone_exit($timestamp.t,$header.cpu_id,$context.cntx.get(0),$context.cntx.get(1),$ret.int); }
| timestamp HOSTNAME SCHED_SWITCH COL LCBRA header RCBRA COM LCBRA context RCBRA COM LCBRA PREV_COMM EQ prev_comm=comm COM PREV_TID EQ prev_tid=INT COM PREV_PRIO EQ prev_prio=sint COM PREV_STATE EQ prev_state=INT COM NEXT_COMM EQ next_comm=comm COM NEXT_TID EQ next_tid=INT COM NEXT_PRIO EQ next_prio=sint RCBRA
{ $tr = new sched_switch($timestamp.t,$header.cpu_id,$context.cntx.get(0),$context.cntx.get(1),$prev_comm.text,$next_comm.text,$prev_tid.int,$next_tid.int,$prev_prio.text,$next_prio.text,$prev_state.int); }
| timestamp HOSTNAME PTASK_TRACEPOINT COL LCBRA header RCBRA COM LCBRA PTASK_PID EQ pid=INT COM PTASK_TID EQ tid=INT COM PTASK_INDEX EQ ptask_index=INT COM PTASK_FLAG_F EQ ptask_flag=PTASK_FLAG COM PTASK_STATE_F EQ ptask_state=PTASK_STATE COM PTASK_TIME EQ times=INT COM PTASK_PRIORITY EQ ptask_prio=INT COM PTASK_PERIOD EQ ptask_peri=INT COM PTASK_DEADLINE EQ ptask_dead=INT RCBRA
{ $tr = new ptask_tracepoint($timestamp.t,$header.cpu_id,$pid.int,$tid.int,$ptask_flag.text,$ptask_state.text,$ptask_index.int,$times.text,$ptask_prio.int,$ptask_peri.int,$ptask_dead.int); }
;
timestamp returns [ time_trace t ] :
LBRA h=INT COL m=INT COL s=INT DOT os=INT RBRA LPAR PLUS delta=DELTA RPAR
{ $t = new time_trace($h.int,$m.int,$s.int,$os.text,$delta.text); } ;
header returns [ Integer cpu_id ] :
CPU_ID EQ cpuid=INT
{ $cpu_id = $cpuid.int; } ;
context returns [ List<Integer> cntx ] :
PID EQ pid=INT COM TID EQ tid=INT
{ $cntx = new ArrayList<Integer>(2);
$cntx.add(0,$pid.int);
$cntx.add(1,$tid.int); } ;
comm : ID;
sint : INT|SINT;
/****************************************************************************
* Class: form() *
* Parameters: graphics parameters *
* Autor: ael-mess *
* Description: represents basic forms *
****************************************************************************/
package com.printer;
import java.awt.*;
import java.awt.geom.*;
import java.util.Random;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.DOMImplementation;
import org.apache.batik.anim.dom.SVGDOMImplementation;
public class form {
protected Graphics2D graph = null;
protected Shape line = null;
protected Shape rec = null;
protected Element recNS = null;
protected Element lineNS = null;
protected Element textNS1 = null;
protected Element textNS2 = null;
protected Stroke stro = null;
protected String font = null;
public form(Graphics2D graph) {
this.graph = graph;
this.line = new Line2D.Double();
this.rec = new Rectangle2D.Double();
this.stro = new BasicStroke(0.4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{1,0}, 0);
this.graph.setPaint(Color.black);
this.font = "arial-plain-5";
this.setFont();
this.setStroke();
this.graph.setBackground(Color.white);
}
public Shape getRec() {
return this.rec;
}
public void setFont() {
this.graph.setFont(Font.decode(this.font));
}
public void setStroke() {
this.graph.setStroke(stro);
}
public void arrow(String orio, Double x, Double y, Double size) {
if(orio.equals("up")) {
((Line2D.Double)this.line).setLine(x, y, x-size, y+size);
this.graph.draw(this.line);
((Line2D.Double)this.line).setLine(x, y, x+size, y+size);
this.graph.draw(this.line);
}
else if(orio.equals("right")) {
((Line2D.Double)this.line).setLine(x, y, x-size, y-size);
this.graph.draw(this.line);
((Line2D.Double)this.line).setLine(x, y, x-size, y+size);
this.graph.draw(this.line);
}
else if(orio.equals("down")) {
((Line2D.Double)this.line).setLine(x, y, x-size, y-size);
this.graph.draw(this.line);
((Line2D.Double)this.line).setLine(x, y, x+size, y-size);
this.graph.draw(this.line);
}
}
public void wakeLine(Double x, Double yh, Double yl) {
Stroke wakeS = new BasicStroke(0.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{2,2}, 0);
this.graph.setStroke(wakeS);
this.graph.setPaint(Color.blue);
((Line2D.Double)this.line).setLine(x, yh, x, yl);
this.graph.draw(this.line);
this.graph.setStroke(this.stro);
this.arrow("up", x, yl, 1.0);
this.graph.setPaint(Color.black);
wakeS = null;
}
public void deadLine(Double x, Double yh, Double yl) {
Stroke deadS = new BasicStroke(0.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[]{3,3}, 0);
this.graph.setStroke(deadS);
this.graph.setPaint(Color.red);
((Line2D.Double)this.line).setLine(x, yh, x, yl);
this.graph.draw(this.line);
this.graph.setStroke(this.stro);
this.arrow("down", x, yh, 1.0);
this.graph.setPaint(Color.black);
deadS = null;
}
public void axis(Double width, Double height, Double scale) {
((Line2D.Double)this.line).setLine(0.0, height, width, height);
this.graph.draw(this.line);
((Line2D.Double)this.line).setLine(0.0, height, 0.0, 0.0);
this.graph.draw(this.line);
this.arrow("right", width, height, 2.0);
this.arrow("up", 0.0, 0.0, 2.0);
for(double h=0.0; h*scale<width; h+=1.0) {
((Line2D.Double)this.line).setLine(h*scale, height, h*scale, height+2);
this.graph.draw(this.line);
}
for(double h=0.0; h*scale<width; h+=0.20) {
((Line2D.Double)this.line).setLine(h*scale, height, h*scale, height+1);
this.graph.draw(this.line);
}
}
public void job(Double x, Double y, Double width, Double height, Color col) {
((Rectangle2D.Double)this.rec).setRect(x, y, width, height);
this.graph.setPaint(col);
this.graph.fill(rec);
this.graph.setPaint(Color.black);
this.graph.draw(rec);
}
public void line(Double y, Double width) {
Stroke st = new BasicStroke(0.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{4,4}, 0);
this.graph.setStroke(st);
this.graph.setPaint(Color.black);
((Line2D.Double)this.line).setLine(0.0, y, width, y);
this.graph.draw(this.line);
this.graph.setStroke(this.stro);
}
public void lineNS(Element root, SVGDocument doc, Double y, Double width) {
this.lineNS = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "line");
this.lineNS.setAttributeNS(null, "transform", "translate(75,25)");
this.lineNS.setAttributeNS(null, "x1", "0");
this.lineNS.setAttributeNS(null, "y1", Double.toString(y));
this.lineNS.setAttributeNS(null, "x2", Double.toString(width));
this.lineNS.setAttributeNS(null, "y2", Double.toString(y));
this.lineNS.setAttributeNS(null, "stroke", "black");
this.lineNS.setAttributeNS(null, "stroke-dasharray", "4");
this.lineNS.setAttributeNS(null, "stroke-width", "0.2px");
root.appendChild(this.lineNS);
}
public void jobNS(Element root, SVGDocument doc, Double x, Double y, Double width, Double height, String col, String text1, String text2) {
Random rand = new Random();
int id = rand.nextInt(Integer.MAX_VALUE - 1) + 0;
this.recNS = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect");
this.recNS.setAttributeNS(null, "id", ""+id);
this.recNS.setAttributeNS(null, "transform", "translate(75,25)");
this.recNS.setAttributeNS(null, "x", Double.toString(x));
this.recNS.setAttributeNS(null, "y", Double.toString(y));
this.recNS.setAttributeNS(null, "width", Double.toString(width));
this.recNS.setAttributeNS(null, "height", Double.toString(height));
this.recNS.setAttributeNS(null, "fill", col);
this.recNS.setAttributeNS(null, "stroke", "black");
this.recNS.setAttributeNS(null, "stroke-width", "0.5px");
root.appendChild(this.recNS);
this.jobInfoNS(root, doc, x, y, width, height, id, text1, text2);
rand = null;
}
private void jobInfoNS(Element root, SVGDocument doc, Double x, Double y, Double width, Double height, Integer id, String text1, String text2) {
this.recNS = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect");
this.recNS.setAttributeNS(null, "transform", "translate(75,25)");
this.recNS.setAttributeNS(null, "x", Double.toString(x));
this.recNS.setAttributeNS(null, "y", Double.toString(y));
this.recNS.setAttributeNS(null, "width", Double.toString(width));
this.recNS.setAttributeNS(null, "height", Double.toString(height));
this.recNS.setAttributeNS(null, "fill", "white");
this.recNS.setAttributeNS(null, "stroke", "black");
this.recNS.setAttributeNS(null, "stroke-width", "0.5px");
this.recNS.setAttributeNS(null, "visibility", "hidden");
root.appendChild(this.recNS);
Element back = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect");
//back.setAttributeNS(null, "transform", "translate(50,25)");
back.setAttributeNS(null, "x", Double.toString(x));
back.setAttributeNS(null, "y", Double.toString(y));
back.setAttributeNS(null, "width", "150");
back.setAttributeNS(null, "height", "12");
back.setAttributeNS(null, "fill", "white");
back.setAttributeNS(null, "stroke", "black");
back.setAttributeNS(null, "transform", "translate(0,13)");
back.setAttributeNS(null, "stroke-width", "0.5px");
back.setAttributeNS(null, "visibility", "hidden");
root.appendChild(back);
this.textNS1 = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "text");
this.textNS1.setAttributeNS(null, "transform", "translate(75,25)");
this.textNS1.setAttributeNS(null, "x", Double.toString(x));
this.textNS1.setAttributeNS(null, "y", Double.toString(y-7.0));
this.textNS1.setAttributeNS(null, "stroke", "none");
this.textNS1.setAttributeNS(null, "font-size", "5px");
this.textNS1.setAttributeNS(null, "text-anchor", "middle");
this.textNS1.setAttributeNS(null, "font-family", "arial");
this.textNS1.setAttributeNS(null, "visibility", "hidden");
this.textNS1.setTextContent(text1);
root.appendChild(this.textNS1);
this.textNS2 = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "text");
this.textNS2.setAttributeNS(null, "transform", "translate(75,25)");
this.textNS2.setAttributeNS(null, "x", Double.toString(x));
this.textNS2.setAttributeNS(null, "y", Double.toString(y-2.0));
this.textNS2.setAttributeNS(null, "stroke", "none");
this.textNS2.setAttributeNS(null, "font-size", "5px");
this.textNS2.setAttributeNS(null, "text-anchor", "middle");
this.textNS2.setAttributeNS(null, "font-family", "arial");
this.textNS2.setAttributeNS(null, "visibility", "hidden");
this.textNS2.setTextContent(text2);
root.appendChild(this.textNS2);
Element set = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "set");
set.setAttributeNS(null, "attributeName", "visibility");
set.setAttributeNS(null, "from", "hidden");
set.setAttributeNS(null, "to", "visible");
set.setAttributeNS(null, "begin", ""+id+".mouseover");
set.setAttributeNS(null, "end", ""+id+".mouseout");
this.recNS.appendChild(set);
set = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "set");
set.setAttributeNS(null, "attributeName", "visibility");
set.setAttributeNS(null, "from", "hidden");
set.setAttributeNS(null, "to", "visible");
set.setAttributeNS(null, "begin", ""+id+".mouseover");
set.setAttributeNS(null, "end", ""+id+".mouseout");
back.appendChild(set);
set = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "set");
set.setAttributeNS(null, "attributeName", "visibility");
set.setAttributeNS(null, "from", "hidden");
set.setAttributeNS(null, "to", "visible");
set.setAttributeNS(null, "begin", ""+id+".mouseover");
set.setAttributeNS(null, "end", ""+id+".mouseout");
this.textNS1.appendChild(set);
set = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "set");
set.setAttributeNS(null, "attributeName", "visibility");
set.setAttributeNS(null, "from", "hidden");
set.setAttributeNS(null, "to", "visible");
set.setAttributeNS(null, "begin", ""+id+".mouseover");
set.setAttributeNS(null, "end", ""+id+".mouseout");
this.textNS2.appendChild(set);
set = null;
back = null;
}
}
/****************************************************************************
* Class: printer_service() *
* Parameters: task service class, svg generator *
* Autor: ael-mess *
* Description: generates the svg file and draw the actions *
****************************************************************************/
package com.printer;
import com.task.*;
import java.io.IOException;
import java.lang.OutOfMemoryError;
import java.util.List;
import java.util.ArrayList;
import java.awt.Color;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.Element;
public class printer_service {
protected svggen svg = null;
protected task_service tasks = null;
protected Element root = null;
protected Integer curH = 0;
public printer_service(task_service t, String out, String[] args) throws IOException, NullPointerException, OutOfMemoryError {
try {
this.tasks = t;
this.svg = new svggen(t, out);
System.out.println("SVG file generated in build/");
this.Externset(Double.valueOf(args[2]), Double.valueOf(args[3]), Boolean.valueOf(args[4]), Boolean.valueOf(args[5]));
this.svg.setCanvas();
System.out.println("Canvas set");
this.root = this.svg.getDoc().getDocumentElement();
this.svg.getGraph().getRoot(root);
if(this.svg.isOsactive()) this.draw_os();
else this.curH++;
this.draw_main();
this.draw_tasks();
System.out.println("Threads printed in build/"+this.svg.getApp().getName()+".svg");
svg.streamOut(root);
System.out.println("SVG file savedin build/"+this.svg.getApp().getName()+".svg");
} catch(NullPointerException e) {
throw new NullPointerException("Null pointer parameter");
} catch (OutOfMemoryError e) {
System.err.println("Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space: failed reallocation (too many events in the trace file)\n at com.printer.printer_service.<init>(printer_service.java:46)\n at com.main.main(main.java:30)");
System.exit(2);
}
}
// for external informations
public void Externset(Double scale, Double task_h, Boolean osactive, Boolean cpu) throws NullPointerException {
this.svg.setScale(scale);
this.svg.setTask_hei(task_h);
this.svg.setOsactive(osactive);
this.svg.setPercpu(cpu);
}
// drawing tasks jobs calling tooltips (param: h) height 6/2 smaller
public void draw_tasks() throws NullPointerException {
double w = 0.0;
double x = 0.0;
double y = this.svg.getTask_hei();
int job = 0;
boolean started = false;
boolean switched = false;
int os_preem = 0;
String text1 = "", text2 = "";
for(Integer id : this.svg.getCpu()) {
for(task t : this.svg.getTasks()) if(t.getCpu_id().equals(id)) {
job = 0;
for(t_event t_e : t.getEvents()) {
switch(t_e.getType()) {
case START :
if(!started) {
job++;
started = true;
x = (t_e.getValue() - this.svg.getStart())*this.svg.getScale();
text1 = "("+job+") task"+t.getName()+" PID:"+t.getId()+" P:"+t.getPeriod()/1000.0+"ms D:"+t.getDeadline()/1000.0+"ms CPU:"+t.getCpu_id();
text2 = "from "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
os_preem = 0;
}
break;
case FINISH :
if(started && !switched) {
started = false;
w = (t_e.getValue() - this.svg.getStart())*this.svg.getScale() - x;
text1 += " ("+os_preem+" os preem)";
text2 += " to "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
this.svg.getForm().jobNS(this.root, this.svg.getDoc(), x, this.curH*y+3.0, w, y-6.0, this.getColor(t_e, t), text1, text2);
}
break;
case SWITCH_OUT :
if(started && !switched) {
if(this.svg.isOsactive() || this.tasks.getTids().contains(t_e.getNp_tid())) {
switched = true;
w = (t_e.getValue() - this.svg.getStart())*this.svg.getScale() - x;
text1 += " ("+os_preem+" os preem)";
text2 += " to "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
this.svg.getForm().jobNS(this.root, this.svg.getDoc(), x, this.curH*y+3.0, w, y-6.0, this.getColor(t_e, t), text1, text2);
}
else os_preem++;
}
break;
case SWITCH_IN :
if(started && switched) {
if(this.svg.isOsactive() || this.tasks.getTids().contains(t_e.getNp_tid())) {
switched = false;
x = (t_e.getValue() - this.svg.getStart())*this.svg.getScale();
text1 = "("+job+") task"+t.getName()+" PID:"+t.getId()+" P:"+t.getPeriod()/1000.0+"ms D:"+t.getDeadline()/1000.0+"ms CPU:"+t.getCpu_id();
text2 = "from "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
os_preem = 0;
}
}
break;
}
}
if(!this.svg.isPercpu()) this.curH++;
}
if(this.svg.isPercpu()) this.curH++;
}
}
private String getColor(t_event evt, task t) {
if(this.svg.isPercpu() || t.getStart()==null) return t.getColorS();
else if(evt.isPassed()!=null && !evt.isPassed()) return "red";
else return "green";
}
// drawing main thread (param: h)
public void draw_main() throws NullPointerException {
double w = 0.0;
double x = 0.0;
double y = this.svg.getTask_hei();
boolean started = false;
String text1 = "", text2 = "";
for(t_event t_e : this.svg.getApp().getEvents()) {
text1 = ""+this.svg.getApp().getName()+" PID:"+this.svg.getApp().getId()+" CPU:"+this.svg.getApp().getCpu_id();
switch(t_e.getType()) {
case SWITCH_OUT :
if(started) {
text2 += " to "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
started = false;
w = (t_e.getValue() - this.svg.getStart())*this.svg.getScale() - x;
this.svg.getForm().jobNS(root, this.svg.getDoc(), x, this.curH*y, w, y, "blue", text1, text2);
}
break;
case SWITCH_IN :
if(!started) {
text2 = "from "+((t_e.getValue()-this.svg.getStart())*1000.0)+"ms";
started = true;
x = (t_e.getValue() - this.svg.getStart())*this.svg.getScale();
}
break;
}
}
this.curH++;
}
// drawing os activity (param: h)
public void draw_os() throws NullPointerException {
double w = 0.0;
double x = 0.0;
double y = this.svg.getTask_hei();
boolean started = false;
String text1 = "", text2 = "";
this.curH = 0;
for(app proc : this.svg.getOs()) {
for(t_event t_e : proc.getEvents()) {
switch(t_e.getType()) {
case SWITCH_OUT :
if(started) {
text2 = "last: "+t_e.getNp_name()+" TID:"+t_e.getNp_tid();
started = false;
w = (t_e.getValue() - this.svg.getStart())*this.svg.getScale() - x;
this.svg.getForm().jobNS(root, this.svg.getDoc(), x, this.curH*y, w, y, "blue", text1, text2);
}
break;
case SWITCH_IN :
if(!started) {
text1 = "first: "+t_e.getNp_name()+" TID:"+t_e.getNp_tid();
started = true;
x = (t_e.getValue() - this.svg.getStart())*this.svg.getScale();
}
break;
}
}
this.curH++;
}
}
}
/****************************************************************************
* Class: svggen() *
* Parameters: svg generation parameters *
* Autor: ael-mess *
* Description: creates svg document and sets the canvas and the infos *
****************************************************************************/
package com.printer;
import com.task.*;
import java.io.Writer;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.NullPointerException;
import java.util.ArrayList;
import java.util.List;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.Font;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.anim.dom.SVGDOMImplementation;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
public class svggen {
protected SVGDocument doc = null;
protected SVGGeneratorContext ctx = null;
protected SVGGraphics2D svgGenerator = null;
protected form f = null;
protected Double start = 0.0;
protected Double height = 0.0;
protected Double width = 0.0;
protected Double scale = 1000.0;
protected Double task_hei = 20.0;
protected List<task> tasks = null;
protected List<app> os = null;
protected List<Integer> cpu = null;
protected Writer out = null;
protected app main = null;
protected Boolean osactive = true;
protected Boolean percpu = false;
protected Integer curH = 0;
public svggen(task_service serv, String out) throws IOException, NullPointerException {
try {
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;//"http://www.w3.org/2000/svg";
this.doc = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);
this.ctx = SVGGeneratorContext.createDefault(this.doc);
ctx.setComment("SVG created for ptask apps");
this.svgGenerator = new SVGGraphics2D(ctx, false);
this.f = new form((Graphics2D)this.svgGenerator);
this.tasks = serv.getTasks();
this.main = serv.getMain_task();
this.os = serv.getOs_task();
this.cpu = serv.getCpu();
if(this.main.getStart()==null) this.start = this.os.get(0).getStart();
else this.start = this.main.getStart();
this.width = (serv.getEnd() - this.start);
this.out = new FileWriter(out);
} catch(IOException e) {
throw new FileNotFoundException("SVG file "+out+" can not be created");
} catch(NullPointerException e) {
throw new NullPointerException("Null pointer parameter");
}
}
public SVGDocument getDoc() {
return this.doc;
}
public SVGGraphics2D getGraph() {
return this.svgGenerator;
}
public Double getStart() {
return this.start;
}
public Double getTask_hei() {
return this.task_hei;
}
public Double getHeight() {
return this.height;
}
public Double getWidth() {
return this.width;
}
public Double getScale() {
return this.scale;
}
public List<task> getTasks() {
return this.tasks;
}
public form getForm() {
return this.f;
}
public List<app> getOs() {
return this.os;
}
public app getApp() {
return this.main;
}
public Integer getCurH() {
return this.curH;
}
public List<Integer> getCpu() {
return this.cpu;
}
public void setHeight() {
int nbt = 0, oss = 0;
if(this.percpu) nbt = this.cpu.size();
else nbt = tasks.size();
if(this.osactive) oss = this.os.size();
else oss = 1;
this.height = (nbt + 1 + oss)* this.task_hei;
}
public void setWidth() {
this.width = this.width * this.scale;
}
public Boolean isOsactive() {
return this.osactive;
}
public Boolean isPercpu() {
return this.percpu;
}
public void setScale(Double scale) {
this.scale = scale;
}
public void setTask_hei(Double th) {
this.task_hei = th;
}
public void setOsactive(Boolean act) {
this.osactive = act;
}
public void setPercpu(Boolean act) {
this.percpu = act;
}
// setting the canvas with 50/2 height and 150/2 width plus
public void setCanvas() throws NullPointerException {
this.setHeight();
this.setWidth();
this.svgGenerator.setSVGCanvasSize(new Dimension(this.width.intValue()+1+150, this.height.intValue()+1+50));
this.svgGenerator.translate(0, 25);
this.setText();
this.svgGenerator.translate(75, 0);
this.setTInfo();
}
// setting info text for canvas (param: h, dist from x=0)
private void setText() throws NullPointerException {
this.curH = 0;
if(this.osactive) for(app proc: this.os) {
this.svgGenerator.drawString("OS CPU:"+proc.getId(), 5.0f, (float)(this.task_hei*(this.curH+0.5)));
this.curH++;
}
else this.curH++;
this.svgGenerator.drawString("Main task "+this.main.getName()+" PID:"+this.main.getId(), 3.0f, (float)(this.task_hei*(this.curH+0.5)));
this.curH++;
if(this.percpu) for(Integer id : this.cpu) {
this.svgGenerator.drawString("CPU"+id, 3.0f, (float)(this.task_hei*(this.curH+0.5)));
this.curH++;
}
else for(Integer id : this.cpu) for(task t : this.tasks) if(t.getCpu_id().equals(id)) {
this.svgGenerator.drawString("Task"+t.getName()+" TID:"+t.getId()+": CPU:"+t.getCpu_id(), 3.0f, (float)(this.task_hei*(this.curH+0.5)));
this.svgGenerator.drawString("(P:"+t.getPeriod()/1000.0+"ms D:"+t.getDeadline()/1000.0+"ms)", 3.0f, (float)(this.task_hei*(this.curH+0.75)));
this.curH++;
}
}
// setting period and deadline infos (param: h)
// using the last period for axis info (1 for 2 period)
private void setTInfo() throws NullPointerException {
this.curH = 0;
int period = 0, deadline = 0;
Double start = null;
if(!this.percpu) {
this.curH = 1 + os.size();
for(Integer id : this.cpu) {
this.f.line(this.curH*this.task_hei, this.width);
for(task t : this.tasks) if(t.getCpu_id().equals(id)) {
period = t.getPeriod();
deadline = t.getDeadline();
start = t.getStart();
if(period != 0 && deadline != 0 && start!=null) for(int nb_period=0; ((start-this.start+((nb_period/1000000.0)*period))*this.scale)<this.width; nb_period++) {
this.f.wakeLine((start - this.start + (nb_period/1000000.0)*period)*this.scale, (1+this.curH)*this.task_hei, this.curH*this.task_hei);
this.f.deadLine((start - this.start + ((nb_period+1)/1000000.0)*deadline)*this.scale, (1+this.curH)*this.task_hei, this.curH*this.task_hei);
}
this.curH++;
}
}
}
else this.curH++;
period = this.tasks.get(0).getPeriod();
this.f.axis(this.width, this.height, period*this.scale/1000000.0);
this.svgGenerator.setFont(Font.decode("arial-plain-3"));
for(int nb_period=0; ((nb_period/1000000.0)*period*this.scale*2)<this.width; nb_period+=1)
this.svgGenerator.drawString(""+String.format("%.3f", ((nb_period/1000.0)*period*2))+"ms", (float)((nb_period/1000000.0)*period*this.scale*2.0f), (float)(this.height+5.0f));
this.f.setFont();
start = null;
}
public void streamOut(Element root) throws NullPointerException, IOException {
try {
this.svgGenerator.stream(root, this.out);
this.out.close();
} catch(IOException e) {
throw new FileNotFoundException("SVG file "+this.out+" can not be closed");
}
}
}
package com.task;
public enum Types { START, FINISH, SWITCH_IN, SWITCH_OUT; }
/****************************************************************************
* Class: app() *
* Parameters: all the main() thread parameters (and os) *
* Autor: ael-mess *
* Description: represents the parameters required for the main thread *
****************************************************************************/
package com.task;
import java.awt.Color;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
public class app {
protected Integer id = null;
protected String name = null;
protected Color color = null;
protected Double start = null;
protected Integer cpu_id = null;
protected List<t_event> events = null;
public Integer getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Color getColor() {
return this.color;
}
public Double getStart() {
return this.start;
}
public List<t_event> getEvents() {
return this.events;
}
public Integer getCpu_id() {
return this.cpu_id;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setColor() {
Random randomGenerator = new Random();
int r = randomGenerator.nextInt(256);
int g = randomGenerator.nextInt(256);
int b = randomGenerator.nextInt(256);
this.color = (new Color(r,g,b)).darker();
}
public void setStart(Double start) {
this.start = start;
}
public void setEvents(List<t_event> events) {
this.events = events;
}
public void setCpu_id(Integer id) {
this.cpu_id = id;
}
public String description() {
String ret = "id: "+this.getId()+" name: "+this.getName()+" ("+this.getColor().toString()+") start="+this.getStart()+"\n";
ret += "[ ";
for(t_event ev : this.events) ret += ev.description()+", ";
ret += "]";
return ret;
}
// checking if the events are correctly imported (used in task_service)
public void check_events() {
int job = 0;
int preep = 0;
int preep_e = 0;
String comm = "";
Iterator<t_event> it = this.getEvents().iterator();
t_event evt = it.next();
while(it.hasNext()) {
evt = it.next();
if(this.getEvents().get(this.getEvents().indexOf(evt)-1).getType().equals(evt.getType())) {System.err.println(" bad time event "+this.getEvents().indexOf(evt)+" for next task"); System.err.println(" evt-1"+this.getEvents().get(this.getEvents().indexOf(evt)-1).getType()+" evt"+this.getEvents().get(this.getEvents().indexOf(evt)).getType());}
if(evt.getType().equals(Types.SWITCH_IN)) preep++;
else if(evt.getType().equals(Types.SWITCH_OUT)) preep_e++;
}
System.err.println(" pid: "+this.getId()+" idx: "+this.getName()+" cpu="+this.getCpu_id()+" start="+this.getStart()+" preemption="+preep_e+"/"+preep);
it = null;
}
}
/****************************************************************************
* Class: t_event() *
* Parameters: the time task parameters *
* Autor: ael-mess *
* Description: represents the parameters required for timing *
****************************************************************************/
package com.task;
public class t_event {
protected Double value = null;
protected Types type = null;
protected Integer np_tid = null;
protected String np_name = null;
protected Boolean pass = null;
//differents construcors for all Types of t_events
public t_event(Types type, Double value) {
this.type = type;
this.value = value;
}
public t_event(Types type, Double value, Boolean pass) {
this.type = type;
this.value = value;
this.pass = pass;
}
public t_event(Types type, Double value, Integer tid) {
this.type = type;
this.value = value;
this.np_tid = tid;
}
public t_event(Types type, Double value, Integer tid, String name) {
this.type = type;
this.value = value;
this.np_tid = tid;
this.np_name = name;
}
public Double getValue() {
return this.value;
}
public Types getType() {
return this.type;
}
public Integer getNp_tid() {
return this.np_tid;
}
public String getNp_name() {
return this.np_name;
}
public Boolean isPassed() {
return this.pass;
}
public String description() {
return ""+this.getType().toString()+":"+this.getValue()+":"+this.getNp_tid()+":"+this.getNp_name()+":"+this.isPassed();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment