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

Measure execution time and add it to the response #96

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ All requests require these two fields to be specified:
All responses will include these fields:
- `id` (string): corresponding to the request ID
- `success` (boolean): whether or not the request was successful
- `execution_time` (long): elapsed time in millis

If an error occurs, all responses will include these fields:
- `error`: a description of the error
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/ibm/mapepire/ClientRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.github.theprez.jcmdutils.StringUtils;
import com.google.gson.Gson;
Expand Down Expand Up @@ -81,6 +82,7 @@ protected void processAfterReplySent() {

@Override
public void run() {
long startTime = System.nanoTime();
try {
go();
addReplyData("success", true);
Expand All @@ -95,6 +97,7 @@ public void run() {
}
} finally {
try {
addReplyData("execution_time", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
sendreply();
processAfterReplySent();
} catch (final Exception e) {
Expand Down
Loading