mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
move one/profiler java files to spy module, avoid load so profble. #961
This commit is contained in:
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Andrei Pangin
|
||||
*
|
||||
* Licensed 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 one.profiler;
|
||||
|
||||
/**
|
||||
* Java API for in-process profiling. Serves as a wrapper around
|
||||
* async-profiler native library. This class is a singleton.
|
||||
* The first call to {@link #getInstance()} initiates loading of
|
||||
* libasyncProfiler.so.
|
||||
*/
|
||||
public class AsyncProfiler implements AsyncProfilerMXBean {
|
||||
private static AsyncProfiler instance;
|
||||
|
||||
private final String version;
|
||||
|
||||
private AsyncProfiler() {
|
||||
this.version = version0();
|
||||
}
|
||||
|
||||
public static AsyncProfiler getInstance() {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
public static synchronized AsyncProfiler getInstance(String libPath) {
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
if (libPath == null) {
|
||||
System.loadLibrary("asyncProfiler");
|
||||
} else {
|
||||
System.load(libPath);
|
||||
}
|
||||
|
||||
instance = new AsyncProfiler();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start profiling
|
||||
*
|
||||
* @param event Profiling event, see {@link Events}
|
||||
* @param interval Sampling interval, e.g. nanoseconds for Events.CPU
|
||||
* @throws IllegalStateException If profiler is already running
|
||||
*/
|
||||
@Override
|
||||
public void start(String event, long interval) throws IllegalStateException {
|
||||
start0(event, interval, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start or resume profiling without resetting collected data.
|
||||
* Note that event and interval may change since the previous profiling session.
|
||||
*
|
||||
* @param event Profiling event, see {@link Events}
|
||||
* @param interval Sampling interval, e.g. nanoseconds for Events.CPU
|
||||
* @throws IllegalStateException If profiler is already running
|
||||
*/
|
||||
@Override
|
||||
public void resume(String event, long interval) throws IllegalStateException {
|
||||
start0(event, interval, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop profiling (without dumping results)
|
||||
*
|
||||
* @throws IllegalStateException If profiler is not running
|
||||
*/
|
||||
@Override
|
||||
public void stop() throws IllegalStateException {
|
||||
stop0();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of samples collected during the profiling session
|
||||
*
|
||||
* @return Number of samples
|
||||
*/
|
||||
@Override
|
||||
public native long getSamples();
|
||||
|
||||
/**
|
||||
* Get profiler agent version, e.g. "1.0"
|
||||
*
|
||||
* @return Version string
|
||||
*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an agent-compatible profiling command -
|
||||
* the comma-separated list of arguments described in arguments.cpp
|
||||
*
|
||||
* @param command Profiling command
|
||||
* @return The command result
|
||||
* @throws IllegalArgumentException If failed to parse the command
|
||||
* @throws java.io.IOException If failed to create output file
|
||||
*/
|
||||
@Override
|
||||
public String execute(String command) throws IllegalArgumentException, java.io.IOException {
|
||||
return execute0(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump profile in 'collapsed stacktraces' format
|
||||
*
|
||||
* @param counter Which counter to display in the output
|
||||
* @return Textual representation of the profile
|
||||
*/
|
||||
@Override
|
||||
public String dumpCollapsed(Counter counter) {
|
||||
return dumpCollapsed0(counter.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump collected stack traces
|
||||
*
|
||||
* @param maxTraces Maximum number of stack traces to dump. 0 means no limit
|
||||
* @return Textual representation of the profile
|
||||
*/
|
||||
@Override
|
||||
public String dumpTraces(int maxTraces) {
|
||||
return dumpTraces0(maxTraces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump flat profile, i.e. the histogram of the hottest methods
|
||||
*
|
||||
* @param maxMethods Maximum number of methods to dump. 0 means no limit
|
||||
* @return Textual representation of the profile
|
||||
*/
|
||||
@Override
|
||||
public String dumpFlat(int maxMethods) {
|
||||
return dumpFlat0(maxMethods);
|
||||
}
|
||||
|
||||
private native void start0(String event, long interval, boolean reset) throws IllegalStateException;
|
||||
private native void stop0() throws IllegalStateException;
|
||||
private native String execute0(String command) throws IllegalArgumentException, java.io.IOException;
|
||||
private native String dumpCollapsed0(int counter);
|
||||
private native String dumpTraces0(int maxTraces);
|
||||
private native String dumpFlat0(int maxMethods);
|
||||
private native String version0();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Andrei Pangin
|
||||
*
|
||||
* Licensed 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 one.profiler;
|
||||
|
||||
/**
|
||||
* AsyncProfiler interface for JMX server.
|
||||
* How to register AsyncProfiler MBean:
|
||||
*
|
||||
* <pre>{@code
|
||||
* ManagementFactory.getPlatformMBeanServer().registerMBean(
|
||||
* AsyncProfiler.getInstance(),
|
||||
* new ObjectName("one.profiler:type=AsyncProfiler")
|
||||
* );
|
||||
* }</pre>
|
||||
*/
|
||||
public interface AsyncProfilerMXBean {
|
||||
void start(String event, long interval) throws IllegalStateException;
|
||||
void resume(String event, long interval) throws IllegalStateException;
|
||||
void stop() throws IllegalStateException;
|
||||
|
||||
long getSamples();
|
||||
String getVersion();
|
||||
|
||||
String execute(String command) throws IllegalArgumentException, java.io.IOException;
|
||||
|
||||
String dumpCollapsed(Counter counter);
|
||||
String dumpTraces(int maxTraces);
|
||||
String dumpFlat(int maxMethods);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Andrei Pangin
|
||||
*
|
||||
* Licensed 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 one.profiler;
|
||||
|
||||
/**
|
||||
* Which metrics to use when generating profile in collapsed stack traces format.
|
||||
*/
|
||||
public enum Counter {
|
||||
SAMPLES,
|
||||
TOTAL
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Andrei Pangin
|
||||
*
|
||||
* Licensed 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 one.profiler;
|
||||
|
||||
/**
|
||||
* Predefined event names to use in {@link AsyncProfiler#start(String, long)}
|
||||
*/
|
||||
public class Events {
|
||||
public static final String CPU = "cpu";
|
||||
public static final String ALLOC = "alloc";
|
||||
public static final String LOCK = "lock";
|
||||
public static final String WALL = "wall";
|
||||
public static final String ITIMER = "itimer";
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
/**
|
||||
* from https://github.com/jvm-profiling-tools/async-profiler
|
||||
*/
|
||||
package one.profiler;
|
||||
Reference in New Issue
Block a user