title: Monitor task CPU utilization in VxWorks while program is running
body: <p>I'm running a VxWorks 6.9 OS embedded system and I need to see when I'm starving low priority tasks. Ideally I'd like to have CPU utilization by task so I know what is eating up all my CPU time. </p>
  
  <p>I know this is a built in feature in many operating systems but have been so far unable to find it for VxWorks 6.9. </p>
  
  <p>If I can't measure by task I'd like to at least to see what percentage of time the CPU is idle. 
  To that end I've been trying to make a lowest priority task that will run the function below that would try to measure it indirectly.</p>
  
  <pre><code>float Foo::IdleTime(Foo* f)
  {
  
      bool inIdleTask;
      float timeIdle;
      float totalTime;
      float percentIdle;
  
      while(true)
      {
          startTime = _time(); //get time before before measurement starts
  
          inIdleTask = true;
          timeIdle = 0;
  
          while(inIdleTask) // I have no clue how to detect when the task left and set this to false
          {
              timeIdle += (amount_of_time_for_inner_loop); //measure idle time
  
          }
  
          returnTime = _time(); //get time after you return to IdleTime task
  
          totalTime = ( returnTime - startTime );
  
          percentIdle = ( timeIdle / totalTime ) * 100; //calculate percentage of idle time
  
          //logic to report percentIdle
  
  
      }
  </code></pre>
  
  <p>The big problem with this concept is I don't know how I would detect when this task is left for a higher priority task.</p>