Skip to content

Commit

Permalink
Added Jobs-stats and, Frame-details windows, job names,classes, conta…
Browse files Browse the repository at this point in the history
…ined jobs and so forth.
  • Loading branch information
jmpenn committed Jan 23, 2025
1 parent 590c3dd commit 8533029
Show file tree
Hide file tree
Showing 17 changed files with 810 additions and 153 deletions.
55 changes: 52 additions & 3 deletions trick_source/java/src/main/java/trick/jobperf/FrameRecord.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package trick.jobperf;
import java.util.*;

/**
* Class CompareByDuration compares two JobExecutionEvent's by their duration.
*/
class CompareByDuration implements Comparator<JobExecutionEvent> {
public int compare(JobExecutionEvent a, JobExecutionEvent b) {
Double dur_a = a.stop - a.start;
Double dur_b = b.stop - b.start;
if ( dur_a > dur_b) return -1;
if ( dur_a < dur_b) return 1;
return 0;
}
}

/**
* Class CompareByDuration compares two JobExecutionEvent's by their start time.
*/
class CompareByStartTime implements Comparator<JobExecutionEvent> {
public int compare(JobExecutionEvent a, JobExecutionEvent b) {
if ( a.start < b.start) return -1;
if ( a.start > a.start) return 1;
return 0;
}
}

/**
* Class FrameRecord represents the set of jobs that have been executed during a
* frame.
Expand All @@ -14,14 +39,38 @@ public class FrameRecord {
public FrameRecord() {
start = 0.0;
stop = 0.0;
jobEvents = new ArrayList<JobExecutionEvent>()

;
jobEvents = new ArrayList<JobExecutionEvent>();
}

/**
* @return the stop time minus the start time.
*/
public double getDuration() {
return stop - start;
}

public void SortByJobEventDuration() {
Collections.sort( jobEvents, new CompareByDuration());
}

public void SortByStartTime() {
Collections.sort( jobEvents, new CompareByStartTime());
}

/**
* For each jobEvent in the frame, record the number of times
* its start time is contained within
* another jobs stop/stop range.
*/
public void CalculateJobContainment() {
SortByJobEventDuration();
int N = jobEvents.size();
for (int i = 0 ; i < (N-1); i++) {
for (int j = i+1 ; j < N; j++) {
if ( jobEvents.get(i).contains( jobEvents.get(j) )) {
jobEvents.get(j).contained ++ ;
}
}
}
}
}
92 changes: 92 additions & 0 deletions trick_source/java/src/main/java/trick/jobperf/FrameViewCanvas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package trick.jobperf;

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

public class FrameViewCanvas extends JPanel {
private FrameRecord frame;
private TraceViewCanvas tvc;
private Font headingsFont;
private Font dataFont;

public FrameViewCanvas( TraceViewCanvas tvc, FrameRecord frame ) {
this.tvc = tvc;
this.frame = frame;
dataFont = new Font("Arial", Font.PLAIN, 18);
headingsFont = new Font("Arial", Font.BOLD, 18);

setPreferredSize(new Dimension(800, neededPanelHeight()));
}

private void doDrawing(Graphics g) {
Graphics2D g2d = (Graphics2D) g;

RenderingHints rh = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);

// Panel Background Color Fill
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, getWidth(), getHeight());

// TITLE
g2d.setFont(headingsFont);
g2d.setPaint( Color.RED );
g2d.drawString("Frame Details", 100, 50);

// Column Headings
g2d.setFont(headingsFont);
g2d.setPaint( Color.BLUE );
g2d.drawString("Job-ID", 100, 80);
g2d.drawString("Job-Class", 180, 80);
g2d.drawString("Start-Time", 420, 80);
g2d.drawString("Stop-Time", 520, 80);
g2d.drawString("Duration", 620, 80);
g2d.drawString("Job-Name", 740, 80);

frame.SortByStartTime();

