Giter VIP home page Giter VIP logo

Comments (4)

aozhimin avatar aozhimin commented on May 18, 2024

@zhihuitang 没太清楚这个问题的意思,起一个子线程每隔一秒钟就抓一次 CPU 使用情况,这样再看 1min, 5min, 15min内的CPU使用情况,能满足你这个需求吗?

from ios-monitor-platform.

zhihuitang avatar zhihuitang commented on May 18, 2024

@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.

zhihuitang avatar zhihuitang commented on May 18, 2024

在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.

aozhimin avatar aozhimin commented on May 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.