[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] How does xentop.c code gets previous sample to calculate CPU utilization ?


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • From: Mahendra Kutare <mahendra.kutare@xxxxxxxxx>
  • Date: Wed, 24 Nov 2010 10:41:07 -0500
  • Delivery-date: Wed, 24 Nov 2010 07:42:36 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=A6kyZTweBMVa2yOqhH3Uif9OQx/MajelKHj0gSyF5oIsoS5Vfo4pNgZ8HDBDTLN/Eu Ioq2AZaZ+TIg9jqRFLcHdOo4CkLhfm2LPfHJsIqu/9qL1XRMb3bjwQ4S/CF49lXKLIrU lz2EZFYZAmWWH1nvMXEqEhzvApnpy6306nLPw=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.