Skip to content

Fix android instrumentation #10335

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
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 @@ -97,16 +97,7 @@ public void onResult(String result) {

@Override
public void onStats(String stats) {
float tps = 0;
try {
JSONObject jsonObject = new JSONObject(stats);
int numGeneratedTokens = jsonObject.getInt("generated_tokens");
int inferenceEndMs = jsonObject.getInt("inference_end_ms");
int promptEvalEndMs = jsonObject.getInt("prompt_eval_end_ms");
tps = (float) numGeneratedTokens / (inferenceEndMs - promptEvalEndMs) * 1000;
LlmModuleInstrumentationTest.this.onStats(tps);
} catch (JSONException e) {
}
LlmModuleInstrumentationTest.this.onStats(stats);
}
});

Expand All @@ -120,7 +111,16 @@ public void onResult(String result) {
}

@Override
public void onStats(float tps) {
tokensPerSecond.add(tps);
public void onStats(String stats) {
float tps = 0;
try {
JSONObject jsonObject = new JSONObject(stats);
int numGeneratedTokens = jsonObject.getInt("generated_tokens");
int inferenceEndMs = jsonObject.getInt("inference_end_ms");
int promptEvalEndMs = jsonObject.getInt("prompt_eval_end_ms");
tps = (float) numGeneratedTokens / (inferenceEndMs - promptEvalEndMs) * 1000;
tokensPerSecond.add(tps);
} catch (JSONException e) {
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty catch block may hide JSON parsing errors, potentially making debugging more difficult. Consider logging the exception or handling it accordingly.

Suggested change
} catch (JSONException e) {
} catch (JSONException e) {
android.util.Log.e("LlmModuleInstrumentationTest", "Failed to parse JSON stats", e);

Copilot uses AI. Check for mistakes.

}
}
}
Loading