提交 350d6ccb 编写于 作者: M Martin Kletzander 提交者: Daniel Veillard

Added RSS information gathering into qemudGetProcessInfo

One more parameter added into the function parsing /proc/<pid>/stat
and the call of the function is fixed as well.
上级 f0495ae9
...@@ -1055,12 +1055,13 @@ cleanup: ...@@ -1055,12 +1055,13 @@ cleanup:
static int static int
qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid, qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
int tid) int pid, int tid)
{ {
char *proc; char *proc;
FILE *pidinfo; FILE *pidinfo;
unsigned long long usertime, systime; unsigned long long usertime, systime;
long rss;
int cpu; int cpu;
int ret; int ret;
...@@ -1077,6 +1078,8 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid, ...@@ -1077,6 +1078,8 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid,
*cpuTime = 0; *cpuTime = 0;
if (lastCpu) if (lastCpu)
*lastCpu = 0; *lastCpu = 0;
if (vm_rss)
*vm_rss = 0;
VIR_FREE(proc); VIR_FREE(proc);
return 0; return 0;
} }
...@@ -1088,10 +1091,10 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid, ...@@ -1088,10 +1091,10 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid,
/* pid -> stime */ /* pid -> stime */
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu" "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu"
/* cutime -> endcode */ /* cutime -> endcode */
"%*d %*d %*d %*d %*d %*u %*u %*d %*u %*u %*u %*u" "%*d %*d %*d %*d %*d %*d %*u %*u %ld %*u %*u %*u"
/* startstack -> processor */ /* startstack -> processor */
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d", "%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime, &systime, &cpu) != 3) { &usertime, &systime, &rss, &cpu) != 4) {
VIR_FORCE_FCLOSE(pidinfo); VIR_FORCE_FCLOSE(pidinfo);
VIR_WARN("cannot parse process status data"); VIR_WARN("cannot parse process status data");
errno = -EINVAL; errno = -EINVAL;
...@@ -1108,9 +1111,16 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid, ...@@ -1108,9 +1111,16 @@ qemudGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, int pid,
if (lastCpu) if (lastCpu)
*lastCpu = cpu; *lastCpu = cpu;
/* We got pages
* We want kiloBytes
* _SC_PAGESIZE is page size in Bytes
* So calculate, but first lower the pagesize so we don't get overflow */
if (vm_rss)
*vm_rss = rss * (sysconf(_SC_PAGESIZE) >> 10);
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d",
pid, tid, usertime, systime, cpu); VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d rss=%ld",
pid, tid, usertime, systime, cpu, rss);
VIR_FORCE_FCLOSE(pidinfo); VIR_FORCE_FCLOSE(pidinfo);
...@@ -2135,7 +2145,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, ...@@ -2135,7 +2145,7 @@ static int qemudDomainGetInfo(virDomainPtr dom,
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
info->cpuTime = 0; info->cpuTime = 0;
} else { } else {
if (qemudGetProcessInfo(&(info->cpuTime), NULL, vm->pid, 0) < 0) { if (qemudGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) {
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("cannot read cputime for domain")); _("cannot read cputime for domain"));
goto cleanup; goto cleanup;
...@@ -3717,6 +3727,7 @@ qemudDomainGetVcpus(virDomainPtr dom, ...@@ -3717,6 +3727,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
if (priv->vcpupids != NULL && if (priv->vcpupids != NULL &&
qemudGetProcessInfo(&(info[i].cpuTime), qemudGetProcessInfo(&(info[i].cpuTime),
&(info[i].cpu), &(info[i].cpu),
NULL,
vm->pid, vm->pid,
priv->vcpupids[i]) < 0) { priv->vcpupids[i]) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册