Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/main/java/io/github/dpsoft/ap/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ private static String getEventType(String segment, Map<String, String> params, O
}

private static Duration getDuration(Map<String, String> params) {
if (params.get("duration") != null) return Duration.ofSeconds(Long.parseLong(params.get("duration")));
if (params.get("seconds") != null) return Duration.ofSeconds(Long.parseLong(params.get("seconds")));
String raw = params.get("duration");
if (raw == null) raw = params.get("seconds");
if (raw != null) {
try {
long secs = Long.parseLong(raw);
if (secs > 0) return Duration.ofSeconds(secs);
} catch (NumberFormatException ignored) {
// fall through to default
}
}
return Duration.ofSeconds(30); // default value
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/github/dpsoft/ap/functions/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public static Map<String, String> splitQueryParams(URI uri) {

for (String pair : pairs) {
final int idx = pair.indexOf("=");
final var key = pair.substring(0, idx);
final var value = pair.substring(idx + 1);
queryPairs.put(URLDecoder.decode(key, StandardCharsets.UTF_8), URLDecoder.decode(value, StandardCharsets.UTF_8));
if (idx < 0) continue; // skip valueless params
final var key = URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8);
final var value = URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8);
queryPairs.put(key, value);
}
return queryPairs;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/github/dpsoft/ap/util/ProfilerExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ private ProfilerExecutor(AsyncProfiler profiler, Command command) {
public Try<ProfilerExecutor> run() {
return Try.of(() -> {
profiler.execute(command.asFormatString(file.getAbsolutePath()));
Thread.sleep(command.getDuration().toMillis());
profiler.stop();
try {
Thread.sleep(command.getDuration().toMillis());
} finally {
profiler.stop(); // always stop, even on interrupt
}
return this;
});
}
Expand Down