我能够获得 GPU 最大频率 /sys/class/kgsl/kgsl-3d0/max_gpuclk 对我来说是 840000000
但是当我尝试从此 /sys/class/kgsl/kgsl-3d0/gpuclk 获取 GPU 当前频率时,我收到错误此错误 -> gpuinfo java.io.FileNotFoundException: /sys/class/kgsl/kgsl-3d0/gpuclk :打开失败:EACCES(权限被拒绝)
我已尝试允许所有权限。
try {
Log.d(
"GPU Info",
"gpuinfo test max" + getGPUFreq("/sys/class/kgsl/kgsl-3d0/max_gpuclk")
)
Log.d(
"GPU Info",
"gpuinfo test curr" + getGPUFreq("/sys/class/kgsl/kgsl-3d0/gpuclk")
)
val gpuFile = File("/sys/class/kgsl/kgsl-3d0/gpuclk")
if (gpuFile.exists()) {
val fis = FileInputStream(gpuFile)
val reader = BufferedReader(InputStreamReader(fis))
var line: String
while (reader.readLine().also { line = it } != null) {
// 'line' contains the content of the file
// You can process or display the content as needed
// For example, you can log it:
Log.d("GPU Info", "gpuinfo$line")
}
// Close the resources when done
reader.close()
fis.close()
} else {
// Handle the case where the file does not exist
Log.d("GPU Info", "gpuinfo he file does not exist")
}
} catch (e: java.lang.Exception) {
// Handle exceptions appropriately
e.printStackTrace()
Log.d("GPU Info", "gpuinfo $e")
}
fun getGPUFreq(path: String): Int? {
return readIntegerFile(path)
}
private fun readIntegerFile(path: String): Int? {
var ret = 0
try {
val reader = RandomAccessFile(path, "r")
ret = try {
val line = reader.readLine()
line.toInt()
} finally {
reader.close()
}
} catch (ex: Exception) {
ex.printStackTrace()
}
return ret
}
这篇文章来自 读取 CPU 使用情况时出错:/proc/stat(权限被拒绝) 指出: