Added Jobs-stats and, Frame-details windows, job names,classes, contained jobs and so forth.

This commit is contained in:
John M. Penn 2025-01-23 14:50:38 -06:00
parent 590c3dda9b
commit 8533029a62
17 changed files with 812 additions and 155 deletions

View File

@ -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.
@ -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 ++ ;
}
}
}
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -11,7 +11,6 @@ import javax.swing.*;
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
@ -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.
@ -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.
*/

View File

@ -5,12 +5,8 @@ import java.io.*;
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
@ -29,7 +25,7 @@ public class JobPerf {
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) {
@ -68,24 +64,58 @@ public class JobPerf {
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);
}
}
@ -132,7 +162,9 @@ public class JobPerf {
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;

View File

@ -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 );
}
}

View File

@ -0,0 +1,59 @@
package trick.jobperf;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.nio.file.*;
/**
* Class JobSpecificationMap associates identifiers with unique RGB colors.
*/
public class JobSpecificationMap {
private Map<String, JobSpecification> jobSpecMap;
/**
* Constructor
*/
public JobSpecificationMap( File file ) throws IOException, FileNotFoundException {
jobSpecMap = new HashMap<String, JobSpecification>();
System.out.println( "INSTANCIATING JobSpecificationMap("+ file.toString() +").");
BufferedReader in = new BufferedReader( new FileReader( file.toString()) );
String line;
String field[];
while( (line = in.readLine()) != null) {
if ( line.matches("\\s+1 [|].*$") ) {
field = line.split("[|]");
if (field.length == 9) {
String jobclass = field[2].trim();
int phase = Integer.parseInt( field[3].trim());
String id = field[7].trim();
String name = field[8].trim();
// System.out.println( "JobSpec = <" + id + "," + name + "," + jobclass + ">\n\n");
jobSpecMap.put(id, new JobSpecification(name, jobclass, phase));
}
}
}
in.close();
}
/**
* Add an identifier, and a JobSpecification to the JobSpecificationMap.
* @ param identifier Specifies the key.
*/
public void addKey( String identifier, JobSpecification jobSpec) {
if (!jobSpecMap.containsKey(identifier)) {
jobSpecMap.put(identifier, jobSpec);
}
}
/**
* Given an identifier, return the corresponding JobSpecification.
* @param identifier the key.
* @return the JobSpecification associated with the key.
*/
public JobSpecification getJobSpecification(String identifier) {
return jobSpecMap.get(identifier);
}
} // class JobSpecificationMap

View File

