• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Camelcade / Perl5-IDEA / #525521839

30 Apr 2026 02:10PM UTC coverage: 76.215% (+0.06%) from 76.16%
#525521839

push

github

hurricup
Testing plugin 2.16.1-SNAPSHOT

14764 of 22542 branches covered (65.5%)

Branch coverage included in aggregate %.

31105 of 37642 relevant lines covered (82.63%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.43
/plugin/profiler/src/main/java/com/perl5/lang/perl/profiler/run/PerlProfilerProgramRunner.java
1
/*
2
 * Copyright 2015-2026 Alexandr Evstigneev
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.perl5.lang.perl.profiler.run;
18

19
import com.intellij.execution.ExecutionException;
20
import com.intellij.execution.configurations.RunProfile;
21
import com.intellij.execution.configurations.RunProfileState;
22
import com.intellij.execution.runners.ExecutionEnvironment;
23
import com.intellij.execution.ui.RunContentDescriptor;
24
import com.intellij.openapi.application.PathManager;
25
import com.intellij.openapi.diagnostic.Logger;
26
import com.intellij.openapi.util.io.FileUtil;
27
import com.intellij.openapi.util.io.NioFiles;
28
import com.intellij.profiler.DefaultProfilerExecutorGroup;
29
import com.intellij.profiler.ProfilerToolWindowManager;
30
import com.perl5.lang.perl.idea.run.GenericPerlProgramRunner;
31
import com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration;
32
import com.perl5.lang.perl.idea.run.PerlRunProfileState;
33
import com.perl5.lang.perl.profiler.PerlProfilerBundle;
34
import com.perl5.lang.perl.profiler.configuration.PerlProfilerConfigurationState;
35
import com.perl5.lang.perl.util.PerlPackageUtilCore;
36
import org.jetbrains.annotations.NotNull;
37
import org.jetbrains.annotations.Nullable;
38
import org.jetbrains.concurrency.AsyncPromise;
39

40
import java.io.IOException;
41
import java.util.Set;
42

43
@SuppressWarnings("UnstableApiUsage")
44
public class PerlProfilerProgramRunner extends GenericPerlProgramRunner {
1✔
45
  private static final Logger LOG = Logger.getInstance(PerlProfilerProgramRunner.class);
1✔
46

47
  @Override
48
  public @NotNull String getRunnerId() {
49
    return "Perl Profiler";
1✔
50
  }
51

52
  @Override
53
  public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
54
    if (!(profile instanceof GenericPerlRunConfiguration)) {
1!
55
      return false;
×
56
    }
57
    var executorSettings = getExecutorSettings(executorId);
1✔
58
    return executorSettings != null && executorSettings.canRun(profile);
1!
59
  }
60

61
  private static @Nullable DefaultProfilerExecutorGroup.ProfilerExecutorSettings getExecutorSettings(@NotNull String executorId) {
62
    var executorGroup = DefaultProfilerExecutorGroup.Companion.getInstance();
1✔
63
    if (executorGroup == null) {
1!
64
      return null;
×
65
    }
66
    return executorGroup.getRegisteredSettings(executorId);
1✔
67
  }
68

69
  @Override
70
  protected @Nullable PerlRunProfileState createState(@NotNull ExecutionEnvironment executionEnvironment)
71
    throws ExecutionException {
72

73
    var executorSettings = getExecutorSettings(executionEnvironment.getExecutor().getId());
1✔
74
    if (executorSettings == null) {
1!
75
      var message = PerlProfilerBundle.message("dialog.message.unable.to.find.executor.settings");
×
76
      LOG.error(message);
×
77
      throw new ExecutionException(message);
×
78
    }
79
    var runProfile = executionEnvironment.getRunProfile();
1✔
80
    if (!executorSettings.canRun(runProfile)) {
1!
81
      var message = PerlProfilerBundle.message("dialog.message.unable.to.run.with", runProfile, executorSettings);
×
82
      LOG.error(message);
×
83
      throw new ExecutionException(message);
×
84
    }
85
    var perlProfilerConfigurationState = executorSettings.getState();
1✔
86
    if (!(perlProfilerConfigurationState instanceof PerlProfilerConfigurationState profilerConfigurationState)) {
1!
87
      LOG.error("PerlProfilerConfigurationState expected, got: " + perlProfilerConfigurationState);
×
88
      throw new ExecutionException(
×
89
        PerlProfilerBundle.message("dialog.message.wrong.profiler.configuration.state", perlProfilerConfigurationState));
×
90
    }
91

92
    return new PerlProfilerRunProfileState(executionEnvironment, profilerConfigurationState);
1✔
93
  }
94

95
  @Override
96
  protected Set<String> getRequiredModules(@NotNull ExecutionEnvironment environment) {
97
    var modules = super.getRequiredModules(environment);
1✔
98
    modules.add(PerlPackageUtilCore.PROFILER_MODULE);
1✔
99
    return modules;
1✔
100
  }
101

102
  @Override
103
  protected void doExecute(@NotNull RunProfileState state,
104
                           @NotNull ExecutionEnvironment environment,
105
                           @NotNull AsyncPromise<? super RunContentDescriptor> result) throws ExecutionException {
106
    if (!(state instanceof PerlProfilerRunProfileState profilerRunProfileState)) {
1!
107
      LOG.error("PerlProfilerRunProfileState expected, got " + state);
×
108
      throw new ExecutionException(PerlProfilerBundle.message("dialog.message.incorrect.run.configuration.state.see.logs.for.details"));
×
109
    }
110
    var profileResultsPath = profilerRunProfileState.getProfilingResultsPath();
1✔
111
    LOG.info("Profiling results saved in: " + profileResultsPath);
1✔
112
    if (FileUtil.isAncestor(PathManager.getSystemPath(), profileResultsPath.toString(), true)) {
1!
113
      try {
114
        // fxime we probably should fix permissions here
115
        NioFiles.deleteRecursively(profileResultsPath, (path) -> {
1✔
116
        });
×
117
      }
118
      catch (IOException e) {
×
119
        throw new ExecutionException(PerlProfilerBundle.message("dialog.message.error.removing.old.profiling.data.at", profileResultsPath),
×
120
                                     e);
121
      }
1✔
122
    }
123
    else {
124
      LOG.error("Wrong profiler results directory: " + profileResultsPath);
×
125
    }
126
    //noinspection ResultOfMethodCallIgnored
127
    profileResultsPath.toFile().mkdirs();
1✔
128

129
    result.then(descriptor -> {
1✔
130
      if (descriptor instanceof RunContentDescriptor runContentDescriptor) {
1!
131
        var profilerProcess = new PerlProfilerProcess(environment, runContentDescriptor, profilerRunProfileState);
1✔
132
        ProfilerToolWindowManager.getInstance(environment.getProject()).addProfilerProcessTab(profilerProcess, false);
1✔
133
      }
134
      return descriptor;
1✔
135
    });
136
    createAndSetContentDescriptor(environment, state.execute(environment.getExecutor(), this), result);
1✔
137
  }
1✔
138
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc