android_cpu/memory/进程/线程

 

 

 

 

  View的computeScroll():Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a {android.widget.Scroller Scroller} object.
  一个pid,可以对应多个packageName; pid,进程id,Android规定android.system.uid=1000;uid,进程所在的用户id,即该进程是有谁启动的root/普通用户等;
  ActivityManager的getRunningAppProcesses():Returns a list of application processes that are running on the device.
  ActivityManager的getMyMemoryState():Return global memory state information for the calling process. This does not fill in all fields of the ActivityManager.RunningAppProcessInfo. The only fields that will be filled in are pid, uid, lastTrimLevel, importance, lru, and importanceReasonCode.
  ActivityManager的getMemoryInfo():Return general information about the memory state of the system. This can be used to help decide how to manage your own memory, though note that polling is not recommended and ComponentCallbacks2.onTrimMemory(int) is the preferred way to do this. Also see getMyMemoryState(ActivityManager.RunningAppProcessInfo) for how to retrieve the current trim level of your process as needed, which gives a better hint for how to manage its memory.
  killBackgroundProcess(packageName)说明:立即杀掉给定包名的进程,释放进程占用的资源(内存等),如果需要,系统会再次重新启动该进程。 PS:系统进程是杀不死的,只能杀死用户进程。但我没有找到好的方法辨别系统进程还是用户进程。但可以肯定的是,能够杀死的一定是用户进程。
  This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.
  在1.5-2.1中,杀掉进程,mActivityManager.restartPackage(packageName);This method was deprecated in API level 8.
  ActivityManager的restartPackage(packageName):This is now just a wrapper for killBackgroundProcesses(String); the previous behavior here is no longer available to applications because it allows them to break other applications by removing their alarms, stopping their services, etc.
  服务自动重启方法:重写onStartCommand(**){ return Service.START_NOT_STICKY;} 
  Process类:Tools for managing OS processes.
  Process.killProcess(appProcessInfo.pid):Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.
  实现重启Process.killProcess(),测试方法,获取当前进程id:Process.myPid();获取当前线程id:Thread.currentThread().getId()
  FORCE_STOP_PACKAGES:Permission is only granted to system apps.
  Integer类extends Number implements Comparable<Integer>{ ***  }
  抽象类: Number implements java.io.Serializable { *** }
  控制CPU使用率"/proc/stat",usage=(currTotal-total)*100.0f/(currTotal-total+currIdle-idle);  空余内存:ActivityManager.MemoryInfo;   内存总大小:"/proc/meminfo"

 

 

 

 在Linux系统中,可以用/proc/stat文件来计算cpu的利用率。这个文件包含了所有CPU活动的信息,该文件中的所有值都是从系统启动开始累计到当前时刻
 输出解释CPU 以及CPU0、CPU1、CPU2、CPU3、CPU4、CPU5、CPU6、每行的每个参数意思(以第一行为例)为:
 参数解释 user (65376847) 从系统启动开始累计到当前时刻,用户态的CPU时间(单位:jiffies) ,不包含 nice值为负进程。1jiffies=0.01秒
 nice (362756) 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间(单位:jiffies)
 system (2405159) 从系统启动开始累计到当前时刻,核心时间(单位:jiffies)
 idle (10834971593) 从系统启动开始累计到当前时刻,除硬盘IO等待时间以外其它等待时间(单位:jiffies)
 iowait (3765180) 从系统启动开始累计到当前时刻,硬盘IO等待时间(单位:jiffies) ,
 irq (93399) 从系统启动开始累计到当前时刻,硬中断时间(单位:jiffies)
 softirq (2395097) 从系统启动开始累计到当前时刻,软中断时间(单位:jiffies)
 CPU时间=user+system+nice+idle+iowait+irq+softirq “intr”这行给出中断的信息,第一个为自系统启动以来,发生的所有的中断的次数;然后每个数对应一个特定的中断自系统启动以来所发生的次数。
 “ctxt”给出了自系统启动以来CPU发生的上下文交换的次数。
 “btime”给出了从系统启动到现在为止的时间,单位为秒。
 “processes (total_forks) 自系统启动以来所创建的任务的个数目。
 “procs_running”:当前运行队列的任务的数目。
 “procs_blocked”:当前被阻塞的任务的数目。
 那么CPU利用率可以使用以下两个方法。先取两个采样点,然后计算其差值:cpu usage=(idle2-idle1)/(cpu2-cpu1)*100cpu usage=[(user_2 +sys_2+nice_2) - (user_1 + sys_1+nice_1)]/(total_2 - total_1)*100

 

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值