Comments (4)
@zhihuitang 没太清楚这个问题的意思,起一个子线程每隔一秒钟就抓一次 CPU 使用情况,这样再看 1min, 5min, 15min内的CPU使用情况,能满足你这个需求吗?
from ios-monitor-platform.
@aozhimin 谢谢,在Swift中已经找到方法了, 就是获得uptime后面的CPU占用率(1min, 5min, 15min)
func getCPULoadAvg() -> [Double]{
var loadAvg = [Double](repeating: 0, count: 3)
getloadavg(&loadAvg, 3)
return loadAvg
}
from ios-monitor-platform.
在Objective-C中是这样的:
typedef struct {
double m1;
double m5;
double m15;
} Upclodavg;
+ (Upclodavg)lodavg {
double loadavg[3];
getloadavg(loadavg, 3);
Upclodavg cpuLoadAvg = {0,0,0};
// 1 mins
cpuLoadAvg.m1 = loadavg[0];
// 5 mins
cpuLoadAvg.m5 = loadavg[1];
// 15 mins
cpuLoadAvg.m15 = loadavg[2];
return cpuLoadAvg;
}
from ios-monitor-platform.
@zhihuitang 好的,明白了,
Libc 的 getloadavg
/*
* getloadavg() -- Get system load averages.
*
* Put `nelem' samples into `loadavg' array.
* Return number of samples retrieved, or -1 on error.
*/
int
getloadavg(loadavg, nelem)
double loadavg[];
int nelem;
{
struct loadavg loadinfo;
int i, mib[2];
size_t size;
mib[0] = CTL_VM;
mib[1] = VM_LOADAVG;
size = sizeof(loadinfo);
if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0)
return (-1);
nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t));
for (i = 0; i < nelem; i++)
loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale;
return (nelem);
}
from ios-monitor-platform.
Related Issues (20)
- API 图形化 HOT 3
- 使用NSProxy的时候遇到问题了 HOT 9
- 新增流量监控的实现方式
- resident_size 大小问题 HOT 2
- 有webview内的h5性能监控方面的资料吗 HOT 2
- 楼主能不能给一个系统CPU的demo HOT 1
- 弱弱问一句,楼主博客文章的用的配色是什么方案,文章看下来很舒服
- 如何使用NSProxy
- ReadMe中的获取应用占用内存方法错误
- 你好,你这边的数据可视化是怎么做的呢
- 总结较全面了,GPU 也可以加一下
- 关于冷热启动的概念描述不对
- 注意文章引用问题
- 有源码借鉴吗
- 有swift版本吗 谢谢 HOT 1
- 使用CFReadStreamCreateForHTTPRequest 截取网络请求,无果!
- Readme里关于`vm_statistics_data_t`的描述
- Xcode13 thread_info failed
- 发现获取cpu频率的函数iOS上并不能正常工作 HOT 50
- 网络监控里面为什么不直接hook socket HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-monitor-platform.