Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame Performance Tool- jperf #1785

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/trick-jperf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/perl

use FindBin qw($RealBin);
use lib ("$RealBin/../libexec/trick/pm", "$RealBin/../lib/trick/pm") ;
use launch_java ;

launch_java("JPERF", "JPerf") ;

2 changes: 2 additions & 0 deletions include/trick/FrameLog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Trick {
/** Data to save for each timeline sample.\n */
struct timeline_t {
bool trick_job;
bool isEndOfFrame;
bool isTopOfFrame;
double id;
long long start;
long long stop;
Expand Down
6 changes: 6 additions & 0 deletions include/trick/JobData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ namespace Trick {
/** Indicates if a scheduler is handling this job */
bool handled; /**< trick_units(--) */

/** Indicates whether this is an "top_of_frame" job. */
bool isTopOfFrame; /**< trick_units(--) */

/** Indicates whether this is an "end_of_frame" job. */
bool isEndOfFrame; /**< trick_units(--) */

/** The cycle time */
double cycle; /**< trick_units(s) */

Expand Down
16 changes: 16 additions & 0 deletions trick_source/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@
<finalName>MM</finalName>
</configuration>
</execution>
<execution>

<id>jobperf</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>trick.jobperf.JobPerf</mainClass>
</transformer>
</transformers>
<finalName>JPerf</finalName>
</configuration>
</execution>

</executions>
</plugin>
Expand Down
76 changes: 76 additions & 0 deletions trick_source/java/src/main/java/trick/jobperf/FrameRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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.
*/
public class FrameRecord {
public ArrayList<JobExecutionEvent> jobEvents;
public double start;
public double stop;
/**
* Constructor
*/
public FrameRecord() {
start = 0.0;
stop = 0.0;
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 ++ ;
}
}
}
}
}
99 changes: 99 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,99 @@
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;
double duration = jobExec.stop - jobExec.start;

g2d.setFont(dataFont);
g2d.drawString(jobExec.id, 100, 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);

JobSpecification jobSpec = tvc.jobSpecificationMap.getJobSpecification(jobExec.id);
if ( jobSpec == null) {
g2d.setPaint( Color.RED );
g2d.drawString("UNKNOWN", 180, jobY);
g2d.drawString("UNKNOWN", 740, jobY);
} else {
g2d.drawString(jobSpec.jobClass, 180, 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
@@ -0,0 +1,12 @@
package trick.jobperf;

/**
* Class InvalidFrameBoundsExpection is an exception indicating
* that the user has specified an illegal range for the frames
* to be rendered.
*/
class InvalidFrameBoundsExpection extends Exception {
public InvalidFrameBoundsExpection(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package trick.jobperf;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.Math;
import java.util.*;
import java.util.List;
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
* clock times at which the job started and finished.
* <isTOF> indicates whether the job was run as
* an "top-of-frame" job.
*/
class JobExecutionEvent {
public String id;
public boolean isTOF;
public boolean isEOF;
public double start;
public double stop;
public int contained;

/**
* @param identifier identifies the relavant Trick job.
* @param isTopOfFrame true if the job is a "top-of-frame" job, otherwise false.
* @param isEndOfFrame true if the job is a "end-of-frame" job, otherwise false.
* @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 id, boolean isTOF, boolean isEOF, double start, double stop) {
this.id = id;
this.isTOF = isTOF;
this.isEOF = isEOF;
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.
*/
@Override
public String toString() {
return ( "JobExecutionEvent: " + id + "," + start + "," + stop );
}
}
Loading
Loading