// For each job in the frame.
int jobY = 100;
for (JobExecutionEvent jobExec : frame.jobEvents) {
g2d.setPaint( tvc.idToColorMap.getColor( jobExec.id ) );
g2d.fillRect(50, jobY, 20, 20);
g2d.setPaint( Color.BLACK );
jobY += 20;
JobSpecification jobSpec = tvc.jobSpecificationMap.getJobSpecification(jobExec.id);
double duration = jobExec.stop - jobExec.start;

g2d.setFont(dataFont);
g2d.drawString(jobExec.id, 100, jobY);
g2d.drawString(jobSpec.jobClass, 180, jobY);
g2d.drawString( String.format("%12.6f", jobExec.start), 420, jobY);
g2d.drawString( String.format("%12.6f", jobExec.stop), 520, jobY);
g2d.drawString( String.format("%12.6f", duration), 620, jobY);
g2d.drawString(jobSpec.name, 740, jobY);
}
frame.SortByJobEventDuration();
}

/**
* Calculate the height of the FrameViewCanvas (JPanel) needed to render the
* jobs in the frame.
*/
private int neededPanelHeight() {
return 20 * frame.jobEvents.size() + 100;
}

/**
* This function paints the FrameViewCanvas (i.e, JPanel) when required.
*/
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}

}
31 changes: 31 additions & 0 deletions trick_source/java/src/main/java/trick/jobperf/FrameViewWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package trick.jobperf;

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

