All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.runtime.profile.builtin.HtmlProfilePrinter Maven / Gradle / Ivy

There is a newer version: 9.4.9.0
Show newest version
/***** BEGIN LICENSE BLOCK *****
 * Version: EPL 1.0/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Eclipse Public
 * License Version 1.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.eclipse.org/legal/epl-v10.html
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the EPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the EPL, the GPL or the LGPL.
 ***** END LICENSE BLOCK *****/
package org.jruby.runtime.profile.builtin;

import org.jruby.util.collections.IntHashMap;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;

public class HtmlProfilePrinter extends ProfilePrinter {
  private static final long LIMIT = 100000000;
    
  public HtmlProfilePrinter(ProfileData profileData) {
      super(profileData);
  }
    
  HtmlProfilePrinter(ProfileData profileData, Invocation topInvocation) {
      super(profileData, topInvocation);
  }

  public void printHeader(PrintStream out) {
    out.println(head);
    out.println("");
  }

  public void printFooter(PrintStream out) {
    out.println("");
    out.println("");
  }

  @Override
  public void printProfile(PrintStream out, boolean first) {
    final Invocation topInvocation = getTopInvocation();
    
    out.printf("

Profile Report: %s

\n", getThreadName()); out.println("

Total time: " + nanoString(topInvocation.getDuration()) + "

"); out.println("\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " "); IntHashMap methods = methodData(topInvocation); MethodData[] sortedMethods = methods.values().toArray(new MethodData[methods.size()]); Arrays.sort(sortedMethods, new Comparator() { public int compare(MethodData md1, MethodData md2) { long time1 = md1.totalTime(); long time2 = md2.totalTime(); return time1 == time2 ? 0 : (time1 < time2 ? 1 : -1); } }); for (final MethodData data : sortedMethods) { if (!isProfilerInvocation(data.invocations.get(0))) { out.println(""); int serial = data.serialNumber; if (serial != 0) { Integer[] parentSerials = parentSerials(data); if (parentSerials.length > 0) { for (int parentSerial : parentSerials) { printInvocationFromParent(out, data, parentSerial, methodName(parentSerial), data.rootInvocationsFromParent(parentSerial)); } } } String displayName = methodName(serial); if (data.totalTime() >= LIMIT) { out.println(""); if (topInvocation.getDuration() == 0) { out.println(" "); out.println(" "); } else { out.println(" "); out.println(" "); } printTimingCells(out, data); out.println(" "); out.println(" "); out.println(""); } int[] childSerialsInts = data.children(); Integer[] childSerials = new Integer[childSerialsInts.length]; for (int i = 0; i < childSerialsInts.length; i++) { childSerials[i] = childSerialsInts[i]; } Arrays.sort(childSerials, new Comparator() { public int compare(Integer child1, Integer child2) { long time1 = data.rootInvocationsOfChild(child1).totalTime(); long time2 = data.rootInvocationsOfChild(child2).totalTime(); return time1 == time2 ? 0 : (time1 < time2 ? 1 : -1); } }); if (childSerials.length > 0) { for (int childSerial : childSerials) { if (!isThisProfilerInvocation(childSerial)) { String callerName = methodName(childSerial); InvocationSet invs = data.rootInvocationsOfChild(childSerial); printInvocationOfChild(out, methods, data, childSerial, callerName, invs); } } } } } out.println("
%Total %Self Total Self Children CallsName
100%100%" + Long.toString(data.totalTime() * 100 / topInvocation.getDuration()) + "%" + Long.toString(data.selfTime() * 100 / topInvocation.getDuration()) + "%" + Integer.toString(data.totalCalls()) + "" + methodAnchor(displayName) + "
"); } private void printInvocationOfChild(PrintStream out, IntHashMap methods, MethodData data, int childSerial, String callerName, InvocationSet invs) { out.print(""); if (invs.totalTime() < LIMIT) { return; } out.println(""); out.println(" "); out.println(" "); printTimingCells(out, invs); out.println(" " + Integer.toString(data.invocationsOfChild(childSerial).totalCalls()) + "/" + Integer.toString(methods.get(childSerial).totalCalls()) + ""); out.println(" " + linkToMethod(callerName) + ""); out.println(""); } private void printInvocationFromParent(PrintStream out, MethodData data, int parentSerial, String callerName, InvocationSet invs) { if (invs.totalTime() < LIMIT) { return; } out.println(""); out.println(" "); out.println(" "); printTimingCells(out, invs); out.println(" " + Integer.toString(data.invocationsFromParent(parentSerial).totalCalls()) + "/" + Integer.toString(data.totalCalls()) + ""); out.println(" " + linkToMethod(callerName) + ""); out.println(""); } private String linkToMethod(String callerName) { return "" + callerName + ""; } private String methodAnchor(String callerName) { return "" + callerName + ""; } private void printTimingCells(PrintStream out, InvocationSet invs) { out.println(" " + nanoString(invs.totalTime()) + ""); out.println(" " + nanoString(invs.selfTime()) + ""); out.println(" " + nanoString(invs.childTime()) + ""); } private Integer[] parentSerials(final MethodData data) { int[] parentSerialsInts = data.parents(); Integer[] parentSerials = new Integer[parentSerialsInts.length]; for (int i = 0; i < parentSerialsInts.length; i++) { parentSerials[i] = parentSerialsInts[i]; } Arrays.sort(parentSerials, new Comparator() { public int compare(Integer parent1, Integer parent2) { long time1 = data.rootInvocationsFromParent(parent1).totalTime(); long time2 = data.rootInvocationsFromParent(parent2).totalTime(); return time1 == time2 ? 0 : (time1 < time2 ? -1 : 1); } }); return parentSerials; } String head = "\n" + "\n" + "\n" + " \n" + " \n"; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy