Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 142 add display of allocating method to profilejvm #146

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public PerfIssue verifyPerfIssue(ProfileJvm annotation, JfrEventsMeasure jfrEven
String insideTlabSum = ALLOC_INSIDE_TLAB_SUM.formatAsString(jfrEvents);
String outsideTlabSum = ALLOC_OUTSIDE_TLAB_SUM.formatAsString(jfrEvents);
String allocationRate = ALLOCATION_RATE.formatAsString(jfrEvents);
String allocatedClasses = ALLOCATED_CLASSES.formatAsString(jfrEvents);

String totalGcPause = TOTAL_GC_PAUSE.formatAsString(jfrEvents);
String gcPause = LONGEST_GC_PAUSE.formatAsString(jfrEvents);
Expand Down Expand Up @@ -89,6 +90,7 @@ public PerfIssue verifyPerfIssue(ProfileJvm annotation, JfrEventsMeasure jfrEven
+ " Inside TLAB : " + fifteenLength.adapt(insideTlabSum) + "| " + twentyNineLength.adapt("Longest GC pause: " + gcPause) + "| Error : " + errorCount + LINE_SEPARATOR
+ " Outside TLAB: " + fifteenLength.adapt(outsideTlabSum) + "| " + twentyNineLength.adapt("Young: " + youngGcCollection) + "| Throwable: " + throwablesCount + LINE_SEPARATOR
+ " Allocation rate: " + twelveLength.adapt(allocationRate) + "| " + twentyNineLength.adapt("Old : " + oldGcCollection) + "|" + LINE_SEPARATOR
+ " " + allocatedClasses + LINE_SEPARATOR
+ LINE
+ thirtyLength.adapt(" COMPILATION") + "| " + "CODE CACHE" + LINE_SEPARATOR
+ thirtyLength.adapt(" Number : " + compilationsCount) + "| " + codeCacheFullCount + LINE_SEPARATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.flightrecorder.jdk.JdkAggregators;
import org.quickperf.jvm.jmc.value.allocationbyclass.AllocationByClassFormatter;
import org.quickperf.jvm.jmc.value.allocationbyclass.AllocationByClassResult;
import org.quickperf.jvm.jmc.value.allocationbyclass.AllocationByClassResultRetriever;
import org.quickperf.jvm.jmc.value.allocationrate.AllocationRate;
import org.quickperf.jvm.jmc.value.allocationrate.AllocationRateFormatter;
import org.quickperf.jvm.jmc.value.allocationrate.AllocationRateRetriever;

@SuppressWarnings("rawtypes")
public enum ProfilingInfo {

TOTAL_GC_PAUSE {
Expand Down Expand Up @@ -284,7 +288,8 @@ public String getLabel() {
return getLabel(JdkAggregators.OS_VERSION, String.class);
}

},
}
,
ALLOCATION_RATE {
@Override
public String formatAsString(IItemCollection jfrEvents) {
Expand All @@ -300,6 +305,21 @@ public String formatAsString(IItemCollection jfrEvents) {
public String getLabel() {
return "Allocation Rate";
}
}
,
ALLOCATED_CLASSES {
@Override
public String formatAsString(IItemCollection jfrEvents) {
AllocationByClassResult result = AllocationByClassResultRetriever.INSTANCE
.extractAllocationByClassResultFrom(jfrEvents);

return AllocationByClassFormatter.INSTANCE.format(result);
}

@Override
public String getLabel() {
return "Allocated Classes";
}
};

public abstract String formatAsString(IItemCollection jfrEvents);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*
* Copyright 2019-2020 the original author or authors.
*/

package org.quickperf.jvm.jmc.value.allocationbyclass;

import org.quickperf.jvm.jmcrule.HtmlToPlainTextTransformer;

public class AllocationByClassFormatter {
public static final AllocationByClassFormatter INSTANCE = new AllocationByClassFormatter();

private AllocationByClassFormatter() {}

public String format(AllocationByClassResult result) {
final String shortDescription = result.getResult().getShortDescription();
return HtmlToPlainTextTransformer.INSTANCE.convertHtmlToPlainText(shortDescription);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*
* Copyright 2019-2020 the original author or authors.
*/

package org.quickperf.jvm.jmc.value.allocationbyclass;

import org.openjdk.jmc.flightrecorder.rules.Result;

public class AllocationByClassResult {

private final Result result;

public AllocationByClassResult(Result result) {
this.result = result;
}

public Result getResult() {
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*
* Copyright 2019-2020 the original author or authors.
*/

package org.quickperf.jvm.jmc.value.allocationbyclass;

import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.util.IPreferenceValueProvider;
import org.openjdk.jmc.flightrecorder.rules.Result;
import org.openjdk.jmc.flightrecorder.rules.jdk.memory.AllocationByClassRule;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.RunnableFuture;

public class AllocationByClassResultRetriever {
public static final AllocationByClassResultRetriever INSTANCE = new AllocationByClassResultRetriever();
private static final AllocationByClassRule allocationByClassRule = new AllocationByClassRule();
private static final Result NO_RESULT = new Result(allocationByClassRule, 0d, "");

private AllocationByClassResultRetriever() {}

public AllocationByClassResult extractAllocationByClassResultFrom(IItemCollection jfrEvents) {
RunnableFuture<Result> allocationByClassRuleFuture =
allocationByClassRule.evaluate(jfrEvents, IPreferenceValueProvider.DEFAULT_VALUES);
allocationByClassRuleFuture.run();
Result result;
try {
result = allocationByClassRuleFuture.get();
} catch (InterruptedException | ExecutionException e) {
result = NO_RESULT;
}
return new AllocationByClassResult(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.jsoup.examples.HtmlToPlainText;
import org.jsoup.nodes.Document;

class HtmlToPlainTextTransformer {
public class HtmlToPlainTextTransformer {

public static final HtmlToPlainTextTransformer INSTANCE = new HtmlToPlainTextTransformer();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*
* Copyright 2019-2020 the original author or authors.
*/

package org.quickperf.testng.jvm.jmc;

import org.quickperf.jvm.jfr.annotation.ProfileJvm;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

public class AllocatedClassesProfileJVMTest {

@ProfileJvm
@Test
public void mostAllocatedClassesProfileJVMAnnotation() {
IntegerAccumulator integerAccumulator = new IntegerAccumulator();
integerAccumulator.accumulateInteger(500_000);
}

private static class IntegerAccumulator {

private List<Integer> integerList;

void accumulateInteger(int numberOfIntegers) {
integerList = new ArrayList<>(numberOfIntegers);
for (int i = 1; i <= numberOfIntegers; i++) {
integerList.add(i);
}
}

}
}