public void removeCallsFasterThan(long thresholdNs) { for (Iterator<CallStackElement> iterator = children.iterator(); iterator.hasNext(); ) { CallStackElement child = iterator.next(); if (child.executionTime < thresholdNs && !child.isIOQuery()) { iterator.remove(); child.recycle(); } else { child.removeCallsFasterThan(thresholdNs); } } }
private void addCallTreeToSpan(SpanContextInformation info, Span span, String operationName) { final CallStackElement callTree = info.getCallTree(); callTree.setSignature(operationName); final double minExecutionTimeMultiplier = tracingPlugin.getMinExecutionTimePercent() / 100; if (minExecutionTimeMultiplier > 0d) { callTree.removeCallsFasterThan((long) (callTree.getExecutionTime() * minExecutionTimeMultiplier)); } if (!tracingPlugin.getExcludedTags().contains(SpanUtils.CALL_TREE_JSON)) { span.setTag(SpanUtils.CALL_TREE_JSON, JsonUtils.toJson(callTree)); } if (!tracingPlugin.getExcludedTags().contains(SpanUtils.CALL_TREE_ASCII)) { span.setTag(SpanUtils.CALL_TREE_ASCII, callTree.toString(true, tracingPlugin.getCallTreeAsciiFormatter())); } } }
@Test public void testRemoveCallsFasterThanNotIncluded() { final CallStackElement callStackElement = TestClass.method0(); callStackElement.removeCallsFasterThan(TimeUnit.MILLISECONDS.toNanos(50)); assertEquals( "----------------------------------------------------------------------\n" + "Selftime (ms) Total (ms) Method signature\n" + "----------------------------------------------------------------------\n" + "000000.00 000% ---------- 001000.00 100% |||||||||| method0\n" + "000000.00 000% ---------- 001000.00 100% |||||||||| `-- method1\n" + "000050.00 005% :--------- 000500.00 050% |||||----- |-- method1_1\n" + "000200.00 020% ||-------- 000200.00 020% ||-------- | |-- method1_1_1\n" + "000200.00 020% ||-------- 000250.00 025% ||:------- | `-- method1_1_2\n" + "000050.00 005% :--------- 000050.00 005% :--------- | `-- method1_1_2_1\n" + "000150.00 015% |:-------- 000500.00 050% |||||----- `-- method1_2\n" + "000050.00 005% :--------- 000050.00 005% :--------- |-- select * from user \n" + "000050.00 005% :--------- 000050.00 005% :--------- |-- select * from address \n" + "000250.00 025% ||:------- 000250.00 025% ||:------- `-- method1_2_1\n", callStackElement.toString()); callStackElement.recycle(); }
@Test public void testRemoveCallsFasterThan() { final CallStackElement callStackElement = TestClass.method0(); callStackElement.removeCallsFasterThan(TimeUnit.MILLISECONDS.toNanos(51)); assertEquals( "----------------------------------------------------------------------\n" + "Selftime (ms) Total (ms) Method signature\n" + "----------------------------------------------------------------------\n" + "000000.00 000% ---------- 001000.00 100% |||||||||| method0\n" + "000000.00 000% ---------- 001000.00 100% |||||||||| `-- method1\n" + "000050.00 005% :--------- 000500.00 050% |||||----- |-- method1_1\n" + "000200.00 020% ||-------- 000200.00 020% ||-------- | |-- method1_1_1\n" + "000250.00 025% ||:------- 000250.00 025% ||:------- | `-- method1_1_2\n" + // method1_1_2_1 is excluded, because execution time 50 < 51 "000150.00 015% |:-------- 000500.00 050% |||||----- `-- method1_2\n" + // io queries are not excluded even though execution time 50 < 51 "000050.00 005% :--------- 000050.00 005% :--------- |-- select * from user \n" + "000050.00 005% :--------- 000050.00 005% :--------- |-- select * from address \n" + "000250.00 025% ||:------- 000250.00 025% ||:------- `-- method1_2_1\n", callStackElement.toString()); callStackElement.recycle(); }