|
|
|
|
|
|
|
|
|
|
xen-devel
[Xen-devel] How does xentop.c code gets previous sample to calculate CPU
Hi,
I am creating my sample code which takes most of the cpu utilization code from xentop.c under tools/xenstat/ for cpu and memory utilization calculation.
I see somehow the cpu utilization always shows zero because it always sees prev_node as zero of the following -
475 /* Computes the CPU percentage used for a specified domain */ 476 static double get_cpu_pct(xenstat_domain *domain) 477 { 478 xenstat_domain *old_domain;
479 double us_elapsed; 480 481 /* Can't calculate CPU percentage without a previous sample. */ 482 if(prev_node == NULL)
483 return 0.0; 484 485 old_domain = xenstat_node_domain(prev_node, xenstat_domain_id(domain));
486 if(old_domain == NULL) 487 return 0.0; 488 489 /* Calculate the time elapsed in microseconds */ 490 us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0
491 +(curtime.tv_usec - oldtime.tv_usec)); 492 493 /* In the following, nanoseconds must be multiplied by 1000.0 to 494 * convert to microseconds, then divided by 100.0 to get a percentage,
495 * resulting in a multiplication by 10.0 */ 496 return ((xenstat_domain_cpu_ns(domain) 497 -xenstat_domain_cpu_ns(old_domain))/10.0)/us_elapsed; 498 }
I have looked around in tools/xenstats/xentop.c code and have used the same functions with same code. But somehow I am missing something here. It is clearly mentioned in above code on line 481 that it requires previous samples and somehow in my code I am not supplying that and xentop is doing it.
I am trying to figure out how does xentop.c provides the previous sample for CPU utilization...so that I can do the same in my code but no luck so far after I have looked and used the same code.
Any pointers would be useful ?
Thanks Mahendra
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
<Prev in Thread] |
Current Thread |
[Next in Thread> |
- [Xen-devel] How does xentop.c code gets previous sample to calculate CPU utilization ?,
Mahendra Kutare <=
|
|
|
|
|