1
0
Fork 0

For #10434: Handle cases when proc/$pid/stat is not accessible.

master
mcarare 2020-05-07 14:59:24 +03:00 committed by liuche
parent 0df27742a3
commit 2090b11c97
4 changed files with 32 additions and 2 deletions

View File

@ -2253,6 +2253,22 @@ startup.timeline:
- perf-android-fe@mozilla.com
- mcomella@mozilla.com
expires: "2020-07-15"
framework_start_read_error:
send_in_pings:
- startup-timeline
type: boolean
description: |
An error when attempting to read stats from /proc pseudo-filesystem -
privacy managers can block access to reading these files -
the application will catch a file reading exception.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/10434
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/10481
notification_emails:
- perf-android-fe@mozilla.com
- mcomella@mozilla.com
expires: "2020-07-15"
clock_ticks_per_second:
send_in_pings:
- startup-timeline

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.perf
import android.os.Process
import android.os.SystemClock
import java.io.FileNotFoundException
import kotlin.math.roundToLong
import org.mozilla.fenix.GleanMetrics.StartupTimeline as Telemetry
@ -53,14 +54,23 @@ internal class StartupFrameworkStartMeasurement(
if (applicationInitNanos < 0) {
telemetry.frameworkStartError.set(true)
} else {
telemetry.frameworkStart.setRawNanos(getFrameworkStartNanos())
try {
telemetry.frameworkStart.setRawNanos(getFrameworkStartNanos())
} catch (e: FileNotFoundException) {
// Privacy managers can add hooks that block access to reading system /proc files.
// We want to catch these exception and report an error on accessing the file
// rather than an implementation error.
telemetry.frameworkStartReadError.set(true)
}
// frameworkStart is derived from the number of clock ticks per second. To ensure this
// value does not throw off our result, we capture it too.
telemetry.clockTicksPerSecond.add(stat.clockTicksPerSecond.toInt())
}
}
/**
* @throws [java.io.FileNotFoundException]
*/
private fun getFrameworkStartNanos(): Long {
// Get our timestamps in ticks: we expect ticks to be less granular than nanoseconds so,
// to ensure our measurement uses the correct number of significant figures, we convert

View File

@ -24,6 +24,9 @@ private const val FIELD_POS_STARTTIME = 21 // starttime naming matches field in
*/
open class Stat {
/**
* @throws [java.io.FileNotFoundException]
*/
@VisibleForTesting(otherwise = PRIVATE)
open fun getStatText(pid: Int): String = File("/proc/$pid/stat").readText()

File diff suppressed because one or more lines are too long