[libvirt] [PATCH] cpu usage in OpenVZ
Evgeniy Sokolov
evg at openvz.org
Fri Jul 18 09:41:34 UTC 2008
> On Thu, Jul 17, 2008 at 03:04:46PM +0400, Evgeniy Sokolov wrote:
>> OpenVZ calculate statistics and allow to get them .
>> Added function for getting cpu usage of container.
>
> Modular some minor comments, ACK for this patch.
>
>> + if (!openvzIsActiveVM(vm)) {
>> + info->cpuTime = 0;
>> + } else {
>> + if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
>> + openvzError(dom->conn, VIR_ERR_OPERATION_FAILED, ("cannot read cputime for domain"));
>
> Need to have a leading '_' in front of the string to be mark
> for translation.
>
>> + return -1;
>> + }
>> + }
>> +
>> /* TODO These need to be calculated differently for OpenVZ */
>> //info->cpuTime =
>> //info->maxMem = vm->def->maxmem;
>> @@ -689,6 +700,48 @@ static int openvzListDefinedDomains(virC
>> return got;
>> }
>>
>> +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) {
>> + int fd;
>> + char line[PATH_MAX] ;
>
> Best to use something else as the size here - we're not reading
> a path & we should try to eliminate uses of PATH_MAX in libvirt,
> since POSIX allows for it to be undefine, or stupidly huge. I
> reckon 1024 would do the job for line length in this case.
>
>> + if (readvps != vpsid) /*not found*/
>> + return -1;
>> +
>> + /* convert jiffies to nanoseconds */
>> + *cpuTime = 1000ull * 1000ull * 1000ull * (usertime + nicetime + systime) / (unsigned long long)sysconf(_SC_CLK_TCK);
>
> Can we break this expression across multiple lines to avoid going
> soo far over 80 chars.
>
> Daniel
Thanks! I completely forgot basic rules.
fixed patch is attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-openvz-cpu_usage.diff
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20080718/9256827a/attachment-0001.bin>
More information about the libvir-list
mailing list