Skip to content

Commit ea43fc0

Browse files
committed
Bug 1783261 - Add telemetry text recognition API timing; r=nordzilla
Differential Revision: https://phabricator.services.mozilla.com/D154893
1 parent 7fe0f60 commit ea43fc0

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

browser/base/content/nsContextMenu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,10 @@ class nsContextMenu {
23242324
getImageText() {
23252325
let dialogBox = gBrowser.getTabDialogBox(this.browser);
23262326
const imageTextResult = this.actor.getImageText(this.targetIdentifier);
2327+
TelemetryStopwatch.start(
2328+
"TEXT_RECOGNITION_API_PERFORMANCE",
2329+
imageTextResult
2330+
);
23272331
const { dialog } = dialogBox.open(
23282332
"chrome://browser/content/textrecognition/textrecognition.html",
23292333
{

browser/components/textrecognition/tests/browser/browser_textrecognition.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ add_task(async function() {
1919
!getTelemetryScalars()["browser.ui.interaction.content_context"],
2020
"No telemetry has been recorded yet."
2121
);
22+
is(
23+
Services.telemetry
24+
.getHistogramById("TEXT_RECOGNITION_API_PERFORMANCE")
25+
.snapshot().sum,
26+
0,
27+
"No histogram timing was recorded."
28+
);
2229

2330
info("Right click image to show context menu.");
2431
let popupShownPromise = BrowserTestUtils.waitForEvent(
@@ -79,6 +86,13 @@ add_task(async function() {
7986
is(p2.innerText, "Firefox\n", "The second piece of text matches.");
8087
}
8188

89+
ok(
90+
Services.telemetry
91+
.getHistogramById("TEXT_RECOGNITION_API_PERFORMANCE")
92+
.snapshot().sum > 0,
93+
"Text recognition API performance was recorded."
94+
);
95+
8296
info("Close the dialog box.");
8397
const close = contentDocument.querySelector("#text-recognition-close");
8498
close.click();

browser/components/textrecognition/tests/browser/browser_textrecognition_no_result.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ add_task(async function() {
6767
const text = contentDocument.querySelector(".textRecognitionText");
6868
is(text.children.length, 0, "No results are listed.");
6969

70+
ok(
71+
Services.telemetry
72+
.getHistogramById("TEXT_RECOGNITION_API_PERFORMANCE")
73+
.snapshot().sum > 0,
74+
"Histogram timing was recorded even though there were no results."
75+
);
76+
7077
info("Close the dialog box.");
7178
const close = contentDocument.querySelector("#text-recognition-close");
7279
close.click();

browser/components/textrecognition/tests/browser/head.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ function getTelemetryScalars() {
4545

4646
function clearTelemetry() {
4747
Services.telemetry.clearScalars();
48+
Services.telemetry
49+
.getHistogramById("TEXT_RECOGNITION_API_PERFORMANCE")
50+
.clear();
4851
}

browser/components/textrecognition/textrecognition.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ class TextRecognitionModal {
4646
if (results.length === 0) {
4747
// Update the UI to indicate that there were no results.
4848
this.showHeaderByID("text-recognition-header-no-results");
49+
// It's still worth recording telemetry times, as the API was still invoked.
50+
TelemetryStopwatch.finish(
51+
"TEXT_RECOGNITION_API_PERFORMANCE",
52+
resultsPromise
53+
);
4954
return;
5055
}
5156

5257
// There were results, cluster them into a nice presentation, and present
5358
// the results to the UI.
5459
this.runClusteringAndUpdateUI(results, direction);
5560
this.showHeaderByID("text-recognition-header-results");
61+
TelemetryStopwatch.finish(
62+
"TEXT_RECOGNITION_API_PERFORMANCE",
63+
resultsPromise
64+
);
5665
},
5766
error => {
5867
// There was an error in the text recognition call. Treat this as the same
@@ -67,6 +76,10 @@ class TextRecognitionModal {
6776
"browser.ui.interaction.textrecognition_error",
6877
1
6978
);
79+
TelemetryStopwatch.cancel(
80+
"TEXT_RECOGNITION_API_PERFORMANCE",
81+
resultsPromise
82+
);
7083
}
7184
);
7285
}

toolkit/components/telemetry/Histograms.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17077,6 +17077,18 @@
1707717077
"alert_emails": ["necko@mozilla.com", "mwoodrow@mozilla.com"],
1707817078
"description": "Time spent waiting on the main-thread to be available to run AsyncOpen, for image preload requests"
1707917079
},
17080+
"TEXT_RECOGNITION_API_PERFORMANCE": {
17081+
"record_in_processes": ["main"],
17082+
"products": ["firefox"],
17083+
"releaseChannelCollection": "opt-out",
17084+
"alert_emails": ["gtatum@mozilla.com", "nordzilla@mozilla.com"],
17085+
"expires_in_version": "109",
17086+
"kind": "exponential",
17087+
"high": 120000,
17088+
"n_buckets": 20,
17089+
"bug_numbers": [1783261],
17090+
"description": "The milliseconds of time the text recognition results took to display, including the UI time and OS response time."
17091+
},
1708017092
"DOWNLOADS_USER_ACTION_ON_BLOCKED_DOWNLOAD": {
1708117093
"record_in_processes": ["main"],
1708217094
"products": ["firefox"],

0 commit comments

Comments
 (0)