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

个人网页上传网站怎么做沈阳模板网站制作

个人网页上传网站怎么做,沈阳模板网站制作,郑州网页制作案例教程,临沂百度联系方式【Android性能优化】Android CPU占用率检测原理和优化方向 CPU相关知识 CPU占用的基本计算公式 (1 - 空闲态运行时间/总运行时间) * 100% Hz、Tick、Jiffies: Hz:Linux核心每隔固定周期会发出timer interrupt (IRQ 0),HZ是用来定义每一秒有…

【Android性能优化】Android CPU占用率检测原理和优化方向

CPU相关知识

  1. CPU占用的基本计算公式
    (1 - 空闲态运行时间/总运行时间) * 100%

  2. Hz、Tick、Jiffies:
    Hz:Linux核心每隔固定周期会发出timer interrupt (IRQ 0),HZ是用来定义每一秒有几次timer interrupts。举例来说,HZ为1000,代表每秒有1000次timer interrupts。
    通过getconf CLK_TC命令,可以查看当前系统的Hz。以某某项目为例,Hz为100。

130|console:/ # getconf CLK_TCK
100

Tick:Tick = 1/Hz,即多久发出一次timer interrupt。
以上述情况为例,则为10ms发生一次。

Jiffies:Jiffies是Linux的核心变数。用于记录系统启动后发生timer interrupt的次数,timer interrupt每发生一次,jiffies增加一次。Jiffies可以认为是Linux下CPU的单位时间;

  1. user、nice、system、idle、iowait、irq、softirq

kernel/Documentation/filesystems/proc.txt

1.8 Miscellaneous kernel statistics in /proc/stat
-------------------------------------------------Various pieces   of  information about  kernel activity  are  available in the
/proc/stat file.  All  of  the numbers reported  in  this file are  aggregates
since the system first booted.  For a quick look, simply cat the file:> cat /proc/statcpu  2255 34 2290 22625563 6290 127 456 0 0 0cpu0 1132 34 1441 11311718 3675 127 438 0 0 0cpu1 1123 0 849 11313845 2614 0 18 0 0 0intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...]ctxt 1990473btime 1062191376processes 2915procs_running 1procs_blocked 0softirq 183433 0 21755 12 39 1137 231 21459 2263The very first  "cpu" line aggregates the  numbers in all  of the other "cpuN" lines.  These numbers identify the amount of time the CPU has spent performing different kinds of work.  Time units are in USER_HZ (typically hundredths of a second).  The meanings of the columns are as follows, from left to right:- user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: twiddling thumbs
- iowait: In a word, iowait stands for waiting for I/O to complete. But thereare several problems:1. Cpu will not wait for I/O to complete, iowait is the time that a task is  waiting for I/O to complete. When cpu goes into idle state for outstanding task io, another task will be scheduled on this CPU.2. In a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.3. The value of iowait field in /proc/stat will decrease in certainconditions.So, the iowait is not reliable by reading from /proc/stat.
- irq: servicing interrupts
- softirq: servicing softirqs
- steal: involuntary wait
- guest: running a normal guest
- guest_nice: running a niced guest
  1. 第一行数字是其他所有CPUN行中的数字总和;
  2. 这些数字表示CPU执行不同工作花费的时间,时间单位为USER_HZ,一般为10ms,从左到右,各列的含义如下
标题含义
user在用户模式下执行的正常进程
niceniced进程在用户模式下执行
system在内核模式下执行的进程
idle空闲
iowait总而言之,iowait代表等待I/O完成。但是
存在以下几个问题:
1.Cpu不会等待I/O完成,iowait是任务等待I/O完成的时间。当cpu为未完成的任务io进入空闲状态时,将在该cpu上调度另一个任务。
2.在多核CPU中,等待I/O完成的任务不在任何CPU上运行,因此每个CPU的iowait很难计算。
3./proc/stat中iowait字段的值将在一定程度上减少
条件
因此,从/proc/stat读取iowait是不可靠的。
irq服务中断
softirq服务软中断
steal非自愿等待时间,另一个解释是其它系统所花的时间
guest执行时间为客户操作系统下的虚拟CPU控制
guest_nice低优先级程序所占用的用户态的cpu时间
  1. Cpu花费时间总和cpuTime = user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;

计算整机CPU占用率

根据上面的公式,我们可以采取两个时间点计算CPU总时间差值和CPU空闲时间IDLE的差值,以此得出CPU使用率;

采样两个足够短的时间间隔的cpu数据,分别记作t1、t2,其中t1、t2的结构均为:
(user、nice、system、idle、iowait、irq、softirq、stealstolen、guest、guest_nice)的10元组;(当然这里依据Linux内核的不同有些数据可能没有,就不必计入)

