@Advice.OnMethodExit(inline = false, onThrowable = Throwable.class) public static void onAfterEvaluate() { final CallStackElement currentFreemarkerCall = Profiler.getMethodCallParent(); Profiler.stop(); removeCurrentNodeIfItHasNoChildren(currentFreemarkerCall); }
public String getFoo() { Profiler.start("String org.stagemonitor.tracing.freemarker.FreemarkerProfilingTransformerTest$TemplateModel.getFoo()"); try { return "foo"; } finally { Profiler.stop(); } } }
static void method1_1_1() { Profiler.start("method1_1_1()"); final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(200000000); }
@Test public void testInnerPrivateMethod() { class Test { private void test() { } } Test test = new Test(); CallStackElement total = Profiler.activateProfiling("total"); test.test(); Profiler.stop(); Assert.assertFalse(total.toString(), total.getChildren().iterator().next().getSignature().contains("access$")); }
static void method1_2_1() { Profiler.start("method1_2_1()"); final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(250000000); } }
static void method1_1_2_1() { Profiler.start("method1_1_2_1()"); final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(50000000); }
static void method1_1_2() { Profiler.start("method1_1_2()"); try { method1_1_2_1(); } finally { final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(250000000); } }
static CallStackElement method0() { final CallStackElement callStackElement = Profiler.activateProfiling("method0()"); try { method1(); return callStackElement; } finally { final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(1000000000); } }
@Test public void testProfileServlet() throws Exception { Filter filter = new CompositeFilter(); final CallStackElement total = Profiler.activateProfiling("total"); filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); Profiler.stop(); final CallStackElement serviceCall = total.getChildren().iterator().next(); assertEquals("CompositeFilter#doFilter", serviceCall.getShortSignature()); }
@Test public void testDontProfileStagemonitorServlet() throws Exception { Filter filter = new HttpRequestMonitorFilter(); final CallStackElement total = Profiler.activateProfiling("total"); filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); Profiler.stop(); assertEquals(0, total.getChildren().size()); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { final Scope scope = new ExternalHttpRequest(tracingPlugin.getTracer(), request.getMethod().toString(), removeQuery(request.getURI()), request.getURI().getHost(), request.getURI().getPort()).createScope(); try { Profiler.start(request.getMethod().toString() + " " + request.getURI() + " "); tracingPlugin.getTracer().inject(scope.span().context(), Format.Builtin.HTTP_HEADERS, new SpringHttpRequestInjectAdapter(request)); return execution.execute(request, body); } finally { Profiler.stop(); scope.close(); } }
static void method1_1() { Profiler.start("method1_1()"); try { method1_1_1(); method1_1_2(); } finally { final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(500000000); } }
@Test public void testProfiler() { ProfilerTest profilerTest = new ProfilerTest(); CallStackElement total = Profiler.activateProfiling("total"); Assert.assertEquals(21, profilerTest.method1()); Profiler.stop(); Assert.assertEquals(total.toString(), 1, total.getChildren().size()); Assert.assertEquals(total.toString(), 3, total.getChildren().get(0).getChildren().size()); final String method5 = total.getChildren().get(0).getChildren().get(2).getSignature(); Assert.assertTrue(method5, method5.contains("org.stagemonitor.tracing.prof.ProfilerTest.method5")); }
static void method1() { Profiler.start("method1()"); try { method1_1(); method1_2(); } finally { final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(1000000000); } }
@Test public void testProfileServlet() throws Exception { Servlet servlet = new DispatcherServlet(); final CallStackElement total = Profiler.activateProfiling("total"); servlet.service(new MockHttpServletRequest(), new MockHttpServletResponse()); Profiler.stop(); final CallStackElement serviceCall = total.getChildren().iterator().next(); assertEquals("FrameworkServlet#service", serviceCall.getShortSignature()); }
@Test public void testDontProfileStagemonitorServlet() throws Exception { Servlet servlet = new StagemonitorFileServlet(); final CallStackElement total = Profiler.activateProfiling("total"); servlet.service(new MockHttpServletRequest(), new MockHttpServletResponse()); Profiler.stop(); assertEquals(0, total.getChildren().size()); } }
@Test public void testNoProfilingIfNotActive() { assertFalse(Profiler.isProfilingActive()); Profiler.start("dummy"); assertNull(Profiler.getMethodCallParent()); Profiler.stop(); }
static void method1_2() { Profiler.start("method1_2()"); Profiler.addIOCall("select * from user", 50000000); Profiler.addIOCall("select * from address", 50000000); method1_2_1(); final CallStackElement thisCallStackElement = Profiler.getMethodCallParent(); Profiler.stop(); thisCallStackElement.setExecutionTime(500000000); } static void method1_2_1() {
@Test public void testMeterTimer() { CallStackElement total = Profiler.activateProfiling("total"); testObject.testMethod(); Profiler.stop(); final String signature = total.getChildren().get(0).getSignature(); assertTrue(signature, signature.contains("org.stagemonitor.tracing.MultipleAnnotationsAndProfilerTest$TestObject.testMethod")); assertOneMeterExists(name("rate").tag("signature", "MultipleAnnotationsAndProfilerTest$TestObject#testMethod").build()); assertOneTimerExists(name("timer").tag("signature", "MultipleAnnotationsAndProfilerTest$TestObject#testMethod").build()); }
@Test public void testCollectElasticsearchQueries() throws Exception { CallStackElement total = Profiler.activateProfiling("total"); client.prepareSearch().setQuery(QueryBuilders.matchAllQuery()).get(); client.prepareSearch().setQuery(QueryBuilders.matchAllQuery()).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get(); Profiler.stop(); Assert.assertEquals(total.toString(), "POST /_search\n" + "{\"query\":{\"match_all\":{\"boost\":1.0}}} ", total.getChildren().get(0).getSignature()); Assert.assertEquals(total.toString(), "POST /_search?search_type=dfs_query_then_fetch\n" + "{\"query\":{\"match_all\":{\"boost\":1.0}}} ", total.getChildren().get(1).getSignature()); } }