提交 38ab1225 编写于 作者: J Jiri Denemark

virsh: Use virDomainGetJobStats in domjobinfo if available

上级 34fd9427
...@@ -4914,64 +4914,189 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -4914,64 +4914,189 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainJobInfo info; virDomainJobInfo info;
virDomainPtr dom; virDomainPtr dom;
bool ret = true; bool ret = false;
const char *unit;
double val;
virTypedParameterPtr params = NULL;
int nparams = 0;
unsigned long long value;
int rc;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
if (virDomainGetJobInfo(dom, &info) == 0) { memset(&info, 0, sizeof(info));
const char *unit;
double val;
vshPrint(ctl, "%-17s ", _("Job type:")); rc = virDomainGetJobStats(dom, &info.type, &params, &nparams, 0);
switch (info.type) { if (rc == 0) {
case VIR_DOMAIN_JOB_BOUNDED: if (virTypedParamsGetULLong(params, nparams,
vshPrint(ctl, "%-12s\n", _("Bounded")); VIR_DOMAIN_JOB_TIME_ELAPSED,
break; &info.timeElapsed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_TIME_REMAINING,
&info.timeRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_TOTAL,
&info.dataTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_PROCESSED,
&info.dataProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_REMAINING,
&info.dataRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_TOTAL,
&info.memTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_PROCESSED,
&info.memProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_REMAINING,
&info.memRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_TOTAL,
&info.fileTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_PROCESSED,
&info.fileProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_REMAINING,
&info.fileRemaining) < 0)
goto save_error;
} else if (last_error->code == VIR_ERR_NO_SUPPORT) {
vshDebug(ctl, VSH_ERR_DEBUG, "detailed statistics not supported\n");
vshResetLibvirtError();
rc = virDomainGetJobInfo(dom, &info);
}
if (rc < 0)
goto cleanup;
case VIR_DOMAIN_JOB_UNBOUNDED: vshPrint(ctl, "%-17s ", _("Job type:"));
vshPrint(ctl, "%-12s\n", _("Unbounded")); switch (info.type) {
break; case VIR_DOMAIN_JOB_BOUNDED:
vshPrint(ctl, "%-12s\n", _("Bounded"));
break;
case VIR_DOMAIN_JOB_NONE: case VIR_DOMAIN_JOB_UNBOUNDED:
default: vshPrint(ctl, "%-12s\n", _("Unbounded"));
vshPrint(ctl, "%-12s\n", _("None")); break;
goto cleanup;
}
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time elapsed:"), info.timeElapsed); case VIR_DOMAIN_JOB_NONE:
if (info.type == VIR_DOMAIN_JOB_BOUNDED) default:
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining); vshPrint(ctl, "%-12s\n", _("None"));
if (info.dataTotal || info.dataRemaining || info.dataProcessed) { goto cleanup;
val = vshPrettyCapacity(info.dataProcessed, &unit); }
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit);
val = vshPrettyCapacity(info.dataRemaining, &unit); vshPrint(ctl, "%-17s %-12llu ms\n", _("Time elapsed:"), info.timeElapsed);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit); if (info.type == VIR_DOMAIN_JOB_BOUNDED)
val = vshPrettyCapacity(info.dataTotal, &unit); vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit);
} if (info.dataTotal || info.dataRemaining || info.dataProcessed) {
if (info.memTotal || info.memRemaining || info.memProcessed) { val = vshPrettyCapacity(info.dataProcessed, &unit);
val = vshPrettyCapacity(info.memProcessed, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit); val = vshPrettyCapacity(info.dataRemaining, &unit);
val = vshPrettyCapacity(info.memRemaining, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit); val = vshPrettyCapacity(info.dataTotal, &unit);
val = vshPrettyCapacity(info.memTotal, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit); }
}
if (info.fileTotal || info.fileRemaining || info.fileProcessed) { if (info.memTotal || info.memRemaining || info.memProcessed) {
val = vshPrettyCapacity(info.fileProcessed, &unit); val = vshPrettyCapacity(info.memProcessed, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit);
val = vshPrettyCapacity(info.fileRemaining, &unit); val = vshPrettyCapacity(info.memRemaining, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit);
val = vshPrettyCapacity(info.fileTotal, &unit); val = vshPrettyCapacity(info.memTotal, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit);
} }
} else {
ret = false; if (info.fileTotal || info.fileRemaining || info.fileProcessed) {
val = vshPrettyCapacity(info.fileProcessed, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit);
val = vshPrettyCapacity(info.fileRemaining, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit);
val = vshPrettyCapacity(info.fileTotal, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit);
} }
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_CONSTANT,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-12llu\n", _("Constant pages:"), value);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_NORMAL,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-12llu\n", _("Normal pages:"), value);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_NORMAL_BYTES,
&value)) < 0) {
goto save_error;
} else if (rc) {
val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Normal data:"), val, unit);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DOWNTIME,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-12llu ms\n", _("Expected downtime:"), value);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_COMPRESSION_CACHE,
&value)) < 0) {
goto save_error;
} else if (rc) {
val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compression cache:"), val, unit);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_COMPRESSION_BYTES,
&value)) < 0) {
goto save_error;
} else if (rc) {
val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compressed data:"), val, unit);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_COMPRESSION_PAGES,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-13llu\n", _("Compressed pages:"), value);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_COMPRESSION_CACHE_MISSES,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-13llu\n", _("Compression cache misses:"), value);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_COMPRESSION_OVERFLOW,
&value)) < 0) {
goto save_error;
} else if (rc) {
vshPrint(ctl, "%-17s %-13llu\n", _("Compression overflows:"), value);
}
ret = true;
cleanup: cleanup:
virDomainFree(dom); virDomainFree(dom);
virTypedParamsFree(params, nparams);
return ret; return ret;
save_error:
vshSaveLibvirtError();
goto cleanup;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册