计算t1、t2总的cpu时间片totalCPUTime
a) 把第一次的所有cpu10元组数据求和,得到totalCPUTime1;
b) 把第二次的所有cpu10元组数据求和,得到totalCPUTime2;

计算空闲时间idle
cpu空闲时间对应第四列的数据
a)获得第一次的idle数据,记为idle1
b)获得第二次的idle数据,记为idle2

计算cpu使用率
totalCPUrate = 1 - ((totalCPUTime2-idle2)-(totalCPUTime1-idle1))/(totalCPUTime2-totalCPUTime1)x100%

计算某个进程CPU占用率

kernel/msm-5.4/Documentation/filesystems/proc.txt

The stat filecontains details information about the process itself.  Its fields are explained in Table 1-4.Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
..............................................................................Field          Contentpid           process idtcomm         filename of the executablestate         state (R is running, S is sleeping, D is sleeping in anuninterruptible wait, Z is zombie, T is traced or stopped)...cmaj_flt      number of major faults with child'sutime         user mode jiffies  utime指进程在用户态的运行时间stime         kernel mode jiffies  ;stime指进程在内核态的运行时间cutime        user mode jiffies with child's   utime指所有子进程在用户态的运行时间总和cstime        kernel mode jiffies with child's   cstime指所有子进程在核心态的运行时间总和priority      priority levelnice          nice levelnum_threads   number of threadsit_real_value	(obsolete, always 0)start_time    time the process started after system bootvsize         virtual memory sizerss           resident set memory sizersslim        current limit in bytes on the rssstart_code    address above which program text can run
...

这里只关注 utime、 stime、 cutime、 cstime,它们的总和就是该进程的CPU时间。取两个时间点进行采样并取差值,就可以得到这段时间内的该进程所占用的CPU时间片。

scheduledTime = utime + stime + cutime + sctime;
if (lastCpuTime && lastScheduledTime)cpuUsage = (scheduledTime - lastScheduledTime) * 100. / (cpuTime - lastCpuTime);
lastScheduledTime = scheduledTime;
lastCpuTime = cpuTime;

优化的基本思路和方向

  1. 确定CPU占用高的进程,使用top命令查看;
  2. 确定该进程CPU占用高的线程,top -p <PID>查看线程状态和线程CPU;
  3. 结合logcat命令和trace工具,确定该线程处于什么工作逻辑中以及相关方法耗时,(实在找不到就打断点,加日志,控制变量法);
    1. 频繁报错 —> 解决报错;
    2. 过度绘制 —> 重新布局绘制;
    3. 解码/编码 —> 排查具体算法逻辑;
    4. 频繁调用 —> 确定各个调用者,并协调修改;
http://www.15wanjia.com/news/165067.html

相关文章:

  • 开源的企业网站管理系统彩票网站维护会跑路吗
  • 如何用域名进网站怎么样网站泛解析
  • .net做的学校网站静态网站怎么建设
  • 可以做锚文本链接的网站官方网站下载免费
  • 手机网站整站源码佛山做网站的哪个好
  • 协会网站方案可自己绘图装修的app
  • 用html5做的个人网站怎么搜索别人的wordpress模板
  • 成都市微信网站建千图网免费海报素材图库
  • 做网站买二手域名长沙城乡建设网站
  • 门户网站有哪些音乐排行榜网页设计作业
  • 招聘网站建设销售网站 备案 固话
  • 企业网站不备案可以吗上海58同城官网
  • 景点网站建设线下广告宣传方式有哪些
  • 深圳网站营销推广公司电话宁波网站建设与维护
  • 徐州招聘网seo免费课程视频
  • 做网站放到百度上需要什么个人网站建设教学视频
  • 石家庄网站建设制作北京电子商务网站建设
  • 做网站的系统嘉兴做毛织的有哪些网站
  • 网站备案什么鬼自己的电脑可以做网站服务器
  • 网站排名优化推广html编写软件
  • 企业网站建设开发服务江苏有哪些做网站建设的公司
  • 优秀手机网站电子商务网站经营性icp
  • 免费wap自助建站火星建站做旅游海报哪个网站好免费的
  • 网站目标定位概念南通工程建设信息网站
  • 网站开发的概要设计模板好的企业官网建设公司
  • 合肥建站方案微信上发的链接网站怎么做的
  • 重庆网站维护公司注册空壳公司判几年
  • 沈阳网站设计运营公司软件商店最新版本
  • 烟台定制网站建设公司oa系统的功能和作用
  • 统一门户网站做网站投注代理犯罪吗