Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7034747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:13:23+00:00 2026-05-28T01:13:23+00:00

#include <mach/mach_init.h> #include <mach/mach_error.h> #include <mach/mach_host.h> #include <mach/vm_map.h> static unsigned long long _previousTotalTicks =

  • 0
#include <mach/mach_init.h>
#include <mach/mach_error.h>
#include <mach/mach_host.h>
#include <mach/vm_map.h>

static unsigned long long _previousTotalTicks = 0;
static unsigned long long _previousIdleTicks = 0;

// Returns 1.0f for "CPU fully pinned", 0.0f for "CPU idle", or somewhere in between
// You'll need to call this at regular intervals, since it measures the load between
// the previous call and the current one.
float GetCPULoad()
{
    host_cpu_load_info_data_t cpuinfo;
    mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
    if (host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpuinfo, &count) == KERN_SUCCESS)
    {
        unsigned long long totalTicks = 0;
        for(int i=0; i<CPU_STATE_MAX; i++) totalTicks += cpuinfo.cpu_ticks[i];
        sysLoadPercentage = CalculateCPULoad(cpuinfo.cpu_ticks[CPU_STATE_IDLE], totalTicks);
    }
    else return -1.0f;
}

float CalculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks)
{
   unsigned long long totalTicksSinceLastTime = totalTicks-_previousTotalTicks;
   unsigned long long idleTicksSinceLastTime  = idleTicks-_previousIdleTicks;
   float ret = 1.0f-((totalTicksSinceLastTime > 0) ? ((float)idleTicksSinceLastTime)/totalTicksSinceLastTime : 0);
   _previousTotalTicks = totalTicks;
   _previousIdleTicks  = idleTicks;
   return ret;
}

I have a few questions about the code which I was hoping you could help me out with:

  • What is a “host_cpu_load_info_data_t” structure? What is it used for?
  • What is a “mach_msg_type_number_t” structure? What is it used for?
  • What is the preprocessor definition “HOST_CPU_LOAD_INFO_COUNT” and its use?
  • What is the host_statistics function?
  • What do each of the arguments listed above for the host_statistics function mean? (never seen them before)
  • What is the preprocessor definition CPU_STATE_MAX and CPU_STATE_IDLE?
  • What is the preprocessor definition KERN_SUCCESS?

If not possible to answer, please reference me to a site that contains ALL these answers. I already tried googling it but couldn’t find any answers, nor could I find any documentation. Also, if the question is too specific I will delete the question, please suggest a source where a question like this would be valid though.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:13:24+00:00Added an answer on May 28, 2026 at 1:13 am

    The site that contains “ALL these answers” is http://www.opensource.apple.com/source/xnu/xnu-1699.24.8/. You might also find the book Mac OS X Internals (by Amit Singh) useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
#include <iostream> #include <queue> using namespace std; struct Call { Call( int callNum, long
#include <pthread.h> static void * worker_thread(void *); void some_func(void) { pthread_t * tmp; tmp
#include<stdio.h> #include<string.h> #define USER_MEM (10*1024) typedef struct { unsigned short int vol_level; int mute_stat;
#include <stdio.h> int main() { FILE *f; unsigned int num[80]; int i=0; int rv;
#include <iostream> using namespace std; int main() { double u = 0; double w
include(conn.php); $result = mysql_query(SELECT * FROM sggame); while($row = mysql_fetch_assoc($result)); { $id = $row['id'];
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
include 'header.php'; // ... some code header('Location:index.php'); exit; The above code keeps giving me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.