Exemple #1
0
g_val_t
cpu_intr_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_intr_jiffies,  intr_jiffies,
             last_total_jiffies, total_jiffies, diff;

   if (num_cpustates == NUM_CPUSTATES_24X) {
     val.f = 0.;
     return val;
     }

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     intr_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = intr_jiffies - last_intr_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     last_intr_jiffies  = intr_jiffies;
     last_total_jiffies = total_jiffies;

   }

   return val;
}
Exemple #2
0
g_val_t
cpu_system_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_system_jiffies,  system_jiffies,
             last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     system_jiffies = strtod( p, (char **)NULL );
     if (num_cpustates > NUM_CPUSTATES_24X) {
       p = skip_token(p);
       p = skip_token(p);
       p = skip_token(p);
       system_jiffies += strtod( p, (char **)NULL ); /* "intr" counted in system */
       p = skip_token(p);
       system_jiffies += strtod( p, (char **)NULL ); /* "sintr" counted in system */
       }
     total_jiffies = total_jiffies_func();

     diff = system_jiffies - last_system_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     last_system_jiffies  = system_jiffies;
     last_total_jiffies = total_jiffies;

   }
   return val;
}
Exemple #3
0
g_val_t
cpu_gnice_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0,0};
   static double last_gnice_jiffies,  gnice_jiffies,
                 last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     gnice_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = gnice_jiffies - last_gnice_jiffies;

     if ( diff )
       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
     else
       val.f = 0.0;

     last_gnice_jiffies  = gnice_jiffies;
     last_total_jiffies = total_jiffies;

   }

   return val;
}
Exemple #4
0
g_val_t
cpu_aidle_func ( void )
{
   char *p;
   g_val_t val;
   JT idle_jiffies, total_jiffies;

   p = update_file(&proc_stat);

   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   idle_jiffies  = (JT) strtod( p , (char **)NULL );
   total_jiffies = total_jiffies_func();

   val.f = ((double)(idle_jiffies/total_jiffies)) * 100.0;

   val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)idle_jiffies, (double)total_jiffies, idle_jiffies, total_jiffies, 0, 0 );
   return val;
}
static g_val_t multi_cpu_system_func (int cpu_index)
{
    char *p;
    cpu_util *cpu = &(cpu_system[cpu_index]);
    
    p = update_file(&proc_stat);
    if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) &&
       (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) {
        cpu->stamp = proc_stat.last_read;
    
        p = find_cpu (p, cpu_index);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_whitespace(p);
        cpu->curr_jiffies = strtod(p , (char **)NULL);
        if (num_cpustates > NUM_CPUSTATES_24X) {
            p = skip_token(p);
            p = skip_token(p);
            p = skip_token(p);
            p = skip_whitespace(p);

            cpu->curr_jiffies += strtod(p , (char **)NULL); /* "intr" counted in system */
            p = skip_token(p);
            cpu->curr_jiffies += strtod(p , (char **)NULL); /* "sintr" counted in system */
        }
        cpu->curr_total_jiffies = total_jiffies_func();
    
        cpu->diff = cpu->curr_jiffies - cpu->last_jiffies;
    
        if (cpu->diff)
            cpu->val.f = (cpu->diff/(cpu->curr_total_jiffies - cpu->last_total_jiffies))*100;
        else
            cpu->val.f = 0.0;
    
        cpu->last_jiffies = cpu->curr_jiffies;
        cpu->last_total_jiffies = cpu->curr_total_jiffies;   
    }

    return cpu->val;
}
g_val_t 
cpu_system_func ( void )
{
   char *p;
   static g_val_t val;
   static int stamp;
   static double last_system_jiffies,  system_jiffies,
                 last_total_jiffies, total_jiffies, diff;
 
   p = update_file(&proc_stat);
   if(proc_stat.last_read != stamp) {
     stamp = proc_stat.last_read;
     
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     system_jiffies = strtod( p , (char **)NULL );
     if (num_cpustates > NUM_CPUSTATES_24X) {
       p = skip_token(p);
       p = skip_token(p);
       p = skip_token(p);
       system_jiffies += strtod( p , (char **)NULL );
       p = skip_token(p);
       system_jiffies += strtod( p , (char **)NULL );
       }
     total_jiffies  = total_jiffies_func();

     diff = system_jiffies  - last_system_jiffies;
 
     if ( diff )
       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
     else
       val.f = 0.0;
 
     last_system_jiffies  = system_jiffies;
     last_total_jiffies = total_jiffies;   

   }
   return val;
}
Exemple #7
0
g_val_t
cpu_idle_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_idle_jiffies,  idle_jiffies,
             last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     idle_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = idle_jiffies - last_idle_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)diff, (double)(total_jiffies - last_total_jiffies), idle_jiffies, last_idle_jiffies, total_jiffies, last_total_jiffies );

     last_idle_jiffies  = idle_jiffies;
     last_total_jiffies = total_jiffies;

   }

   return val;
}
Exemple #8
0
double cpu_user_func ( void ) {
	char *p;
	double val;
	double last_user_jiffies,  user_jiffies, 
                 last_total_jiffies, total_jiffies, diff;
   
	p = update_file(&proc_stat);

	p = skip_token(p);
	user_jiffies  = strtod( p , (char **)NULL );
	total_jiffies = total_jiffies_func();

	diff = user_jiffies - last_user_jiffies; 

	if ( diff )
	val = (diff/(total_jiffies - last_total_jiffies))*100;
	else
	val = 0.0;

	last_user_jiffies  = user_jiffies;
	last_total_jiffies = total_jiffies;

	return val;
}