Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.oak.benchmark.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.lang.instrument.Instrumentation;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* A simple CPU profiling tool similar to java -Xrunhprof. It can be used
* in-process (to profile the current application) or as a standalone program
* (to profile a different process).
*/
public class Profiler implements Runnable {
private static Instrumentation instrumentation;
private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n");
private static final int MAX_ELEMENTS = 1000;
public int interval = 2;
public int depth = 48;
public boolean paused;
public boolean sumClasses;
private int pid;
private final String[] ignoreLines = {};
private final String[] ignorePackages = (
"java," +
"sun," +
"com.sun."
).split(",");
private final String[] ignoreThreads = (
"java.lang.Object.wait," +
"java.lang.Thread.dumpThreads," +
"java.lang.Thread.getThreads," +
"java.lang.Thread.sleep," +
"java.lang.UNIXProcess.waitForProcessExit," +
"java.net.PlainSocketImpl.accept," +
"java.net.PlainSocketImpl.socketAccept," +
"java.net.SocketInputStream.socketRead," +
"java.net.SocketOutputStream.socketWrite," +
"sun.awt.windows.WToolkit.eventLoop," +
"sun.misc.Unsafe.park," +
"dalvik.system.VMStack.getThreadStackTrace," +
"dalvik.system.NativeStart.run"
).split(",");
private volatile boolean stop;
private final HashMap counts = new HashMap();
/**
* The summary (usually one entry per package, unless sumClasses is enabled,
* in which case it's one entry per class).
*/
private final HashMap summary = new HashMap();
private int minCount = 1;
private int total;
private Thread thread;
private long start;
private long time;
/**
* This method is called when the agent is installed.
*
* @param agentArgs the agent arguments
* @param inst the instrumentation object
*/
public static void premain(String agentArgs, Instrumentation inst) {
instrumentation = inst;
}
/**
* Get the instrumentation object if started as an agent.
*
* @return the instrumentation, or null
*/
public static Instrumentation getInstrumentation() {
return instrumentation;
}
/**
* Run the command line version of the profiler. The JDK (jps and jstack)
* need to be in the path.
*
* @param args the process id of the process - if not set the java processes
* are listed
*/
public static void main(String... args) {
new Profiler().run(args);
}
private void run(String... args) {
if (args.length == 0) {
System.out.println("Show profiling data");
System.out.println("Usage: java " + getClass().getName() + " ");
System.out.println("Processes:");
String processes = exec("jps", "-l");
System.out.println(processes);
return;
}
pid = Integer.parseInt(args[0]);
start = System.currentTimeMillis();
long last = 0;
while (true) {
tick();
long t = System.currentTimeMillis();
if (t - last > 5000) {
time = System.currentTimeMillis() - start;
System.out.println(getTopTraces(3));
last = t;
}
}
}
private static List