Package org.apache.hadoop.hbase.http
Class ProfileServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.hadoop.hbase.http.ProfileServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
Servlet that runs async-profiler as a web endpoint.
Query parameters:
event- profiling event: cpu|alloc|lock|cache-misses etc. (default: cpu)duration- run profiling for N seconds, clamped to [1, 3600] (default: 10)interval- sampling interval in nanoseconds (long)jstackdepth- maximum Java stack depth (integer)bufsize- frame buffer size (long); honored only by BinaryBackendthread- profile different threads separately (flag)simple- simple class names instead of FQN (flag)output- output format: summary|traces|flat|collapsed|tree|jfr|html (default: html)width- flame graph width in pixels; honored only by BinaryBackendheight- flame graph frame height in pixels; honored only by BinaryBackendminwidth- skip frames smaller than this width in pixels (double)reverse- generate stack-reversed FlameGraph / Call tree (flag)pid- target process ID; LibraryBackend only supports the current JVM (returns 400 for other PIDs), BinaryBackend supports external PIDsrefreshDelay- extra seconds added to the auto-refresh delay (integer)last- instead of starting a new session, redirect to the most recently completed profiling result. Returns 404 if no result is cached yet. The last result is kept in memory for the lifetime of the JVM.
Examples:
# 30-second CPU profile (default) curl "http://localhost:10002/prof" # 1-minute allocation profile in tree format curl "http://localhost:10002/prof?event=alloc&output=tree&duration=60" # Redirect to the most recent profiling result curl "http://localhost:10002/prof?last"
Profiling is single-flight: only one session runs at a time. A second request while a session is active returns HTTP 409 Conflict with the URL of the last completed result (if any). Closing the browser tab does not cancel a running session — the stopper thread runs to completion on the server.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class(package private) static enum(package private) static enumstatic final class(package private) static final classImmutable record of a completed profiling session. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final ProfilerBackendprivate static final Stringprivate final longprivate static final intprivate static final ProfilerBackendprivate static final AtomicIntegerprivate static ProfileServlet.ProfileResultprivate static final org.slf4j.Logger(package private) static final int(package private) static final String(package private) static final intprivate static final Lockprivate static booleanprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancheckInstrumentationAccess(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) private Filevoiddestroy()protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) (package private) static voidCreatesOUTPUT_DIRwith permissions 0700 (owner-only) when the filesystem supports POSIX permissions, so other local users cannot plant symlinks or read profiling output.protected StringexecuteStart(ProfileServlet.ProfileRequest request, File outputFile) protected StringexecuteStop(ProfileServlet.ProfileRequest request, File outputFile) (package private) static Stringprivate ProfileServlet.EventgetEvent(javax.servlet.http.HttpServletRequest req) private IntegergetInteger(javax.servlet.http.HttpServletRequest req, String param, Integer defaultValue) private Longprivate DoublegetMinWidth(javax.servlet.http.HttpServletRequest req) private ProfileServlet.OutputgetOutput(javax.servlet.http.HttpServletRequest req) voidinit()static booleanReturns true if a profiler backend was detected at class-load time.parseProfileRequest(javax.servlet.http.HttpServletRequest req) (package private) static voidsetResponseHeader(javax.servlet.http.HttpServletResponse response) private voidstartStopperThread(int durationSeconds, ProfileServlet.ProfileRequest request, File outputFile, String relativeUrl) private voidwriteAcceptedResponse(javax.servlet.http.HttpServletResponse resp, ProfileServlet.ProfileRequest request, String relativeUrl) private voidwriteError(javax.servlet.http.HttpServletResponse resp, int status, String message) Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceMethods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
serialVersionUID
- See Also:
-
LOG
-
ACCESS_CONTROL_ALLOW_METHODS
- See Also:
-
ALLOWED_METHODS
- See Also:
-
ACCESS_CONTROL_ALLOW_ORIGIN
- See Also:
-
CONTENT_TYPE_TEXT
- See Also:
-
DEFAULT_DURATION_SECONDS
- See Also:
-
MAX_DURATION_SECONDS
- See Also:
-
ID_GEN
-
OUTPUT_DIR
-
PROF_OUTPUT_MIN_BYTES
- See Also:
-
ASYNC_PROFILER_HOME_ENV
- See Also:
-
ASYNC_PROFILER_HOME_SYSTEM_PROPERTY
- See Also:
-
lastResult
-
DETECTED_BACKEND
-
profilerLock
-
profiling
-
currentPid
-
backend
-
-
Constructor Details
-
ProfileServlet
public ProfileServlet() -
ProfileServlet
ProfileServlet(ProfilerBackend backend)
-
-
Method Details
-
init
- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
ensureOutputDir
CreatesOUTPUT_DIRwith permissions 0700 (owner-only) when the filesystem supports POSIX permissions, so other local users cannot plant symlinks or read profiling output. No-ops if the directory already exists. Silently skips the permission step on non-POSIX filesystems (Windows, some container runtimes).- Throws:
IOException
-
getAsyncProfilerHome
-
isAvailable
Returns true if a profiler backend was detected at class-load time. Detection is a one-shot operation: a library added to the classpath after the JVM starts requires a restart. A backend that resolved successfully here may still fail on first use if the native binary is incompatible with the OS/kernel — that error surfaces at request time via thecatch(Error | RuntimeException)block indoGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse). -
parseProfileRequest
-
executeStart
protected String executeStart(ProfileServlet.ProfileRequest request, File outputFile) throws IOException - Throws:
IOException
-
executeStop
protected String executeStop(ProfileServlet.ProfileRequest request, File outputFile) throws IOException - Throws:
IOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException - Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
IOException
-
startStopperThread
private void startStopperThread(int durationSeconds, ProfileServlet.ProfileRequest request, File outputFile, String relativeUrl) -
checkInstrumentationAccess
private boolean checkInstrumentationAccess(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException - Throws:
IOException
-
destroy
- Specified by:
destroyin interfacejavax.servlet.Servlet- Overrides:
destroyin classjavax.servlet.GenericServlet
-
writeError
private void writeError(javax.servlet.http.HttpServletResponse resp, int status, String message) throws IOException - Throws:
IOException
-
createOutputFile
- Throws:
IOException
-
writeAcceptedResponse
private void writeAcceptedResponse(javax.servlet.http.HttpServletResponse resp, ProfileServlet.ProfileRequest request, String relativeUrl) throws IOException - Throws:
IOException
-
getInteger
private Integer getInteger(javax.servlet.http.HttpServletRequest req, String param, Integer defaultValue) -
getLong
-
getMinWidth
-
getEvent
-
getOutput
-
setResponseHeader
-