[libvirt] [PATCH] qemu: add reporting of vCPU wait time

Ján Tomko jtomko at redhat.com
Tue Jan 5 12:05:27 UTC 2016


On Thu, Dec 10, 2015 at 02:41:56PM +0000, Daniel P. Berrange wrote:
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 783a7cd..5293294 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -1361,6 +1361,80 @@ static char *qemuConnectGetCapabilities(virConnectPtr conn) {
>  
>  
>  static int
> +qemuGetSchedInfo(unsigned long long *cpuWait,
> +                 pid_t pid, pid_t tid)
> +{
> +    char *proc = NULL;
> +    char *data = NULL;
> +    char **lines = NULL;
> +    size_t i;
> +    int ret = -1;
> +    double val;
> +
> +    *cpuWait = 0;
> +

> +    /* In general, we cannot assume pid_t fits in int; but /proc parsing
> +     * is specific to Linux where int works fine.  */
> +    if (tid)
> +        ret = virAsprintf(&proc, "/proc/%d/task/%d/sched", (int)pid, (int)tid);
> +    else
> +        ret = virAsprintf(&proc, "/proc/%d/sched", (int)pid);
> +    if (ret < 0)
> +        goto cleanup;
> +

After this hunk, ret contains the positive integer returned by
virAsprintf instead of the expected value of -1.

> +    /* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */
> +    if (access(proc, R_OK) < 0)
> +        return 0;
> +
> +    if (virFileReadAll(proc, (1<<16), &data) < 0)
> +        goto cleanup;
> +
> +    lines = virStringSplit(data, "\n", 0);
> +    if (!lines)
> +        goto cleanup;
> +
> +    for (i = 0; lines[i] != NULL; i++) {
> +        const char *line = lines[i];
> +
> +        /* Needs CONFIG_SCHEDSTATS. The second check
> +         * is the old name the kernel used in past */
> +        if (STRPREFIX(line, "se.statistics.wait_sum") ||
> +            STRPREFIX(line, "se.wait_sum")) {
> +            line = strchr(line, ':');
> +            if (!line) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("Missing separate in sched info '%s'"),
> +                               lines[i]);
> +                goto cleanup;
> +            }
> +            line++;
> +            while (*line == ' ') {
> +                line++;
> +            }

This breaks syntax check:

Curly brackets around single-line body:
src/qemu/qemu_driver.c:1411-1413:
            while (*line == ' ') {
                line++;
            }

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160105/cffe2b83/attachment-0001.sig>


More information about the libvir-list mailing list