Search in sources :

Example 1 with ProfilingData

use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.

the class ProfilingContainerResponseFilter method filter.

@Override
public ContainerResponse filter(final ContainerRequest request, final ContainerResponse response) {
    try {
        final ProfilingData rawData = Profiling.getPerThreadProfilingData();
        if (rawData != null) {
            if (rawData.getProfileFeature().isProfilingJAXRS()) {
                rawData.addEnd(ProfilingFeatureType.JAXRS, request.getPath());
            }
            final ProfilingDataJson profilingData = new ProfilingDataJson(rawData);
            final String value;
            try {
                value = mapper.writeValueAsString(profilingData);
                response.getHttpHeaders().add(PROFILING_HEADER_RESP, value);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
    } finally {
        Profiling.resetPerThreadProfilingData();
    }
    return response;
}
Also used : ProfilingDataJson(org.killbill.billing.jaxrs.json.ProfilingDataJson) ProfilingData(org.killbill.commons.profiling.ProfilingData) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with ProfilingData

use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.

the class ProfilingContainerResponseFilter method filter.

@Override
public ContainerRequest filter(final ContainerRequest request) {
    final List<String> profilingHeaderRequests = request.getRequestHeader(PROFILING_HEADER_REQ);
    final String profilingHeaderRequest = (profilingHeaderRequests == null || profilingHeaderRequests.isEmpty()) ? null : profilingHeaderRequests.get(0);
    if (profilingHeaderRequest != null) {
        try {
            Profiling.setPerThreadProfilingData(profilingHeaderRequest);
            // If we need to profile JAXRS let's do it...
            final ProfilingData profilingData = Profiling.getPerThreadProfilingData();
            if (profilingData.getProfileFeature().isProfilingJAXRS()) {
                profilingData.addStart(ProfilingFeatureType.JAXRS, request.getPath());
            }
        } catch (IllegalArgumentException e) {
            log.info("Profiling data output {} is not supported, profiling NOT enabled", profilingHeaderRequest);
        }
    }
    return request;
}
Also used : ProfilingData(org.killbill.commons.profiling.ProfilingData)

Example 3 with ProfilingData

use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.

the class PluginDispatcher method dispatchWithTimeout.

@VisibleForTesting
ReturnType dispatchWithTimeout(final Callable<PluginDispatcherReturnType<ReturnType>> task, final long timeout, final TimeUnit unit) throws TimeoutException, ExecutionException, InterruptedException {
    final ExecutorService pluginExecutor = paymentExecutors.getPluginExecutorService();
    // Wrap existing callable to keep the original requestId
    final Callable<PluginDispatcherReturnType<ReturnType>> callableWithRequestData = new CallableWithRequestData(Request.getPerThreadRequestData(), UUIDs.getRandom(), ThreadContext.getSecurityManager(), ThreadContext.getSubject(), MDC.getCopyOfContextMap(), task);
    final Future<PluginDispatcherReturnType<ReturnType>> future = pluginExecutor.submit(callableWithRequestData);
    final PluginDispatcherReturnType<ReturnType> pluginDispatcherResult = future.get(timeout, unit);
    if (pluginDispatcherResult instanceof WithProfilingPluginDispatcherReturnType) {
        // Transfer state from dispatch thread into current one.
        final ProfilingData currentThreadProfilingData = Profiling.getPerThreadProfilingData();
        if (currentThreadProfilingData != null) {
            currentThreadProfilingData.merge(((WithProfilingPluginDispatcherReturnType) pluginDispatcherResult).getProfilingData());
        }
    }
    return pluginDispatcherResult.getReturnType();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ProfilingData(org.killbill.commons.profiling.ProfilingData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ProfilingData (org.killbill.commons.profiling.ProfilingData)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ExecutorService (java.util.concurrent.ExecutorService)1 ProfilingDataJson (org.killbill.billing.jaxrs.json.ProfilingDataJson)1