< prev index next >

src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java

Print this page

        

*** 38,47 **** --- 38,48 ---- import sun.java2d.pipe.Region; import java.lang.reflect.Field; import java.util.StringTokenizer; import java.util.Iterator; import java.util.HashMap; + import java.util.HashSet; import java.util.Map; import java.io.PrintStream; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException;
*** 320,363 **** static HashMap<Object, int[]> traceMap; public static int traceflags; public static String tracefile; public static PrintStream traceout; public static final int TRACELOG = 1; public static final int TRACETIMESTAMP = 2; public static final int TRACECOUNTS = 4; static { GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace"); String trace = AccessController.doPrivileged(gpa); if (trace != null) { - boolean verbose = false; int traceflags = 0; StringTokenizer st = new StringTokenizer(trace, ","); while (st.hasMoreTokens()) { String tok = st.nextToken(); if (tok.equalsIgnoreCase("count")) { traceflags |= GraphicsPrimitive.TRACECOUNTS; } else if (tok.equalsIgnoreCase("log")) { traceflags |= GraphicsPrimitive.TRACELOG; } else if (tok.equalsIgnoreCase("timestamp")) { traceflags |= GraphicsPrimitive.TRACETIMESTAMP; } else if (tok.equalsIgnoreCase("verbose")) { verbose = true; } else if (tok.regionMatches(true, 0, "out:", 0, 4)) { tracefile = tok.substring(4); } else { if (!tok.equalsIgnoreCase("help")) { System.err.println("unrecognized token: "+tok); } ! System.err.println("usage: -Dsun.java2d.trace="+ ! "[log[,timestamp]],[count],"+ ! "[out:<filename>],[help],[verbose]"); } } if (verbose) { System.err.print("GraphicsPrimitive logging "); if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) { System.err.println("enabled"); System.err.print("GraphicsPrimitive timetamps "); --- 321,389 ---- static HashMap<Object, int[]> traceMap; public static int traceflags; public static String tracefile; + public static String pname; public static PrintStream traceout; + public static long treshold = 0; + public static boolean verbose = false; public static final int TRACELOG = 1; public static final int TRACETIMESTAMP = 2; public static final int TRACECOUNTS = 4; + public static final int TRACEPTIME = 8; + public static final int TRACEPNAME = 16; + public static final int TRACEPIMPL = 32; + + static void showTraceUsage() { + System.err.println("usage: -Dsun.java2d.trace="+ + "[log[,timestamp]],[count],[ptime],[pimpl],[name:<substr pattern>],"+ + "[out:<filename>],[td=<treshold>],[help],[verbose]"); + } static { GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace"); String trace = AccessController.doPrivileged(gpa); if (trace != null) { int traceflags = 0; StringTokenizer st = new StringTokenizer(trace, ","); while (st.hasMoreTokens()) { String tok = st.nextToken(); if (tok.equalsIgnoreCase("count")) { traceflags |= GraphicsPrimitive.TRACECOUNTS; } else if (tok.equalsIgnoreCase("log")) { traceflags |= GraphicsPrimitive.TRACELOG; } else if (tok.equalsIgnoreCase("timestamp")) { traceflags |= GraphicsPrimitive.TRACETIMESTAMP; + } else if (tok.equalsIgnoreCase("ptime")) { + traceflags |=GraphicsPrimitive.TRACEPTIME; + } else if (tok.equalsIgnoreCase("pimpl")) { + traceflags |=GraphicsPrimitive.TRACEPIMPL; + } else if (tok.regionMatches(true, 0, "name:", 0, 5)) { + traceflags |=GraphicsPrimitive.TRACEPNAME; + pname = tok.substring(6); } else if (tok.equalsIgnoreCase("verbose")) { verbose = true; } else if (tok.regionMatches(true, 0, "out:", 0, 4)) { tracefile = tok.substring(4); + } else if (tok.regionMatches(true, 0, "td=", 0, 3)) { + try { + treshold = Long.parseLong(tok.substring(3)); + } catch (NumberFormatException e) { + showTraceUsage(); + } } else { if (!tok.equalsIgnoreCase("help")) { System.err.println("unrecognized token: "+tok); } ! showTraceUsage(); } } + + GraphicsPrimitiveMgr.setTraceFlags(traceflags); + if (verbose) { System.err.print("GraphicsPrimitive logging "); if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) { System.err.println("enabled"); System.err.print("GraphicsPrimitive timetamps ");
*** 414,424 **** } return traceout; } public static class TraceReporter implements Runnable { ! public static void setShutdownHook() { AccessController.doPrivileged((PrivilegedAction<Void>) () -> { TraceReporter t = new TraceReporter(); Thread thread = new Thread( ThreadGroupUtils.getRootThreadGroup(), t, "TraceReporter", 0, false); --- 440,455 ---- } return traceout; } public static class TraceReporter implements Runnable { ! private static boolean hookEnabled = false; ! ! public static synchronized void setShutdownHook() { ! if (hookEnabled) return; ! hookEnabled = true; ! AccessController.doPrivileged((PrivilegedAction<Void>) () -> { TraceReporter t = new TraceReporter(); Thread thread = new Thread( ThreadGroupUtils.getRootThreadGroup(), t, "TraceReporter", 0, false);
*** 428,437 **** --- 459,469 ---- }); } public void run() { PrintStream ps = getTraceOutputFile(); + if (traceMap != null) { Iterator<Map.Entry<Object, int[]>> iterator = traceMap.entrySet().iterator(); long total = 0; int numprims = 0; while (iterator.hasNext()) {
*** 439,464 **** Object prim = me.getKey(); int[] count = me.getValue(); if (count[0] == 1) { ps.print("1 call to "); } else { ! ps.print(count[0]+" calls to "); } ps.println(prim); numprims++; total += count[0]; } if (numprims == 0) { ps.println("No graphics primitives executed"); } else if (numprims > 1) { ! ps.println(total+" total calls to "+ ! numprims+" different primitives"); } } } - public static synchronized void tracePrimitive(Object prim) { if ((traceflags & TRACECOUNTS) != 0) { if (traceMap == null) { traceMap = new HashMap<>(); TraceReporter.setShutdownHook(); } --- 471,501 ---- Object prim = me.getKey(); int[] count = me.getValue(); if (count[0] == 1) { ps.print("1 call to "); } else { ! ps.print(count[0] + " calls to "); } ps.println(prim); numprims++; total += count[0]; } if (numprims == 0) { ps.println("No graphics primitives executed"); } else if (numprims > 1) { ! ps.println(total + " total calls to " + ! numprims + " different primitives"); ! } ! } } } + + public synchronized static void tracePrimitive(Object prim) { + if ((traceflags & TRACEPNAME) != 0) { + if (!prim.toString().contains(pname)) return; } if ((traceflags & TRACECOUNTS) != 0) { if (traceMap == null) { traceMap = new HashMap<>(); TraceReporter.setShutdownHook(); }
*** 476,485 **** --- 513,556 ---- } ps.println(prim); } } + public synchronized static void traceImplPrimitive(Object prim, Object msg) { + if ((traceflags & TRACEPNAME) != 0) { + if (!prim.toString().contains(pname)) return; + } + + if ((traceflags & TRACEPIMPL) != 0) { + PrintStream ps = getTraceOutputFile(); + if ((traceflags & TRACETIMESTAMP) != 0) { + ps.print(System.currentTimeMillis()); + } + ps.println(prim + " : " + msg); + } + } + + + public synchronized static void tracePrimitiveTime(Object prim, long time) { + if ((traceflags & TRACEPNAME) != 0) { + if (!prim.toString().contains(pname)) return; + } + if (time > treshold && (traceflags & TRACEPTIME) != 0 && (traceflags & TRACELOG) != 0) { + PrintStream ps = getTraceOutputFile(); + ps.println(prim + " time: " + time); + if (verbose) { + final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + if (stackTrace.length > 3) { + for (int i = 3; i < stackTrace.length; i++) { + ps.println(" " + stackTrace[i].toString()); + } + } + ps.println(); + } + } + } + protected void setupGeneralBinaryOp(GeneralBinaryOp gbo) { int primID = gbo.getPrimTypeID(); String methodSignature = gbo.getSignature(); SurfaceType srctype = gbo.getSourceType(); CompositeType comptype = gbo.getCompositeType();
< prev index next >