@Test public void testFreemarkerProfilingMethodCall() throws Exception { final CallStackElement callTree = Profiler.activateProfiling("testFreemarkerProfilingMethodCall"); final String renderedTemplate = processTemplate("test.ftl", "${templateModel.getFoo()}", new TemplateModel()); Profiler.stop(); Profiler.deactivateProfiling(); assertThat(renderedTemplate).isEqualTo("foo"); System.out.println(callTree); assertThat(callTree.getChildren()).hasSize(1); final CallStackElement freemarkerNode = callTree.getChildren().get(0); assertThat(freemarkerNode.getSignature()).isEqualTo("test.ftl:1#templateModel.getFoo()"); assertThat(freemarkerNode.getChildren()).hasSize(1); final CallStackElement templateModelNode = freemarkerNode.getChildren().get(0); assertThat(templateModelNode.getSignature()).isEqualTo("String org.stagemonitor.tracing.freemarker.FreemarkerProfilingTransformerTest$TemplateModel.getFoo()"); }
@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$")); }
@Test public void testFreemarkerProfiling() throws Exception { final CallStackElement callTree = Profiler.activateProfiling("testFreemarkerProfiling"); final String renderedTemplate = processTemplate("test.ftl", "${templateModel.foo}", new TemplateModel()); Profiler.stop(); Profiler.deactivateProfiling(); assertThat(renderedTemplate).isEqualTo("foo"); System.out.println(callTree); assertThat(callTree.getChildren()).hasSize(1); final CallStackElement freemarkerNode = callTree.getChildren().get(0); assertThat(freemarkerNode.getSignature()).isEqualTo("test.ftl:1#templateModel.foo"); assertThat(freemarkerNode.getChildren()).hasSize(1); final CallStackElement templateModelNode = freemarkerNode.getChildren().get(0); assertThat(templateModelNode.getSignature()).isEqualTo("String org.stagemonitor.tracing.freemarker.FreemarkerProfilingTransformerTest$TemplateModel.getFoo()"); }
@Override public void onStart(SpanWrapper spanWrapper) { final SpanContextInformation contextInfo = SpanContextInformation.forSpan(spanWrapper); if (tracingPlugin.isSampled(spanWrapper) && contextInfo.getPreExecutionInterceptorContext() != null) { determineIfEnableProfiler(spanWrapper, contextInfo); if (!Profiler.isProfilingActive() && contextInfo.getPreExecutionInterceptorContext().isCollectCallTree()) { contextInfo.setCallTree(Profiler.activateProfiling("total")); } } }
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 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()); }
@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 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")); }
@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 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 testProfilerActive() { assertFalse(Profiler.isProfilingActive()); Profiler.activateProfiling(""); assertTrue(Profiler.isProfilingActive()); Profiler.deactivateProfiling(); assertFalse(Profiler.isProfilingActive()); }
@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()); } }