Skip to content

Commit

Permalink
Tidy up whitespace in openj9.traceformat
Browse files Browse the repository at this point in the history
* remove trailing whitespace
* indent with tabs consistently
* collapse sequences of two or more blank lines
* remove extra trailing blank lines

Signed-off-by: Keith W. Campbell <[email protected]>
  • Loading branch information
keithc-ca committed Sep 10, 2024
1 parent cbe04f9 commit fc7dee8
Show file tree
Hide file tree
Showing 47 changed files with 3,870 additions and 3,895 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,64 @@
import java.io.BufferedWriter;
import java.io.IOException;

/**
/**
* Active section of a file header.
*
* @author Tim Preece
*/
public class ActiveSection {
private String eyecatcher_string;
private int length;
private int version;
private int modification;
private long active_offset;
private long active_end;
private String eyecatcher_string;
private int length;
private int version;
private int modification;
private long active_offset;
private long active_end;

private TraceFile traceFile;
private TraceFile traceFile;

public ActiveSection (TraceFile traceFile, int start ) throws IOException
{
// Version 1.1
this.traceFile = traceFile;
traceFile.seek((long)start);
eyecatcher_string = Util.convertAndCheckEyecatcher(traceFile.readI());
length = traceFile.readI();
version = traceFile.readI();
modification = traceFile.readI();
active_offset = traceFile.getFilePointer();
active_end = start + length;
public ActiveSection (TraceFile traceFile, int start ) throws IOException
{
// Version 1.1
this.traceFile = traceFile;
traceFile.seek((long)start);
eyecatcher_string = Util.convertAndCheckEyecatcher(traceFile.readI());
length = traceFile.readI();
version = traceFile.readI();
modification = traceFile.readI();
active_offset = traceFile.getFilePointer();
active_end = start + length;

Util.Debug.println("ActiveSection: eyecatcher: " + eyecatcher_string);
Util.Debug.println("ActiveSection: length: " + length);
Util.Debug.println("ActiveSection: version: " + version);
Util.Debug.println("ActiveSection: modification: " + modification);
Util.Debug.println("ActiveSection: eyecatcher: " + eyecatcher_string);
Util.Debug.println("ActiveSection: length: " + length);
Util.Debug.println("ActiveSection: version: " + version);
Util.Debug.println("ActiveSection: modification: " + modification);

}
}

protected void summary(BufferedWriter out) throws IOException
{
traceFile.seek(active_offset);
byte[] activeBuffer = new byte[(int)(active_end - active_offset)];
Util.Debug.println("ActiveSection: active_offset: " + active_offset);
Util.Debug.println("ActiveSection: active_end: " + active_end);
protected void summary(BufferedWriter out) throws IOException
{
traceFile.seek(active_offset);
byte[] activeBuffer = new byte[(int)(active_end - active_offset)];
Util.Debug.println("ActiveSection: active_offset: " + active_offset);
Util.Debug.println("ActiveSection: active_end: " + active_end);

out.write("Activation Info :");
out.newLine();
out.write("Activation Info :");
out.newLine();

StringBuffer buf;
traceFile.read(activeBuffer);
// Util.printDump(activeBuffer,activeBuffer.length);
for (int i=0, j=0; (i<activeBuffer.length) ; i++) {
for ( ; (activeBuffer[i]!=0) ; i++) { // look for null terminator
}
if (i == j) {
break; // a null terminates the list
}
out.write(Util.SUM_TAB); // indent the new string
out.write(new String(activeBuffer, j, i - j, "UTF-8"));
out.newLine();
j = i + 1;
}
out.newLine();
}
StringBuffer buf;
traceFile.read(activeBuffer);
// Util.printDump(activeBuffer,activeBuffer.length);
for (int i=0, j=0; (i<activeBuffer.length) ; i++) {
for ( ; (activeBuffer[i]!=0) ; i++) { // look for null terminator
}
if (i == j) {
break; // a null terminates the list
}
out.write(Util.SUM_TAB); // indent the new string
out.write(new String(activeBuffer, j, i - j, "UTF-8"));
out.newLine();
j = i + 1;
}
out.newLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,134 +29,134 @@
import java.util.*;

public class Format2Tprof {
final String Trc_JIT_Component_Name = "j9jit";
final int Trc_JIT_Sampling_Id = 13;
final int Trc_JIT_Sampling_Detail_Id = 14;
final char FS = '\t'; // field separator
final String TraceEntryPrefix = "SamplingLog"; // common to both ids

static int totalCount = 0;
final String Trc_JIT_Component_Name = "j9jit";
final int Trc_JIT_Sampling_Id = 13;
final int Trc_JIT_Sampling_Detail_Id = 14;
final char FS = '\t'; // field separator
final String TraceEntryPrefix = "SamplingLog"; // common to both ids

public class MethodEntry implements Comparable {
public String name = null;
public String offset = null;
public int count = 0;
public MethodEntry(String n, String o) { name = n; offset = o; }
public MethodEntry(String n) { name = n; }
/* offset won't be compared */
public boolean equals(Object o) { MethodEntry e = (MethodEntry) o; return name.equals(e.name); }
public int compareTo(Object o) { MethodEntry e = (MethodEntry) o; return name.compareTo(e.name); }
}
static int totalCount = 0;

public void run(String args[]) {
if (args.length < 1 || args.length > 2) {
System.err.println("Format2Tprof <trace format input> [tprof output]");
return;
}
LinkedList sampleMethodTable = new LinkedList();
if (!readAndFormat(args, sampleMethodTable)) {
System.err.println("No method sampling event found in the trace. No output will be written.");
return;
}
Collections.sort(sampleMethodTable);
// System.err.println(sampleMethodTable);
totalCount = sampleMethodTable.size();
countSampleMethod(sampleMethodTable); // dup method names will be removed
Collections.sort(sampleMethodTable, new Comparator()
{
public int compare(Object o1, Object o2) {
MethodEntry m1 = (MethodEntry) o1;
MethodEntry m2 = (MethodEntry) o2;
return m2.count - m1.count; // in descending order
}
}
);
try {
PrintStream ps = System.out; // default
if (args.length == 2)
ps = new PrintStream(new FileOutputStream(args[1]));
generateTprofOutput(ps, sampleMethodTable);
if (args.length == 2)
ps.close();
}
catch (FileNotFoundException e) {
System.err.println("Error opening output file");
e.printStackTrace();
}
}

public static void main(String args[]) {
Format2Tprof pf = new Format2Tprof();
pf.run(args);
}

public void countSampleMethod(Collection s) {
Iterator iter = s.iterator();
MethodEntry pe = (MethodEntry) iter.next();
pe.count++;
while (iter.hasNext())
{
MethodEntry e = (MethodEntry) iter.next();
if (pe.equals(e))
iter.remove();
else
pe = e;
pe.count++;
}
}
public class MethodEntry implements Comparable {
public String name = null;
public String offset = null;
public int count = 0;
public MethodEntry(String n, String o) { name = n; offset = o; }
public MethodEntry(String n) { name = n; }
/* offset won't be compared */
public boolean equals(Object o) { MethodEntry e = (MethodEntry) o; return name.equals(e.name); }
public int compareTo(Object o) { MethodEntry e = (MethodEntry) o; return name.compareTo(e.name); }
}

public void generateTprofOutput(PrintStream out, Collection s) {
Iterator iter = s.iterator();
while (iter.hasNext())
{
MethodEntry e = (MethodEntry) iter.next();
float percent = (float) (e.count * 100) / totalCount;
String percentStr = Float.toString(percent).substring(0, 4) + "%";
out.println(percentStr + " " + e.count + " " + e.name);
}
}
public void run(String args[]) {
if (args.length < 1 || args.length > 2) {
System.err.println("Format2Tprof <trace format input> [tprof output]");
return;
}
LinkedList sampleMethodTable = new LinkedList();
if (!readAndFormat(args, sampleMethodTable)) {
System.err.println("No method sampling event found in the trace. No output will be written.");
return;
}
Collections.sort(sampleMethodTable);
// System.err.println(sampleMethodTable);
totalCount = sampleMethodTable.size();
countSampleMethod(sampleMethodTable); // dup method names will be removed
Collections.sort(sampleMethodTable, new Comparator()
{
public int compare(Object o1, Object o2) {
MethodEntry m1 = (MethodEntry) o1;
MethodEntry m2 = (MethodEntry) o2;
return m2.count - m1.count; // in descending order
}
}
);
try {
PrintStream ps = System.out; // default
if (args.length == 2)
ps = new PrintStream(new FileOutputStream(args[1]));
generateTprofOutput(ps, sampleMethodTable);
if (args.length == 2)
ps.close();
}
catch (FileNotFoundException e) {
System.err.println("Error opening output file");
e.printStackTrace();
}
}

public MethodEntry getJittedMethod(String msg) {
int firstTabPos = msg.indexOf(FS);
int secondTabPos = (firstTabPos != -1) ? msg.indexOf(FS, firstTabPos+1) : -1;
if (firstTabPos == -1 || secondTabPos == -1)
return null;
String name = msg.substring(firstTabPos+1,secondTabPos-1);
int thirdTabPos = msg.indexOf(FS, secondTabPos+1);
if (thirdTabPos == -1)
return new MethodEntry(name);
int fourthTabPos = msg.indexOf(FS, thirdTabPos+1);
if (fourthTabPos == -1)
return new MethodEntry(name, msg.substring(thirdTabPos+1));
return new MethodEntry(name, msg.substring(thirdTabPos+1,fourthTabPos-1));
}
public static void main(String args[]) {
Format2Tprof pf = new Format2Tprof();
pf.run(args);
}

public boolean readAndFormat(String args[], List methodTable) {
boolean rc = false;
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
String line = null;
while ((line = in.readLine()) != null) {
int pos;
if ((pos = line.indexOf(TraceEntryPrefix)) != -1) {
String formattedData = line.substring(pos);
MethodEntry me = getJittedMethod(formattedData);
if (me != null) {
rc = true;
methodTable.add(me);
}
}
}
in.close();
}
catch (FileNotFoundException e) {
System.err.println("Error opening trace file");
e.printStackTrace();
}
catch (IOException e) {
System.err.println("Error processing trace file");
e.printStackTrace();
}
return rc;
}
public void countSampleMethod(Collection s) {
Iterator iter = s.iterator();
MethodEntry pe = (MethodEntry) iter.next();
pe.count++;
while (iter.hasNext())
{
MethodEntry e = (MethodEntry) iter.next();
if (pe.equals(e))
iter.remove();
else
pe = e;
pe.count++;
}
}

public void generateTprofOutput(PrintStream out, Collection s) {
Iterator iter = s.iterator();
while (iter.hasNext())
{
MethodEntry e = (MethodEntry) iter.next();
float percent = (float) (e.count * 100) / totalCount;
String percentStr = Float.toString(percent).substring(0, 4) + "%";
out.println(percentStr + " " + e.count + " " + e.name);
}
}

public MethodEntry getJittedMethod(String msg) {
int firstTabPos = msg.indexOf(FS);
int secondTabPos = (firstTabPos != -1) ? msg.indexOf(FS, firstTabPos+1) : -1;
if (firstTabPos == -1 || secondTabPos == -1)
return null;
String name = msg.substring(firstTabPos+1,secondTabPos-1);
int thirdTabPos = msg.indexOf(FS, secondTabPos+1);
if (thirdTabPos == -1)
return new MethodEntry(name);
int fourthTabPos = msg.indexOf(FS, thirdTabPos+1);
if (fourthTabPos == -1)
return new MethodEntry(name, msg.substring(thirdTabPos+1));
return new MethodEntry(name, msg.substring(thirdTabPos+1,fourthTabPos-1));
}

public boolean readAndFormat(String args[], List methodTable) {
boolean rc = false;
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
String line = null;
while ((line = in.readLine()) != null) {
int pos;
if ((pos = line.indexOf(TraceEntryPrefix)) != -1) {
String formattedData = line.substring(pos);
MethodEntry me = getJittedMethod(formattedData);
if (me != null) {
rc = true;
methodTable.add(me);
}
}
}
in.close();
}
catch (FileNotFoundException e) {
System.err.println("Error opening trace file");
e.printStackTrace();
}
catch (IOException e) {
System.err.println("Error processing trace file");
e.printStackTrace();
}
return rc;
}
}
Loading

0 comments on commit fc7dee8

Please sign in to comment.