public class FrameViewWindow extends JFrame {
public FrameViewWindow( TraceViewCanvas tvc, FrameRecord frame, int frameNumber ) {

FrameViewCanvas frameViewCanvas = new FrameViewCanvas(tvc, frame);

JScrollPane scrollPane = new JScrollPane( frameViewCanvas );
scrollPane.getVerticalScrollBar().setUnitIncrement( 20 );

JPanel scrollingFrameViewCanvas = new JPanel();
scrollingFrameViewCanvas.add(scrollPane);
scrollingFrameViewCanvas.setLayout(new BoxLayout(scrollingFrameViewCanvas, BoxLayout.X_AXIS));

setTitle("Frame " + frameNumber);
setPreferredSize(new Dimension(1200, 400));
add(scrollingFrameViewCanvas);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setFocusable(true);
setVisible(true);

frameViewCanvas.repaint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javax.swing.event.*;
import java.net.URL;


/**
* Class JobExecutionEvent represents one execution/run of a Trick job.
* <id> identifies the job. <start> and <stop> specify the
Expand All @@ -25,6 +24,7 @@ class JobExecutionEvent {
public boolean isTOF;
public double start;
public double stop;
public int contained;

/**
* @param identifier identifies the relavant Trick job.
Expand All @@ -33,13 +33,27 @@ class JobExecutionEvent {
* @param start_time the start time (seconds) of the identified job.
* @param stop_time the stop time (seconds) of the identified job.
*/
public JobExecutionEvent(String identifier, boolean isTopOfFrame, boolean isEndOfFrame, double start_time, double stop_time) {
id = identifier;
isEOF = isEndOfFrame;
isTOF = isTopOfFrame;
start = start_time;
stop = stop_time;
public JobExecutionEvent(String id, boolean isTOF, boolean isEOF, double start, double stop) {
this.id = id;
this.isEOF = isEOF;
this.isTOF = isTOF;
this.start = start;
this.stop = stop;
contained = 1;
}

/**
* Determine whether a job's start time is contained
* within another jobs stop/stop range.
*/
public boolean contains( JobExecutionEvent other ) {
if ((other.start >= this.start) &&
(other.start <= this.stop)) {
return true;
}
return false;
}

/**
* Create a String representation of an object of this class.
*/
Expand Down
58 changes: 45 additions & 13 deletions trick_source/java/src/main/java/trick/jobperf/JobPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
import java.util.*;
import javax.swing.*;

/**
* Capabilites That Need To Be Added
* - a way to filter the data to be within a user specified sub time period
* within the data set.
*/

import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Class JobPerf is an application that renders time-line data from a Trick based
simulation. It also generates run-time statistics reports for the simulation
Expand All @@ -29,7 +25,7 @@ public JobPerf( String[] args ) {
boolean interactive = true;
boolean printReport = false;
JobStats.SortCriterion sortOrder = JobStats.SortCriterion.MEAN;
String fileName = "in.csv";
String timeLineFileName = "in.csv";

int ii = 0;
while (ii < args.length) {
Expand Down Expand Up @@ -68,24 +64,58 @@ public JobPerf( String[] args ) {
sortOrder = JobStats.SortCriterion.MIN;
} break;
default : {
fileName = args[ii];
timeLineFileName = args[ii];
} break;
} //switch
++ii;
} // while

jobExecEvtList = getJobExecutionEventList(fileName);
jobStats = new JobStats(jobExecEvtList);
// All files shall be in the same directory as the timeline file.
String filesDir = Paths.get(timeLineFileName).toAbsolutePath().getParent().toString();
System.out.println( "\n\nFilesDir = " + filesDir + "\n\n");


// Generate the JobSpecificationMap from information extracted from the S_job_execution
// file, that should be in the same directory as the time-line file.
File s_job_execution_file = new File( filesDir + "/S_job_execution" );
JobSpecificationMap jobSpecificationMap = null;
try {
jobSpecificationMap = new JobSpecificationMap( s_job_execution_file );
} catch ( java.io.FileNotFoundException e ) {
System.out.println("File \"" + s_job_execution_file.toString() + "\" not found.\n");
System.exit(0);
} catch ( java.io.IOException e ) {
System.out.println("IO Exception while attempting to read " + s_job_execution_file.toString() + ".\n");
System.exit(0);
}

// Read Color Map
KeyedColorMap idToColorMap = null;
File colorMapFile = null;
try {
colorMapFile = new File(filesDir + "/IdToColors.txt");
idToColorMap = new KeyedColorMap( colorMapFile.toString());
if ( colorMapFile.exists()) {
idToColorMap.readFile();
}
} catch ( java.io.IOException e ) {
System.out.println("IO Exception while attempting to read " + colorMapFile.toString() + ".\n");
System.exit(0);
}

jobExecEvtList = getJobExecutionEventList(timeLineFileName);

if (printReport) {
jobStats = new JobStats(jobExecEvtList);
if (sortOrder == JobStats.SortCriterion.ID ) jobStats.SortByID();
if (sortOrder == JobStats.SortCriterion.MEAN ) jobStats.SortByMeanValue();
if (sortOrder == JobStats.SortCriterion.STDDEV ) jobStats.SortByStdDev();
if (sortOrder == JobStats.SortCriterion.MAX ) jobStats.SortByMaxValue();
if (sortOrder == JobStats.SortCriterion.MIN ) jobStats.SortByMinValue();
jobStats.write();
jobStats.write( jobSpecificationMap);
}
if (interactive) {
traceViewWindow = new TraceViewWindow(jobExecEvtList);
traceViewWindow = new TraceViewWindow(jobExecEvtList, idToColorMap, jobSpecificationMap);
}
}

Expand Down Expand Up @@ -132,7 +162,9 @@ private ArrayList<JobExecutionEvent> getJobExecutionEventList( String fileName )
line = in.readLine();
while( (line = in.readLine()) !=null) {
field = line.split(",");
String id = field[0];
// Need to strip trailing 0's from the id to make the ID's in
// 1) timeline file and 2) the S_job_execution file consistent.
String id = field[0].replaceAll("0*$","");
boolean isTOF = false;
if (Integer.parseInt(field[1]) == 1) isTOF = true;
boolean isEOF = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package trick.jobperf;

import java.awt.*;
import java.io.*;
import java.util.*;


/**
* Class JobSpecification represents ...
*/
class JobSpecification {
public String name;
public String jobClass;
public int phase;

/**
* @param name identifies the relevant Trick job.
* @param jobClass the Trick job class.
* @param phase the Trick phase number of the Trick job.
*/
public JobSpecification(String name, String jobClass, int phase) {
this.name = name;
this.jobClass = jobClass;
this.phase = phase;
}
/**
* Create a String representation of an object of this jobClass.
*/
@Override
public String toString() {
return ( "JobSpecification: " + name + "," + jobClass + "," + phase );
}
}
Loading

0 comments on commit 8533029

Please sign in to comment.