当前位置: 首页 > news >正文

电网站建设用地赔偿在线网页视频提取

电网站建设用地赔偿,在线网页视频提取,免费建立个人网站的视频,网站标题算关键词优化吗最近在优化 App 的性能,需要获取当前 CPU视频频率和占用率,通过查询资料,大致思路如下: 目前没有标准的 API 来获取 CPU 的使用频率,只能通过读取指定 CPU 文件获取当前 CPU 频率,在某些机器或者特定版本中…

最近在优化 App 的性能,需要获取当前 CPU视频频率和占用率,通过查询资料,大致思路如下:

目前没有标准的 API 来获取 CPU 的使用频率,只能通过读取指定 CPU 文件获取当前 CPU 频率,在某些机器或者特定版本中,可能需要ROOT 权限或者特殊权限,因此会存在一定几率的失败,因此需要做好 Try…catch 动作。又因为现在手机 CPU 的多核数目,因此我们可能需要获取多个 CPU 频率数,并取平均值。

获取系统 CPU 核心数:

 val cpuCoreNum = Runtime.getRuntime().availableProcessors()

获取指定 CPU 当前频率:

/sys/devices/system/cpu/cpu${index}/cpufreq/scaling_cur_freq

那么核心代码为:

private fun getAllCpuCoreFrequency() : Long {var frequency = 0Lfor (index in 0 until  cpuCoreNum){frequency += readFile("/sys/devices/system/cpu/cpu$index/cpufreq/scaling_cur_freq")}BLog.d("frequency : $frequency")return frequency / cpuCoreNum}private fun readFile(filePath: String): Long{try {val file = RandomAccessFile(filePath, "r")val content = file.readLine()file.close()if (TextUtils.isEmpty(content)){return 0L}BLog.d("readFile content : $content")return content.trim().toLong()}catch (e : Exception){e.printStackTrace()return 0L}}

如果需要获取 CPU 的占用率,那么就需要知道每个核心的最大频率和最小频率,同样是通过文件获取:

//max frequency file
/sys/devices/system/cpu/cpu${index}/cpufreq/cpuinfo_max_freq//min frequency file
/sys/devices/system/cpu/cpu${index}/cpufreq/cpuinfo_min_freq

那么核心代码为:

object CPUUtils {private var cpuCoreNum = 0private var cpuMaxFrequency = 0Lprivate var cpuMinFrequency = 0Lfun initCpuCoreNum(){if (cpuCoreNum <= 0 || cpuMaxFrequency <= 0L || cpuMinFrequency <= 0L){cpuCoreNum = Runtime.getRuntime().availableProcessors()initMaxAndMinFrequency()if (cpuCoreNum > 0 && cpuMaxFrequency > 0L && cpuMinFrequency > 0L){SpManager.getInstance().setCanUseCPUFrequency(true)}}BLog.d("cpuCoreNum : $cpuCoreNum")}private fun initMaxAndMinFrequency()  {if (cpuCoreNum <= 0){return}cpuMaxFrequency = 0LcpuMinFrequency = 0Lfor (index in 0 until cpuCoreNum){cpuMaxFrequency += readFile("/sys/devices/system/cpu/cpu${index}/cpufreq/cpuinfo_max_freq")cpuMinFrequency += readFile("/sys/devices/system/cpu/cpu${index}/cpufreq/cpuinfo_min_freq")}BLog.d("cpuMaxFrequency : $cpuMaxFrequency, cpuMinFrequency : $cpuMinFrequency")}private fun readFile(filePath: String): Long{try {val file = RandomAccessFile(filePath, "r")val content = file.readLine()file.close()if (TextUtils.isEmpty(content)){return 0L}BLog.d("readFile content : $content")return content.trim().toLong()}catch (e : Exception){ExceptionHandler.recordException(e)return 0L}}private fun getAllCpuCoreFrequency() : Long {initCpuCoreNum()if (cpuCoreNum <=0){return 0L}var frequency = 0Lfor (index in 0 until  cpuCoreNum){frequency += readFile("/sys/devices/system/cpu/cpu$index/cpufreq/scaling_cur_freq")}BLog.d("frequency : $frequency")return frequency}fun findCurrentFrequencyPercent() : Long {val currentFrequency = getAllCpuCoreFrequency()BLog.d("currentFrequency : $currentFrequency, cpuMinFrequency : $cpuMinFrequency, cpuMaxFrequency : $cpuMaxFrequency")if (cpuMaxFrequency - cpuMinFrequency <= 0L || currentFrequency - cpuMinFrequency < 0L || cpuMaxFrequency - currentFrequency < 0L){return 0L}return (currentFrequency - cpuMinFrequency) * 100 / (cpuMaxFrequency - cpuMinFrequency)}fun getCpuCoreFrequency() : Long {initCpuCoreNum()if (cpuCoreNum <=0){return 0L}return getAllCpuCoreFrequency() / cpuCoreNum}}

获取 CPU 频率:

CPUUtils.getCpuCoreFrequency()

获取 CPU 占用率:

CPUtils.findCurrentFrequencyPercent()
http://www.yayakq.cn/news/681095/

相关文章:

  • 哪些网站是用php编写的用vue做网站
  • 网站建设万首先金手指14网站做302重定向会怎么样
  • 网站开发源代码广告字制作哪家好
  • 百度上的网站怎么做办公室装修设计图片
  • 亚马逊全球开店官方网站宁德网络推广
  • 越秀电子商务网站建设个人网站备案网址导航
  • 怎么编写自己的网站网页设计公司兴田德润在那里
  • 北京网站建设知名公司常州网站建设电话
  • 政务咨询投诉举报网站建设智慧团建系统官方网站登录
  • 建设一个官方网站多少钱国外有名的设计网站
  • wordpress post 属性郑州seo网站推广
  • 网站建设的步骤图片过程江宁区财政局网站开发区分局
  • 杭州网站建设求职简历怎么找到外贸公司采购
  • 手机怎么做淘客网站营销网站文章去那找
  • 怎么建立自己的个人网站广东建设工程信息网站6
  • 一个网站如何产生流量cms建站系统免费
  • 正在建设中网站linux xampp wordpress
  • 网站如果不备案WordPress目录怎么发表文章
  • 工业设计公司网站如何建设建设网站怎么赚钱的
  • 免费网站制作报价新手小白怎样运营1688店铺
  • 中山建设公司网站网页布局设计的一般步骤
  • 南宁物流公司网站建设潜江人才网官网
  • 黄州做网站的免费ppt模板软件
  • 掌握商务网站建设内容电商app开发
  • 山西网站开发建设企业微信app开发
  • dede手机网站建设教程建设网站的工具是什么
  • 淮安做微信网站漂亮的网站底部代码
  • 绍兴建设用地使用权网站dz多语言企业网站
  • 自己搭建网站只有文字物流企业网站模板下载
  • 网站建设费走什么费用大数据