@ -46,8 +46,8 @@ class CompareByMaxDuration implements Comparator<StatisticsRecord> {
*/
class CompareByMinDuration implements Comparator<StatisticsRecord> {
public int compare(StatisticsRecord a, StatisticsRecord b) {
if ( a.minValue < b.minValue) return -1;
if ( a.minValue > b.minValue) return 1;
if ( a.minValue > b.minValue) return -1;
if ( a.minValue < b.minValue) return 1;
return 0;
}
}
@ -87,8 +87,8 @@ public class JobStats {
}
}
SortCriterion currentSortCriterion = SortCriterion.MEAN;
ArrayList<StatisticsRecord> jobStatisticsList;
public SortCriterion currentSortCriterion = SortCriterion.MEAN;
public ArrayList<StatisticsRecord> jobStatisticsList;
/**
* Constructor
@ -122,6 +122,7 @@ public class JobStats {
jobStatisticsList.add( new StatisticsRecord(id, mean, stddev, min, max));
}
SortByMeanValue();
}
/**
@ -167,18 +168,26 @@ public class JobStats {
/**
Write a text report to System.out.
*/
public void write() {
public void write( JobSpecificationMap jobSpecificationMap ) {
System.out.println(" [Job Duration Statistics Sorted by " + currentSortCriterion +"]");
System.out.println("----------------------------------------------------------------------");
System.out.println(" Job Id Mean Duration Std Dev Min Duration Max Duration");
System.out.println("---------- -------------- -------------- -------------- --------------");
for (StatisticsRecord jobStatisticsRecord : jobStatisticsList ) {
System.out.println( String.format("%10s %14.6f %14.6f %14.6f %14.6f",
jobStatisticsRecord.id,
jobStatisticsRecord.meanValue,
jobStatisticsRecord.stddev,
jobStatisticsRecord.minValue,
jobStatisticsRecord.maxValue));
System.out.println("--------------------------------------------------------------------------------------------------");
System.out.println(" Job Id Mean Duration Std Dev Min Duration Max Duration Name");
System.out.println("---------- -------------- -------------- -------------- -------------- ---------------------------");
for (StatisticsRecord jobStatisticsRecord : jobStatisticsList ) {
JobSpecification jobSpec = jobSpecificationMap.getJobSpecification( jobStatisticsRecord.id);
System.out.println( String.format("%10s %14.6f %14.6f %14.6f %14.6f %s",
jobStatisticsRecord.id,
jobStatisticsRecord.meanValue,
jobStatisticsRecord.stddev,
jobStatisticsRecord.minValue,
jobStatisticsRecord.maxValue,
jobSpec.name
)
);
}
}
}

View File

@ -0,0 +1,91 @@
package trick.jobperf;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class JobStatsViewCanvas extends JPanel {
private Font headingsFont;
private Font dataFont;
JobStats jobStats;
JobSpecificationMap jobSpecificationMap;
public JobStatsViewCanvas( JobStats jobStats,
JobSpecificationMap jobSpecificationMap ) {
this.jobStats = jobStats;
this.jobSpecificationMap = jobSpecificationMap;
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("Jobs Duration Statistics Sorted by " + jobStats.currentSortCriterion, 100, 50);
// Column Headings
g2d.setFont(headingsFont);
g2d.setPaint( Color.BLUE );
g2d.drawString("Job-ID", 100, 80);
g2d.drawString("Mean Dur", 200, 80);
g2d.drawString("Std Dev", 300, 80);
g2d.drawString("Min Dur", 400, 80);
g2d.drawString("Max Dur", 500, 80);
g2d.drawString("Job-Name", 600, 80);
// For each record
int jobY = 100;
for (StatisticsRecord jobStatisticsRecord : jobStats.jobStatisticsList ) {
JobSpecification jobSpec = jobSpecificationMap.getJobSpecification( jobStatisticsRecord.id);
g2d.setFont(dataFont);
g2d.setPaint( Color.BLACK );
g2d.drawString(jobStatisticsRecord.id, 100, jobY);
g2d.drawString( String.format("%14.6f", jobStatisticsRecord.meanValue), 180, jobY);
g2d.drawString( String.format("%14.6f", jobStatisticsRecord.stddev), 280, jobY);
g2d.drawString( String.format("%14.6f", jobStatisticsRecord.minValue), 380, jobY);
g2d.drawString( String.format("%14.6f", jobStatisticsRecord.maxValue), 480, jobY);
g2d.drawString(jobSpec.name, 600, jobY);
jobY += 20;
}
}
/**
* Calculate the height of the JobStatsCanvas (JPanel) needed to render the
* jobs in the frame.
*/
private int neededPanelHeight() {
return 20 * jobStats.jobStatisticsList.size() + 100;
}
/**
* This function paints the JobStatsCanvas (i.e, JPanel) when required.
*/
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}

View File

@ -0,0 +1,113 @@
package trick.jobperf;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
class SortButtonsToolBar extends JToolBar implements ActionListener {
JobStatsViewCanvas statsViewCanvas;
private JButton sortByIDButton;
private JButton sortByMean;
private JButton sortByStdDev;
private JButton sortByMin;
private JButton sortByMax;
public SortButtonsToolBar( JobStatsViewCanvas statsViewCanvas ) {
this.statsViewCanvas = statsViewCanvas;
add( new JLabel("Sort by : "));
sortByIDButton = new JButton("ID");
sortByIDButton.addActionListener(this);
sortByIDButton.setActionCommand("sort-by-ID");
sortByIDButton.setToolTipText("Sort by Job ID");
add(sortByIDButton);
sortByMean = new JButton("Mean");
sortByMean.addActionListener(this);
sortByMean.setActionCommand("sort-by-mean");
sortByMean.setToolTipText("Sort by Mean Job Run Duration");
add(sortByMean);
sortByStdDev = new JButton("Std Dev");
sortByStdDev.addActionListener(this);
sortByStdDev.setActionCommand("sort-by-std-dev");
sortByStdDev.setToolTipText("Sort by Std Deviation of Job Run Duration");
add(sortByStdDev);
sortByMin = new JButton("Min");
sortByMin.addActionListener(this);
sortByMin.setActionCommand("sort-by-min");
sortByMin.setToolTipText("Sort by Minimum Job Run Duration");
add(sortByMin);
sortByMax = new JButton("Max");
sortByMax.addActionListener(this);
sortByMax.setActionCommand("sort-by-max");
sortByMax.setToolTipText("Sort by Maximum Job Run Duration");
add(sortByMax);
}
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
switch (s) {
case "sort-by-ID":
statsViewCanvas.jobStats.SortByID();
statsViewCanvas.repaint();
break;
case "sort-by-mean":
statsViewCanvas.jobStats.SortByMeanValue();
statsViewCanvas.repaint();
break;
case "sort-by-std-dev":
statsViewCanvas.jobStats.SortByStdDev();
statsViewCanvas.repaint();
break;
case "sort-by-min":
statsViewCanvas.jobStats.SortByMinValue();
statsViewCanvas.repaint();
break;
case "sort-by-max":
statsViewCanvas.jobStats.SortByMaxValue();
statsViewCanvas.repaint();
break;
default:
System.out.println("Unknown Action Command:" + s);
break;
}
}
}
public class JobStatsViewWindow extends JFrame {
public JobStatsViewWindow( JobStats jobStats, JobSpecificationMap jobSpecificationMap ) {
JobStatsViewCanvas statsViewCanvas = new JobStatsViewCanvas( jobStats, jobSpecificationMap);
JScrollPane scrollPane = new JScrollPane( statsViewCanvas );
scrollPane.setPreferredSize(new Dimension(800, 400));
scrollPane.getVerticalScrollBar().setUnitIncrement( 20 );
SortButtonsToolBar toolbar = new SortButtonsToolBar( statsViewCanvas);
JPanel scrollingJobStatsCanvas = new JPanel();
scrollingJobStatsCanvas.setPreferredSize(new Dimension(800, 400));
scrollingJobStatsCanvas.add(toolbar);
scrollingJobStatsCanvas.add(scrollPane);
scrollingJobStatsCanvas.setLayout( new BoxLayout(scrollingJobStatsCanvas, BoxLayout.Y_AXIS));
setTitle("Job Statistics");
// setSize(800, 500);
setPreferredSize(new Dimension(1200, 500));
add(scrollingJobStatsCanvas);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setFocusable(true);
setVisible(true);
statsViewCanvas.repaint();
}
}

View File

@ -10,11 +10,13 @@ import java.util.*;
public class KeyedColorMap {
private Map<String, Color> colorMap;
int minLuminance;
String fileName;
/**
* Constructor
*/
public KeyedColorMap() {
public KeyedColorMap(String fileName) {
this.fileName = fileName;
colorMap = new HashMap<String, Color>();
minLuminance = 30;
}
@ -82,7 +84,7 @@ public class KeyedColorMap {
* Write the identifier, color key/value pairs of the KeyedColorMap to a file.
* @param fileName
*/
public void writeFile(String fileName) throws IOException {
public void writeFile() throws IOException {
BufferedWriter out = new BufferedWriter( new FileWriter(fileName) );
for (Map.Entry<String, Color> entry : colorMap.entrySet()) {
String id = entry.getKey();
@ -100,7 +102,7 @@ public class KeyedColorMap {
* Read identifier, color key-value pairs into the KeyedColorMap from a file.
* @param fileName
*/
public void readFile(String fileName) throws IOException {
public void readFile() throws IOException {
try {
BufferedReader in = new BufferedReader( new FileReader(fileName) );
String line;

View File

@ -12,17 +12,17 @@ public class StatisticsRecord {
public double minValue;
/**
* Constructor
* @param s - the job identifier.
* @param id - the job identifier.
* @param mean - the mean value of job duration.
* @param sd - the standard deviation of job duration.
* @param stddev - the standard deviation of job duration.
* @param min - the minimum value of job duration.
* @param max - the maximum value of job duration.
*/
public StatisticsRecord( String s, double mean, double sd, double min, double max) {
id = s;
meanValue = mean;
stddev = sd;
minValue = min;
maxValue = max;
public StatisticsRecord( String id, double mean, double stddev, double min, double max) {
this.id = id;
this.meanValue = mean;
this.stddev = stddev;
this.minValue = min;
this.maxValue = max;
}
}

View File

@ -17,26 +17,31 @@ import javax.swing.event.*;
*/
public class TraceViewCanvas extends JPanel {
public static final int MIN_TRACE_WIDTH = 4;
public static final int DEFAULT_TRACE_WIDTH = 15;
public static final int MAX_TRACE_WIDTH = 30;
public static final int MIN_TRACE_WIDTH = 12;
public static final int DEFAULT_TRACE_WIDTH = 18;
public static final int MAX_TRACE_WIDTH = 24;
public static final int LEFT_MARGIN = 100;
public static final int RIGHT_MARGIN = 100;
public static final int TOP_MARGIN = 20;
public static final int TOP_MARGIN = 50;
public static final int BOTTOM_MARGIN = 20;
public static final int DEFAULT_FRAMES_TO_RENDER = 100;
public KeyedColorMap idToColorMap;
public JobSpecificationMap jobSpecificationMap;
public JobStats jobStats;
private int traceWidth;
private double frameSize;
private double totalDuration;
private FrameRecord[] frameArray;
private int selectedFrameNumber;
private FrameRange frameRenderRange;
private KeyedColorMap idToColorMap;
private BufferedImage image;
private TraceViewOutputToolBar sToolBar;
private TraceViewOutputToolBar outputToolBar;
private Cursor crossHairCursor;
private Cursor defaultCursor;
private Font frameFont12;
private Font frameFont18;
public class FrameRange {
public int first;
@ -59,22 +64,28 @@ public class TraceViewCanvas extends JPanel {
* @param outputToolBar the toolbar to which data is to be sent for display.
*/
public TraceViewCanvas( ArrayList<JobExecutionEvent> jobExecEvtList,
TraceViewOutputToolBar outputToolBar ) {
TraceViewOutputToolBar outputToolBar,
KeyedColorMap idToColorMap,
JobSpecificationMap jobSpecificationMap ) {
traceWidth = DEFAULT_TRACE_WIDTH;
frameSize = 1.0;
image = null;
selectedFrameNumber = 0;
sToolBar = outputToolBar;
this.outputToolBar = outputToolBar;
this.idToColorMap = idToColorMap;
this.jobSpecificationMap = jobSpecificationMap;
jobStats = new JobStats(jobExecEvtList);
crossHairCursor = new Cursor( Cursor.CROSSHAIR_CURSOR );
defaultCursor = new Cursor( Cursor.DEFAULT_CURSOR );
frameFont12 = new Font("Arial", Font.PLAIN, 12);
frameFont18 = new Font("Arial", Font.PLAIN, 18);
try {
idToColorMap = new KeyedColorMap();
File colorfile = new File("IdToColors.txt");
if (colorfile.exists()) {
idToColorMap.readFile("IdToColors.txt");
}
boolean wasTOF = false;
List<FrameRecord> frameList = new ArrayList<FrameRecord>();
@ -84,6 +95,7 @@ public class TraceViewCanvas extends JPanel {
if (!wasTOF && jobExec.isTOF) {
// Wrap up the previous frame record.
frameRecord.stop = jobExec.start;
frameRecord.CalculateJobContainment();
frameList.add(frameRecord);
// Start a new frame record.
@ -95,9 +107,10 @@ public class TraceViewCanvas extends JPanel {
wasTOF = jobExec.isTOF;
idToColorMap.addKey(jobExec.id);
}
frameArray = frameList.toArray( new FrameRecord[ frameList.size() ]);
// Estimate the total duration and the average frame size. Notice
// Determine the total duration and the average frame size. Notice
// that we skip the first frame.
totalDuration = 0.0;
for (int n=1; n < frameArray.length; n++) {
@ -112,13 +125,10 @@ public class TraceViewCanvas extends JPanel {
}
frameRenderRange = new FrameRange(0, last_frame_to_render);
// Write the color file.
idToColorMap.writeFile("IdToColors.txt");
// Write the color map to a file.
idToColorMap.writeFile();
System.out.println("File loaded.\n");
} catch ( java.io.FileNotFoundException e ) {
System.out.println("File not found.\n");
System.exit(0);
// System.out.println("File loaded.\n");
} catch ( java.io.IOException e ) {
System.out.println("IO Exception.\n");
System.exit(0);
@ -203,6 +213,20 @@ public class TraceViewCanvas extends JPanel {
}
}
/**
*
*/
public void displaySelectedFrame() {
FrameViewWindow window = new FrameViewWindow( this, frameArray[selectedFrameNumber], selectedFrameNumber);
}
/**
*
*/
public void displayJobStatsWindow() {
JobStatsViewWindow window = new JobStatsViewWindow( jobStats, jobSpecificationMap);
}
/**
* @return true if the trace rectangle contains the point <x,y>, otherwise
* false.
@ -228,22 +252,27 @@ public class TraceViewCanvas extends JPanel {
// Get and display the ID of the job associated with the color.
String id = idToColorMap.getKeyOfColor( color );
sToolBar.setJobID(id);
outputToolBar.setJobID(id);
// Get and display the job name associated with the ID.
JobSpecification jobSpec = jobSpecificationMap.getJobSpecification(id);
if (jobSpec != null) {
outputToolBar.setJobName(jobSpec.name);
outputToolBar.setJobClass(jobSpec.jobClass);
}
// Determine the frame number that we clicked on from the y-
// coordinate of the click position.
if ( y > TOP_MARGIN) {
selectedFrameNumber = (y - TOP_MARGIN) / traceWidth + frameRenderRange.first;
sToolBar.setFrameNumber(selectedFrameNumber);
}
// Determine the subframe-time where we clicked from the x-coordinate
// of the click position.
double subFrameClickTime = 0.0;
if ( traceRectContains(x, y)) {
double pixelsPerSecond = (double)traceRectWidth() / frameSize;
double subFrameTime = (x - LEFT_MARGIN) / pixelsPerSecond;
sToolBar.setSubFrameTime(subFrameTime);
subFrameClickTime = (x - LEFT_MARGIN) / pixelsPerSecond;
}
/**
@ -252,15 +281,17 @@ public class TraceViewCanvas extends JPanel {
*/
if (id != null) {
FrameRecord frame = frameArray[selectedFrameNumber];
Double clickTime = frame.start + subFrameClickTime;
for (JobExecutionEvent jobExec : frame.jobEvents) {
if (id.equals( jobExec.id)) {
sToolBar.setJobStartTime(jobExec.start);
sToolBar.setJobStopTime(jobExec.stop);
if (id.equals( jobExec.id) &&
clickTime >= jobExec.start &&
clickTime <= jobExec.stop ) {
outputToolBar.setJobTimes(jobExec.start, jobExec.stop);
}
}
repaint();
} else {
sToolBar.clearJobStartStopTime();
outputToolBar.clearJobFields();
}
}
@ -327,26 +358,61 @@ public class TraceViewCanvas extends JPanel {
g2d.setPaint(Color.BLACK);
g2d.fillRect(LEFT_MARGIN, TOP_MARGIN, traceRectWidth, traceRectHeight());
if (traceWidth >= DEFAULT_TRACE_WIDTH) {
g2d.setFont(frameFont18);
} else {
g2d.setFont(frameFont12);
}
FontMetrics fm = g2d.getFontMetrics();
int TX = 0;
String FN_text = "Frame #";
TX = (LEFT_MARGIN - fm.stringWidth(FN_text))/2;
g2d.drawString (FN_text, TX, 40);
g2d.drawString ("Top of Frame", LEFT_MARGIN, 40);
String EOF_text = "End of Frame";
TX = LEFT_MARGIN + traceRectWidth - fm.stringWidth(EOF_text);
g2d.drawString (EOF_text, TX, 40);
// Draw each frame in the selected range of frames to be rendered.
for (int n = frameRenderRange.first;
n <= frameRenderRange.last;
n++) {
FrameRecord frame = frameArray[n];
int jobY = TOP_MARGIN + (n - frameRenderRange.first) * traceWidth;
// Draw frame number.
if (n == selectedFrameNumber) {
g2d.setPaint(Color.RED);
// g2d.drawString ( "\u25b6", 20, jobY + traceWidth - 2);
g2d.drawString ( "\u25c0", 80, jobY + traceWidth - 2);
// g2d.fillRect(LEFT_MARGIN-traceWidth, jobY, traceWidth, traceWidth);
} else {
g2d.setPaint(Color.BLACK);
}
g2d.drawString ( String.format("%d", n), 40, jobY + traceWidth - 2);
// Draw the frame
for (JobExecutionEvent jobExec : frame.jobEvents) {
int jobY = TOP_MARGIN + (n - frameRenderRange.first) * traceWidth;
int jobStartX = LEFT_MARGIN + (int)((jobExec.start - frame.start) * pixelsPerSecond);
int jobWidth = (int)( (jobExec.stop - jobExec.start) * pixelsPerSecond);
// NOTE that the jobEvents within the frame are expected to be sorted in duration-order,
// so that smaller sub-jobs are not obscurred.
g2d.setPaint(Color.BLACK);
if (n == selectedFrameNumber) {
g2d.setPaint(Color.GREEN);
}
g2d.drawString ( String.format("%d", n), 50, jobY + traceWidth/2);
for (JobExecutionEvent jobExec : frame.jobEvents) {
int jobStartX = (int)((jobExec.start - frame.start) * pixelsPerSecond) + LEFT_MARGIN;
int jobWidth = (int)((jobExec.stop - jobExec.start) * pixelsPerSecond);
g2d.setPaint( idToColorMap.getColor( jobExec.id ) );
g2d.fillRect(jobStartX, jobY, jobWidth, traceWidth-2);
int jobHeight = traceWidth - 2;
if (jobExec.contained > 1) {
jobHeight = traceWidth / jobExec.contained;
}
// int jobStartY = jobY + (traceWidth - 2) - jobHeight;
g2d.fillRect(jobStartX, jobY, jobWidth, jobHeight);
}
}
}

View File

@ -22,10 +22,11 @@ import java.net.URL;
* JLabel
* JTextField [lastRenderFrameField]
*/
public class TraceViewInputToolBar extends JToolBar {
public class TraceViewInputToolBar extends JToolBar implements ActionListener {
private TraceViewCanvas traceView;
private JTextField frameSizeField;
private JButton frameDetailsButton;
private JTextField firstRenderFrameField;
private JTextField lastRenderFrameField;
/**
@ -35,8 +36,8 @@ public class TraceViewInputToolBar extends JToolBar {
public TraceViewInputToolBar (TraceViewCanvas tvc) {
traceView = tvc;
add( new JLabel(" Frame Size: "));
frameSizeField = new JTextField(15);
add( new JLabel(" Frame Size (Avg): "));
frameSizeField = new JTextField(10);
frameSizeField.setText( String.format("%8.4f", traceView.getFrameSize()) );
add(frameSizeField);
frameSizeField.addKeyListener( new KeyAdapter() {
@ -48,11 +49,17 @@ public class TraceViewInputToolBar extends JToolBar {
}
});
add( new JLabel( String.format(" Total Frame Range: %d ... %d", 0, traceView.getFrameTotal()-1 )));
frameDetailsButton = new JButton("Frame Details");
frameDetailsButton.addActionListener(this);
frameDetailsButton.setActionCommand("display-frame-details");
frameDetailsButton.setToolTipText("Display the job details of the selected frame.");
add(frameDetailsButton);
add( new JLabel(" Selected Frame Range: "));
add( new JLabel( String.format(" Frames : [%d ... %d]", 0, traceView.getFrameTotal()-1 )));
firstRenderFrameField = new JTextField(15);
add( new JLabel(" Selected Range: "));
firstRenderFrameField = new JTextField(10);
firstRenderFrameField.setText( String.format("%d", traceView.getFirstRenderFrame()) );
add(firstRenderFrameField);
firstRenderFrameField.addKeyListener( new KeyAdapter() {
@ -65,7 +72,7 @@ public class TraceViewInputToolBar extends JToolBar {
});
add( new JLabel("..."));
lastRenderFrameField = new JTextField(15);
lastRenderFrameField = new JTextField(10);
lastRenderFrameField.setText( String.format("%d", traceView.getLastRenderFrame()) );
add(lastRenderFrameField);
lastRenderFrameField.addKeyListener( new KeyAdapter() {
@ -77,9 +84,24 @@ public class TraceViewInputToolBar extends JToolBar {
}
});
add( new JLabel(" "));
// Add Trick LOGO here.
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
switch (s) {
case "display-frame-details":
traceView.displaySelectedFrame();
break;
default:
System.out.println("Unknown Action Command:" + s);
break;
}
}
private void setFirstRenderFrame() {
int newStartFrame = 0;
try {

View File

@ -11,10 +11,10 @@ import javax.swing.*;
* JMenuBar [this]
* JMenu [fileMenu]
* JMenuItem [fileMenuExit], Action: Call System.exit(0);
* JMenu [optionsMenu]
* JMenu [viewMenu]
* JMenu [traceSizeMenu]
* JMenuItem [traceSizeMenuIncrease], Action: Call traceView.incrementTraceWidth().
* JMenuItem [traceSizeMenuDecrease], Action: Call traceView.decrementTraceWidth()
* JMenuItem [traceSizeIncrease], Action: Call traceView.incrementTraceWidth().
* JMenuItem [traceSizeDecrease], Action: Call traceView.decrementTraceWidth()
*/
public class TraceViewMenuBar extends JMenuBar implements ActionListener {
@ -30,26 +30,45 @@ public class TraceViewMenuBar extends JMenuBar implements ActionListener {
JMenu fileMenu = new JMenu("File");
JMenuItem fileMenuExit = new JMenuItem("Exit");
fileMenuExit.setActionCommand("exit");
KeyStroke ctrlQ = KeyStroke.getKeyStroke('Q', InputEvent.CTRL_MASK );
fileMenuExit.setAccelerator(ctrlQ);
fileMenuExit.addActionListener(this);
fileMenu.add(fileMenuExit);
add(fileMenu);
JMenu optionsMenu = new JMenu("Options");
JMenu traceSizeMenu = new JMenu("TraceSize");
JMenuItem traceSizeMenuIncrease = new JMenuItem("Increase Trace Width");
traceSizeMenuIncrease.setActionCommand("increase-trace_width");
JMenu viewMenu = new JMenu("View");
JMenuItem traceSizeIncrease = new JMenuItem("Increase Trace Width");
traceSizeIncrease.setActionCommand("increase-trace_width");
KeyStroke ctrlPlus = KeyStroke.getKeyStroke('=', InputEvent.CTRL_MASK );
traceSizeMenuIncrease.setAccelerator(ctrlPlus);
traceSizeMenuIncrease.addActionListener(this);
traceSizeMenu.add(traceSizeMenuIncrease);
JMenuItem traceSizeMenuDecrease = new JMenuItem("Decrease Trace Width");
traceSizeMenuDecrease.setActionCommand("decrease-trace_width");
traceSizeIncrease.setAccelerator(ctrlPlus);
traceSizeIncrease.addActionListener(this);
viewMenu.add(traceSizeIncrease);
JMenuItem traceSizeDecrease = new JMenuItem("Decrease Trace Width");
traceSizeDecrease.setActionCommand("decrease-trace_width");
KeyStroke ctrlMinus = KeyStroke.getKeyStroke('-', InputEvent.CTRL_MASK);
traceSizeMenuDecrease.setAccelerator(ctrlMinus);
traceSizeMenuDecrease.addActionListener(this);
traceSizeMenu.add(traceSizeMenuDecrease);
optionsMenu.add(traceSizeMenu);
add(optionsMenu);
traceSizeDecrease.setAccelerator(ctrlMinus);
traceSizeDecrease.addActionListener(this);
viewMenu.add(traceSizeDecrease);
viewMenu.addSeparator();
JMenuItem showFrame = new JMenuItem("Frame Details ...");
showFrame.setActionCommand("expand-selected-frame");
KeyStroke ctrlF = KeyStroke.getKeyStroke('F', InputEvent.CTRL_MASK);
showFrame.setAccelerator(ctrlF);
showFrame.addActionListener(this);
viewMenu.add(showFrame);
JMenuItem showStats = new JMenuItem("Job Statistics ...");
showStats.setActionCommand("show-job-stats");
KeyStroke ctrlV = KeyStroke.getKeyStroke('V', InputEvent.CTRL_MASK);
showStats.setAccelerator(ctrlV);
showStats.addActionListener(this);
viewMenu.add(showStats);
add(viewMenu);
}
@Override
@ -62,6 +81,13 @@ public class TraceViewMenuBar extends JMenuBar implements ActionListener {
case "decrease-trace_width":
traceView.decrementTraceWidth();
break;
case "expand-selected-frame":
traceView.displaySelectedFrame();
break;
case "show-job-stats":
traceView.jobStats.SortByID();
traceView.displayJobStatsWindow();
break;
case "exit":
System.exit(0);
default:

View File

@ -1,18 +1,20 @@
package trick.jobperf;
import java.awt.*;
import javax.swing.*;
/**
* Class TraceViewOutputToolBar displays information output from a
* TraceViewCanvas. Specifically, this displays the Job ID, frame number, and
* subFrame Time associated with a mouse click position on the TraceViewCanvas.
* TraceViewCanvas.
*/
class TraceViewOutputToolBar extends JToolBar {
private JTextField IDField;
private JTextField nameField;
private JTextField classField;
private JTextField startField;
private JTextField stopField;
private JTextField frameNumberField;
private JTextField subFrameTimeField;
// private JTextField frameNumberField;
private JTextField durationField;
/**
* Constructor
@ -20,71 +22,83 @@ class TraceViewOutputToolBar extends JToolBar {
public TraceViewOutputToolBar () {
add( new JLabel(" Job ID: "));
IDField = new JTextField(15);
IDField = new JTextField(5);
IDField.setEditable(false);
IDField.setText( "");
add(IDField);
add( new JLabel(" Job Start: "));
startField = new JTextField(15);
add( new JLabel(" Name: "));
nameField = new JTextField(25);
nameField.setEditable(false);
nameField.setText( "");
add(nameField);
add( new JLabel(" Class: "));
classField = new JTextField(12);
classField.setEditable(false);
classField.setText( "");
add(classField);
add( new JLabel(" Start: "));
startField = new JTextField(6);
startField.setEditable(false);
startField.setText( "");
add(startField);
add( new JLabel(" Job Stop: "));
stopField = new JTextField(15);
add( new JLabel(" Stop: "));
stopField = new JTextField(6);
stopField.setEditable(false);
stopField.setText( "");
add(stopField);
add( new JLabel(" Frame Number: "));
frameNumberField = new JTextField(15);
frameNumberField.setEditable(false);
frameNumberField.setText( "0");
add(frameNumberField);
add( new JLabel(" Subframe Time: "));
subFrameTimeField = new JTextField(15);
subFrameTimeField.setEditable(false);
subFrameTimeField.setText( "0.00");
add(subFrameTimeField);
add( new JLabel(" Duration: "));
durationField = new JTextField(6);
durationField.setEditable(false);
durationField.setText( "");
add(durationField);
}
/**
* @param id job identifier to display.
*/
public void setJobID(String id) {
IDField.setText( id );
}
/**
* @param id job identifier to display.
*/
public void setJobName(String name) {
nameField.setText(name);
}
/**
* @param id job class to display.
*/
public void setJobClass(String name) {
classField.setText(name);
}
/**
* @param time to be displayed in the job start field.
*/
public void setJobStartTime(Double time) {
startField.setText( String.format("%8.4f", time) );
}
/**
* @param time to be displayed in the job stop field.
*/
public void setJobStopTime(Double time) {
stopField.setText( String.format("%8.4f", time) );
public void setJobTimes(Double start_time, Double stop_time) {
startField.setText( String.format("%8.4f", start_time) );
stopField.setText( String.format("%8.4f", stop_time) );
Double duration = stop_time - start_time;
durationField.setText( String.format("%8.4f", duration) );
}
/**
* Clear the startField and stopField.
*/
public void clearJobStartStopTime() {
public void clearJobFields() {
nameField.setText("");
classField.setText("");
startField.setText("");
stopField.setText("");
durationField.setText("");
IDField.setText("");
}
/**
* @param fn frame number to display.
*/
public void setFrameNumber(int fn) {
frameNumberField.setText( String.format("%d", fn));
}
/**
* @param time subframe time to display.
*/
public void setSubFrameTime(double time) {
subFrameTimeField.setText( String.format("%8.4f", time));
}
}

View File

@ -22,9 +22,13 @@ public class TraceViewWindow extends JFrame {
* Constructor
* @param jobExecList an ArrayList of JobExecutionEvent, i.e., the job timeline data.
*/
public TraceViewWindow( ArrayList<JobExecutionEvent> jobExecList ) {
public TraceViewWindow( ArrayList<JobExecutionEvent> jobExecList,
KeyedColorMap idToColorMap,
JobSpecificationMap jobSpecificationMap ) {
TraceViewOutputToolBar outputToolBar = new TraceViewOutputToolBar();
TraceViewCanvas traceViewCanvas = new TraceViewCanvas( jobExecList, outputToolBar);
TraceViewCanvas traceViewCanvas = new TraceViewCanvas( jobExecList, outputToolBar, idToColorMap, jobSpecificationMap);
TraceViewMenuBar menuBar = new TraceViewMenuBar( traceViewCanvas);
setJMenuBar(menuBar);