Skip to content

Commit

Permalink
BenchmarkTag generation, fix for throwing an exception on explorer se…
Browse files Browse the repository at this point in the history
…lect
  • Loading branch information
mjok committed Dec 11, 2020
1 parent 2ca1e93 commit fa499a3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -88,7 +89,7 @@ protected static PsiClass generateClassAndMethods(CBGenerateDialog options, PsiD
for (MemberInfo m : options.getSelectedMethods()) {
if (m.getMember() instanceof PsiMethod) {
PsiMethod psiMethod = (PsiMethod) m.getMember();
generateMethodWithAnnotations(psiMethod.getName() + "Benchmark", options.getMode(), created, factory);
generateMethodWithAnnotations(psiMethod.getName() + "Benchmark", options.getMode(), created, factory, options.shouldGenerateBechmarkTag());
}
}

Expand Down Expand Up @@ -120,11 +121,14 @@ private static PsiClass createPsiClass(PsiDirectory parent, String benchmarkFile
}

@NotNull
private static PsiMethod generateMethodWithAnnotations(String name, String mode, PsiClass created, JVMElementFactory factory) {
private static PsiMethod generateMethodWithAnnotations(String name, String mode, PsiClass created, JVMElementFactory factory, boolean addBenchmarkTag) {
PsiMethod benchmarkMethod = factory.createMethodFromText("public void " + name + "(org.openjdk.jmh.infra.Blackhole bh){}", created);
benchmarkMethod.getModifierList().addAnnotation("org.openjdk.jmh.annotations.Benchmark");
benchmarkMethod.getModifierList().addAnnotation("org.openjdk.jmh.annotations.BenchmarkMode(org.openjdk.jmh.annotations." + mode + ")");
benchmarkMethod.getModifierList().addAnnotation("org.openjdk.jmh.annotations.OutputTimeUnit(java.util.concurrent.TimeUnit.SECONDS)");
if (addBenchmarkTag) {
benchmarkMethod.getModifierList().addAnnotation("com.gocypher.cybench.core.annotation.BenchmarkTag(tag=\"" + UUID.randomUUID() + "\")");
}
PsiElement add = created.add(benchmarkMethod);

return benchmarkMethod;
Expand Down Expand Up @@ -243,9 +247,12 @@ public void setupLibrary(Module module) {
"jmh-core", "1.26", "1.26");
ExternalLibraryDescriptor aProcessor = new ExternalLibraryDescriptor("org.openjdk.jmh",
"jmh-generator-annprocess", "1.26", "1.26");
ExternalLibraryDescriptor benchmarkTag = new ExternalLibraryDescriptor("com.gocypher.cybench.client",
"gocypher-cybench-annotations", "1.0.0", "1.0.0");

JavaProjectModelModificationService.getInstance(module.getProject()).addDependency(module, core, DependencyScope.TEST);
JavaProjectModelModificationService.getInstance(module.getProject()).addDependency(module, aProcessor, DependencyScope.TEST);
JavaProjectModelModificationService.getInstance(module.getProject()).addDependency(module, benchmarkTag, DependencyScope.TEST);
} else {

OrderEntryFix.addJarsToRoots(Arrays.asList(Utils.getJMHLibFiles()).stream().map(f -> f.getAbsolutePath()).collect(Collectors.toList()), null, module, null);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/gocypher/cybench/generate/CBGenerateDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class CBGenerateDialog extends DialogWrapper {
"@Setup");
private final JCheckBox myGenerateAfterBox = new JCheckBox(
"@TearDown");
private final JCheckBox myGenerateBenchmarkTag = new JCheckBox(
"@BenchmarkTag");
private final MemberSelectionTable myMethodsTable = new MemberSelectionTable(
Collections.emptyList(), null);
protected PsiDirectory myTargetDirectory;
Expand Down Expand Up @@ -234,6 +236,11 @@ public void actionPerformed(@NotNull AnActionEvent e) {
myGenerateAfterBox.setSelected(true);
panel.add(myGenerateAfterBox, constr);

constr.insets = insets(1);
constr.gridy = gridy++;
myGenerateBenchmarkTag.setSelected(true);
panel.add(myGenerateBenchmarkTag, constr);

final JLabel membersLabel = new JLabel("Select methods");
membersLabel.setLabelFor(myMethodsTable);
panel.add(membersLabel, constr);
Expand Down Expand Up @@ -309,6 +316,10 @@ public boolean shouldGenerateSetup() {
return myGenerateBeforeBox.isSelected();
}

public boolean shouldGenerateBechmarkTag() {
return myGenerateBeforeBox.isSelected();
}


public String getMode() {
return mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,24 @@ public static void refreshToolWindow() {
private void initComponents() {
toolWindowContent = new JPanel(new BorderLayout(0, 0));

reportList = new JBTable(new DefaultTableModel());
reportList = new JBTable(new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
});
((DefaultTableModel) reportList.getModel()).setColumnIdentifiers(new String[]{"Benchmark Name", "Score", "Timestamp", "Actual_File_Hidden"});
reportList.removeColumn(reportList.getColumnModel().getColumn(3));

reportList.getSelectionModel().addListSelectionListener(x -> {

if (x.getValueIsAdjusting() || reloading) return;

int selectionIndex = x.getLastIndex();
File valueAt = (File) reportList.getModel().getValueAt(selectionIndex, 3);
CyBenchToolWindow.activateReportView(valueAt, toolWindowContent, null);
reportList.getSelectionModel().removeIndexInterval(x.getFirstIndex(), x.getLastIndex());

reportList.getSelectionModel().clearSelection();
});

toolWindowContent.add(new JScrollPane(reportList), BorderLayout.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.gocypher.cybench.utils.NodeAndTabFiller;
import com.gocypher.cybench.utils.Nodes;
import com.gocypher.cybench.utils.ResultFileParser;
import com.gocypher.cybench.viewPanels.ResultJPanel;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.wm.ToolWindow;
Expand Down Expand Up @@ -120,7 +121,7 @@ public static void activateReportView(File file, JPanel toolWindowContent, Strin
myToolWindow.selectActualReport(selectReport);
}
} else {
cyBench_report.getContentManager().setSelectedContent(ToolWindowFactory.loaded.get(file));
ApplicationManager.getApplication().invokeLater(() -> cyBench_report.getContentManager().setSelectedContent(ToolWindowFactory.loaded.get(file)));
if (selectReport != null) {
ToolWindowFactory.loadedWindows.get(file).selectActualReport(selectReport);
}
Expand Down

0 comments on commit fa499a3

Please sign in to comment.