diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/BytecodeUtils.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/BytecodeUtils.java index ca321695e..127e61592 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/BytecodeUtils.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/BytecodeUtils.java @@ -78,7 +78,7 @@ public final class BytecodeUtils { if (closeable != null) { try { closeable.close(); - } catch (IOException e) { + } catch (IOException ignore) { // skip } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperLatestJobWorker.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperLatestJobWorker.java index 9a37b1936..4adb8fea8 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperLatestJobWorker.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperLatestJobWorker.java @@ -280,8 +280,9 @@ public class ZookeeperLatestJobWorker implements Runnable { while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.isStarted()) { try { lock.wait(waitUnitTime); - } catch (InterruptedException e) { - + } catch (InterruptedException ignore) { +// Thread.currentThread().interrupt(); +// TODO check Interrupted state } } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassLoaderUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassLoaderUtils.java index 025f9445a..0f5be3eaf 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassLoaderUtils.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassLoaderUtils.java @@ -30,7 +30,7 @@ public final class ClassLoaderUtils { if (contextClassLoader != null) { return contextClassLoader; } - } catch (Throwable e) { + } catch (Throwable ignore) { // skip } // 파라미터로 ClassLoader를 전달 받으면 security exception 의 발생타이밍이 다르다. diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassUtils.java index 84a55b417..389f0b7c6 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassUtils.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/ClassUtils.java @@ -25,7 +25,7 @@ public final class ClassUtils { } try { return (classLoaderToUse.loadClass(name) != CLASS_NOT_LOADED); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException ignore) { // Swallow } return false; diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/NetUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/NetUtils.java index d7ec23127..8c771af30 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/util/NetUtils.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/NetUtils.java @@ -41,7 +41,8 @@ public final class NetUtils { URI uri = new URI("pinpoint://" + address); return new InetSocketAddress(uri.getHost(), uri.getPort()); - } catch (URISyntaxException e) { + } catch (URISyntaxException ignore) { + // skip } return null; @@ -54,7 +55,8 @@ public final class NetUtils { if (validationIpV4FormatAddress(localIp)) { return localIp; } - } catch (UnknownHostException e) { + } catch (UnknownHostException ignore) { + // skip } return LOOPBACK_ADDRESS_V4; } @@ -69,7 +71,8 @@ public final class NetUtils { Enumeration interfaces = null; try { interfaces = NetworkInterface.getNetworkInterfaces(); - } catch (SocketException e) { + } catch (SocketException ignore) { + // skip } if (interfaces == null) { @@ -104,7 +107,8 @@ public final class NetUtils { return true; } return false; - } catch (Exception e) { + } catch (Exception ignore) { + // skip } return true; } @@ -130,7 +134,8 @@ public final class NetUtils { } return true; - } catch (Exception e) { + } catch (Exception ignore) { + //skip } return false; @@ -149,7 +154,8 @@ public final class NetUtils { } } return true; - } catch (NumberFormatException e) { + } catch (NumberFormatException ignore) { + // skip } return false; diff --git a/examples/bin/start-testapp.sh b/examples/bin/start-testapp.sh index 729f872ed..7ed1902ed 100755 --- a/examples/bin/start-testapp.sh +++ b/examples/bin/start-testapp.sh @@ -191,9 +191,9 @@ function func_start_pinpoint_testapp echo "---$TESTAPP_IDENTIFIER initialization started. pid=$pid.---" end_count=0 - process_status=`curl $check_url 2>/dev/null` + process_status=`curl $check_url 2>/dev/null | grep 'getCurrentTimestamp'` - until [[ $process_status =~ ^-?[0-9]+$ ]]; + while [ -z $process_status]; do wait_time=`expr $end_count \* $UNIT_TIME` echo "starting $TESTAPP_IDENTIFIER. $wait_time sec/$CLOSE_WAIT_TIME sec(close wait limit)." @@ -204,7 +204,7 @@ function func_start_pinpoint_testapp sleep $UNIT_TIME end_count=`expr $end_count + 1` - process_status=`curl $check_url 2>/dev/null` + process_status=`curl $check_url 2>/dev/null | grep 'getCurrentTimestamp'` done diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/ApisController.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/ApisController.java index 400545502..be902189c 100644 --- a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/ApisController.java +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/ApisController.java @@ -1,5 +1,8 @@ package com.navercorp.pinpoint.testapp.controller; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.SortedSet; @@ -11,6 +14,7 @@ import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.method.HandlerMethod; @@ -20,46 +24,129 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl /** * @author koo.taejin */ +import com.navercorp.pinpoint.testapp.util.Description; + @Controller(value = "apisController") public class ApisController { private final RequestMappingHandlerMapping handlerMapping; - - private final Map> apiMappings = new TreeMap>(String.CASE_INSENSITIVE_ORDER); - + + private final Map> apiMappings = new TreeMap>(String.CASE_INSENSITIVE_ORDER); + @Autowired public ApisController(RequestMappingHandlerMapping handlerMapping) { this.handlerMapping = handlerMapping; } - + @PostConstruct private void initApiMappings() { Map requestMappedHandlers = this.handlerMapping.getHandlerMethods(); for (Map.Entry requestMappedHandlerEntry : requestMappedHandlers.entrySet()) { RequestMappingInfo requestMappingInfo = requestMappedHandlerEntry.getKey(); HandlerMethod handlerMethod = requestMappedHandlerEntry.getValue(); - + Class handlerMethodBeanClazz = handlerMethod.getBeanType(); if (handlerMethodBeanClazz == this.getClass()) { continue; } - + String controllerName = handlerMethodBeanClazz.getSimpleName(); Set mappedRequests = requestMappingInfo.getPatternsCondition().getPatterns(); - - SortedSet alreadyMappedRequests = this.apiMappings.get(controllerName); + + SortedSet alreadyMappedRequests = this.apiMappings.get(controllerName); if (alreadyMappedRequests == null) { - alreadyMappedRequests = new TreeSet(String.CASE_INSENSITIVE_ORDER); + alreadyMappedRequests = new TreeSet(RequestMappedUri.MAPPED_URI_ORDER); this.apiMappings.put(controllerName, alreadyMappedRequests); } - alreadyMappedRequests.addAll(mappedRequests); + alreadyMappedRequests.addAll(createRequestMappedApis(handlerMethod, mappedRequests)); } } - @RequestMapping(value = {"/index.html", "/apis"}, method = RequestMethod.GET) + private Set createRequestMappedApis(HandlerMethod handlerMethod, Set mappedUris) { + if (CollectionUtils.isEmpty(mappedUris)) { + return Collections.emptySet(); + } + Set requestMappedUris = new HashSet(mappedUris.size()); + Description description = handlerMethod.getMethodAnnotation(Description.class); + for (String mappedUri : mappedUris) { + requestMappedUris.add(new RequestMappedUri(mappedUri, description)); + } + return requestMappedUris; + } + + @RequestMapping(value = { "/index.html", "/apis" }, method = RequestMethod.GET) public String apis(Model model) { model.addAttribute("apiMappings", this.apiMappings); return "apis"; } - + + public static class RequestMappedUri { + + private final String mappedUri; + private final String description; + + private RequestMappedUri(String mappedUri, Description description) { + if (mappedUri == null) { + throw new IllegalArgumentException("mappedUri must not be null"); + } + this.mappedUri = mappedUri; + this.description = description == null ? "" : description.value(); + } + + public String getMappedUri() { + return this.mappedUri; + } + + public String getDescription() { + return this.description; + } + + private static final Comparator MAPPED_URI_ORDER = new Comparator() { + @Override + public int compare(RequestMappedUri arg0, RequestMappedUri arg1) { + if (arg0 == null && arg1 == null) return 0; + if (arg1 == null) return -1; + if (arg0 == null) return 1; + return String.CASE_INSENSITIVE_ORDER.compare(arg0.mappedUri, arg1.mappedUri); + } + }; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((mappedUri == null) ? 0 : mappedUri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RequestMappedUri other = (RequestMappedUri) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (mappedUri == null) { + if (other.mappedUri != null) + return false; + } else if (!mappedUri.equals(other.mappedUri)) + return false; + return true; + } + + @Override + public String toString() { + return "RequestMappedUri [mappedUri=" + mappedUri + ", description=" + description + "]"; + } + + } + } diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/CallSelfController.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/CallSelfController.java new file mode 100644 index 000000000..a1768debe --- /dev/null +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/CallSelfController.java @@ -0,0 +1,84 @@ +package com.navercorp.pinpoint.testapp.controller; + +import java.net.InetAddress; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.http.client.utils.URIBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.navercorp.pinpoint.testapp.service.remote.RemoteService; +import com.navercorp.pinpoint.testapp.util.Description; + +@Controller +@RequestMapping("/callSelf") +public class CallSelfController { + + private static final String GET_CURRENT_TIMESTAMP_PATH = "/getCurrentTimestamp"; + private static final String GET_GEO_CODE_PATH = "/httpclient4/getGeoCode"; + private static final String GET_TWITTER_URL_COUNT_PATH = "/httpclient4/getTwitterUrlCount"; + + private static final String DEFAULT_LOCAL_IP = "127.0.0.1"; + private static final String LOCAL_IP = getLocalHostIp(); + + private static String getLocalHostIp() { + try { + final InetAddress localHost = InetAddress.getLocalHost(); + return localHost.getHostAddress(); + } catch (UnknownHostException e) { + } + return DEFAULT_LOCAL_IP; + } + + @Autowired + @Qualifier("httpRemoteService") + RemoteService remoteService; + + @RequestMapping("/getCurrentTimestamp") + @ResponseBody + @Description("Calls self for " + GET_CURRENT_TIMESTAMP_PATH + " over HTTP.") + public Map getCurrentTimeStamp(HttpServletRequest request) throws Exception { + String url = createTargetUrl(request, GET_CURRENT_TIMESTAMP_PATH); + @SuppressWarnings("unchecked") + Map response = remoteService.get(url, Map.class); + return response; + } + + @RequestMapping("/httpclient4/getGeoCode") + @ResponseBody + @Description("Calls self for " + GET_GEO_CODE_PATH + " over HTTP.") + public Map httpClient4GetGeoCode(HttpServletRequest request) throws Exception { + String url = createTargetUrl(request, GET_GEO_CODE_PATH); + @SuppressWarnings("unchecked") + Map response = remoteService.get(url, Map.class); + return response; + } + + @RequestMapping("/httpclient4/getTwitterUrlCount") + @ResponseBody + @Description("Calls self for " + GET_TWITTER_URL_COUNT_PATH + " over HTTP.") + public Map httpClient4GetTwitterUrlCount(HttpServletRequest request) throws Exception { + String url = createTargetUrl(request, GET_TWITTER_URL_COUNT_PATH); + @SuppressWarnings("unchecked") + Map response = remoteService.get(url, Map.class); + return response; + } + + private static final String createTargetUrl(final HttpServletRequest request, final String path) throws URISyntaxException { + return new URIBuilder() + .setScheme("http") + .setHost(LOCAL_IP) + .setPort(request.getLocalPort()) + .setPath(path + ".pinpoint") + .build() + .toString(); + } + +} diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/HttpClient4Controller.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/HttpClient4Controller.java index 1f1f420f7..df827002e 100644 --- a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/HttpClient4Controller.java +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/HttpClient4Controller.java @@ -2,6 +2,8 @@ package com.navercorp.pinpoint.testapp.controller; import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,40 +23,43 @@ public class HttpClient4Controller { private static final String GOOGLE_GEOCODE_URL = "http://maps.googleapis.com/maps/api/geocode/json"; private static final String TWITTER_URL_COUNT_URL = "http://urls.api.twitter.com/1/urls/count.json"; - private static final String DEFAULT_GET_GEOCODE_ADDRESS = "Gyeonggi-do, Seongnam-si, Bundang-gu, Jeongja-dong, 178-1"; private static final String DEFAULT_GET_TWITTER_URL_COUNT_URL = "http://www.naver.com"; - RemoteService remoteOperations = new HttpRemoteService(); + @Autowired + @Qualifier("httpRemoteService") + RemoteService remoteService; @RequestMapping("/getGeoCode") - @Description("") @ResponseBody + @Description("HTTP GET to " + GOOGLE_GEOCODE_URL) public Map getGeoCode(@RequestParam(defaultValue = DEFAULT_GET_GEOCODE_ADDRESS, required = false) String address) throws Exception { LinkedMultiValueMap params = new LinkedMultiValueMap(); params.add("address", address); params.add("sensor", "false"); - return remoteOperations.get(GOOGLE_GEOCODE_URL, params, Map.class); + return remoteService.get(GOOGLE_GEOCODE_URL, params, Map.class); } @RequestMapping("/getTwitterUrlCount") @ResponseBody + @Description("HTTP GET to " + TWITTER_URL_COUNT_URL) public Map getTwitterUrlCount(@RequestParam(defaultValue = DEFAULT_GET_TWITTER_URL_COUNT_URL, required = false) String url) throws Exception { LinkedMultiValueMap params = new LinkedMultiValueMap(); params.add("url", url); - return remoteOperations.get(TWITTER_URL_COUNT_URL, params, Map.class); + return remoteService.get(TWITTER_URL_COUNT_URL, params, Map.class); } @RequestMapping("/getTwitterUrlCountByPost") @ResponseBody + @Description("HTTP POST to " + TWITTER_URL_COUNT_URL) public Map getTwitterUrlCountByPost(@RequestParam(defaultValue = DEFAULT_GET_TWITTER_URL_COUNT_URL, required = false) String url) throws Exception { LinkedMultiValueMap params = new LinkedMultiValueMap(); params.add("url", url); - return remoteOperations.post(TWITTER_URL_COUNT_URL, params, Map.class); + return remoteService.post(TWITTER_URL_COUNT_URL, params, Map.class); } } diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/SimpleController.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/SimpleController.java index 404b21077..c51c041c4 100644 --- a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/SimpleController.java +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/SimpleController.java @@ -1,17 +1,14 @@ package com.navercorp.pinpoint.testapp.controller; -import java.lang.ref.WeakReference; -import java.math.BigDecimal; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.concurrent.CountDownLatch; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import com.navercorp.pinpoint.testapp.util.Description; + /** * @author koo.taejin */ @@ -20,6 +17,7 @@ public class SimpleController { @RequestMapping("/getCurrentTimestamp") @ResponseBody + @Description("Returns the server's current timestamp.") public Map getCurrentTimestamp() { Map map = new HashMap(); map.put("getCurrentTimestamp", System.currentTimeMillis()); @@ -27,99 +25,9 @@ public class SimpleController { return map; } - @RequestMapping("/consumeCpu") - @ResponseBody - public Map consumeCpu() throws InterruptedException { - int cpuCount = Runtime.getRuntime().availableProcessors(); - int threadSize = Math.max(1, cpuCount - 1); - - long limitTime = 10000; - CountDownLatch latch = new CountDownLatch(threadSize); - - for (int i = 0; i < threadSize; i++) { - Thread thread = new Thread(new ConsumeCpu(latch, limitTime)); - thread.setDaemon(true); - - thread.start(); - } - - latch.await(); - - Map map = new HashMap(); - map.put("message", "ok"); - - return map; - } - - class ConsumeCpu implements Runnable { - - private final CountDownLatch latch; - private final long limitTime; - - public ConsumeCpu(CountDownLatch latch, long limitTime) { - this.latch = latch; - this.limitTime = limitTime; - } - - @Override - public void run() { - long startTime = System.currentTimeMillis(); - - try { - BigDecimal decimal = new BigDecimal(0); - for (int num = 1; num < Integer.MAX_VALUE; num++) { - long currentTimeMillis = System.currentTimeMillis(); - - if (currentTimeMillis - startTime > limitTime) { - break; - } - - decimal.add(new BigDecimal(num)); - } - } finally { - latch.countDown(); - } - } - } - - @RequestMapping("/consumeMemory") - @ResponseBody - public Map consumeMemory() throws InterruptedException { - consumeMemory(1024 * 16, 20); - - Map map = new HashMap(); - map.put("message", "ok"); - - return map; - } - - - @RequestMapping("/consumeMemoryLarge") - @ResponseBody - public Map consumeMemoryLarge() throws InterruptedException { - consumeMemory(1024 * 16, 100); - - Map map = new HashMap(); - map.put("message", "ok"); - - return map; - } - - private void consumeMemory(int byteArraySize, int createMaxHeapCount) { - long heapSize = Runtime.getRuntime().maxMemory(); - - int count = (int) Math.max(1, (heapSize/byteArraySize) * createMaxHeapCount); - - List> weakReferece = new ArrayList>(); - for (int i = 0; i < count; i++) { - weakReferece.add(new WeakReference(new byte[byteArraySize])); - } - - System.gc(); - } - @RequestMapping("/sleep3") @ResponseBody + @Description("Call that takes 3 seconds to complete.") public Map sleep3() throws InterruptedException { Thread.sleep(3000); @@ -131,6 +39,7 @@ public class SimpleController { @RequestMapping("/sleep5") @ResponseBody + @Description("Call that takes 5 seconds to complete") public Map sleep5() throws InterruptedException { Thread.sleep(5000); @@ -142,6 +51,7 @@ public class SimpleController { @RequestMapping("/sleep7") @ResponseBody + @Description("Call that takes 7 seconds to complete") public Map sleep7() throws InterruptedException { Thread.sleep(7000); diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/StressController.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/StressController.java new file mode 100644 index 000000000..04b863b0d --- /dev/null +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/controller/StressController.java @@ -0,0 +1,112 @@ +package com.navercorp.pinpoint.testapp.controller; + +import java.lang.ref.WeakReference; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.navercorp.pinpoint.testapp.util.Description; + +@Controller +public class StressController { + + @RequestMapping("/consumeCpu") + @ResponseBody + @Description("Call that consumes a lot of cpu time.") + public Map consumeCpu() throws InterruptedException { + int cpuCount = Runtime.getRuntime().availableProcessors(); + int threadSize = Math.max(1, cpuCount - 1); + + long limitTime = 10000; + CountDownLatch latch = new CountDownLatch(threadSize); + + for (int i = 0; i < threadSize; i++) { + Thread thread = new Thread(new ConsumeCpu(latch, limitTime)); + thread.setDaemon(true); + + thread.start(); + } + + latch.await(); + + Map map = new HashMap(); + map.put("message", "ok"); + + return map; + } + + class ConsumeCpu implements Runnable { + + private final CountDownLatch latch; + private final long limitTime; + + public ConsumeCpu(CountDownLatch latch, long limitTime) { + this.latch = latch; + this.limitTime = limitTime; + } + + @Override + public void run() { + long startTime = System.currentTimeMillis(); + + try { + BigDecimal decimal = new BigDecimal(0); + for (int num = 1; num < Integer.MAX_VALUE; num++) { + long currentTimeMillis = System.currentTimeMillis(); + + if (currentTimeMillis - startTime > limitTime) { + break; + } + + decimal.add(new BigDecimal(num)); + } + } finally { + latch.countDown(); + } + } + } + + @RequestMapping("/consumeMemory") + @ResponseBody + @Description("Call that consumes some memory that may trigger a few garbage collections.") + public Map consumeMemory() throws InterruptedException { + consumeMemory(1024 * 16, 20); + + Map map = new HashMap(); + map.put("message", "ok"); + + return map; + } + + @RequestMapping("/consumeMemoryLarge") + @ResponseBody + @Description("Call that consumes a large amount of memory that will most likely trigger multiple garbage collections.") + public Map consumeMemoryLarge() throws InterruptedException { + consumeMemory(1024 * 16, 100); + + Map map = new HashMap(); + map.put("message", "ok"); + + return map; + } + + private void consumeMemory(int byteArraySize, int createMaxHeapCount) { + long heapSize = Runtime.getRuntime().maxMemory(); + + int count = (int) Math.max(1, (heapSize/byteArraySize) * createMaxHeapCount); + + List> weakReferece = new ArrayList>(); + for (int i = 0; i < count; i++) { + weakReferece.add(new WeakReference(new byte[byteArraySize])); + } + + System.gc(); + } +} diff --git a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/service/remote/HttpRemoteService.java b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/service/remote/HttpRemoteService.java index 676eb7d68..c683ace74 100644 --- a/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/service/remote/HttpRemoteService.java +++ b/examples/testapp/src/main/java/com/navercorp/pinpoint/testapp/service/remote/HttpRemoteService.java @@ -17,6 +17,7 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; +import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -25,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; /** * @author koo.taejin */ +@Component public class HttpRemoteService implements RemoteService { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/examples/testapp/src/main/resources/servlet-context.xml b/examples/testapp/src/main/resources/servlet-context.xml index a5dd6d0f2..e53eba0fb 100644 --- a/examples/testapp/src/main/resources/servlet-context.xml +++ b/examples/testapp/src/main/resources/servlet-context.xml @@ -12,12 +12,6 @@ - - - - - - diff --git a/examples/testapp/src/main/webapp/WEB-INF/views/apis.jsp b/examples/testapp/src/main/webapp/WEB-INF/views/apis.jsp index c4ac6e511..7b4a483c4 100644 --- a/examples/testapp/src/main/webapp/WEB-INF/views/apis.jsp +++ b/examples/testapp/src/main/webapp/WEB-INF/views/apis.jsp @@ -14,11 +14,12 @@
${apiMapping.key}
- +
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java index 1ad8d99fe..d99591922 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java @@ -94,7 +94,8 @@ public class HttpUriRequestExecuteInterceptor extends AbstractHttpRequestExecute if (len > 0) { try { port = Integer.parseInt(host.substring(pos, pos + len)); - } catch (NumberFormatException ex) { + } catch (NumberFormatException ignore) { + // skip } } host = host.substring(0, colon); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/bindvalue/Types.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/bindvalue/Types.java index 80350821e..3801ab60d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/bindvalue/Types.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/bindvalue/Types.java @@ -23,7 +23,8 @@ public class Types { try { Integer value = (Integer) field.get(java.sql.Types.class); map.put(value, name); - } catch (IllegalAccessException e) { + } catch (IllegalAccessException ignore) { + // skip } } return map; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/test/fork/ForkRunner.java b/profiler/src/main/java/com/navercorp/pinpoint/test/fork/ForkRunner.java index 8bb2b317c..c0aad4e3d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/test/fork/ForkRunner.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/test/fork/ForkRunner.java @@ -341,7 +341,7 @@ public class ForkRunner extends BlockJUnit4ClassRunner { } try { closeable.close(); - } catch (IOException e) { + } catch (IOException ignore) { // skip } } diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java index 2d4332fa9..fefc34674 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/ClassPreLoader.java @@ -16,7 +16,8 @@ public final class ClassPreLoader { public static void preload() { try { preload(65535); - } catch (Exception e) { + } catch (Exception ignore) { + // skip } } diff --git a/rpc/src/main/java/com/navercorp/pinpoint/rpc/stream/StreamChannel.java b/rpc/src/main/java/com/navercorp/pinpoint/rpc/stream/StreamChannel.java index 766672bc2..572f1e745 100644 --- a/rpc/src/main/java/com/navercorp/pinpoint/rpc/stream/StreamChannel.java +++ b/rpc/src/main/java/com/navercorp/pinpoint/rpc/stream/StreamChannel.java @@ -66,6 +66,7 @@ public abstract class StreamChannel { try { openLatch.await(); } catch (InterruptedException e) { + // check Interrupted state } } @@ -73,6 +74,7 @@ public abstract class StreamChannel { try { return openLatch.await(timeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { + // check Interrupted state } return false; diff --git a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/ByteArrayOutputStreamTransport.java b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/ByteArrayOutputStreamTransport.java index 03756ab63..3ab2f294a 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/ByteArrayOutputStreamTransport.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/ByteArrayOutputStreamTransport.java @@ -29,7 +29,8 @@ public class ByteArrayOutputStreamTransport extends TTransport { if (out != null) { try { out.close(); - } catch (IOException e) { + } catch (IOException ignore) { + // skip } } } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/DefaultTBaseLocator.java b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/DefaultTBaseLocator.java index f87b1612b..62973d6d7 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/DefaultTBaseLocator.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/DefaultTBaseLocator.java @@ -125,7 +125,8 @@ class DefaultTBaseLocator implements TBaseLocator { try { tBaseLookup(type); return true; - } catch (TException e) { + } catch (TException ignore) { + // skip } return false;