Пример #1
0
static int
StatGetMemoryLimit(void)
{
   int exitStatus = EXIT_SUCCESS;
   uint32 memLimit;
   VMGuestLibHandle glHandle;
   VMGuestLibError glError;

   exitStatus = OpenHandle(&glHandle, &glError);
   if (exitStatus) {
      return exitStatus;
   }
   glError = VMGuestLib_GetMemLimitMB(glHandle, &memLimit);
   if (glError != VMGUESTLIB_ERROR_SUCCESS) {
      ToolsCmd_PrintErr(SU_(stat.maxmem.failed,
                            "Failed to get memory limit: %s\n"),
                        VMGuestLib_GetErrorText(glError));
      exitStatus = EX_TEMPFAIL;
   } else {
      g_print(SU_(stat.memoryLimit.info, "%u MB\n"), memLimit);
   }
   VMGuestLib_CloseHandle(glHandle);
   return exitStatus;
}
Пример #2
0
int sample(struct vg_data *pvg, unsigned int flag)
{
	int rc;
	VMGuestLibError ret;
	
	rc = gettimeofday(&pvg->ts, NULL);
	if (rc < 0) {
		printf("gettimeofday() failed.");
		return 1;
	}

	ret = VMGuestLib_UpdateInfo(pvg->handle);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_Updateinfo: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetSessionId(pvg->handle, &pvg->id);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetSessionId: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetHostProcessorSpeed(pvg->handle, &pvg->hostmhz);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetHostProcessorSpeed: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetCpuReservationMHz(pvg->handle, &pvg->reservemhz);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetCpuReservationMHz: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetCpuLimitMHz(pvg->handle, &pvg->limitmhz);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetCpuLimitMHz: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetCpuShares(pvg->handle, &pvg->cpushares);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetCpuShares: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetElapsedMs(pvg->handle, &pvg->elapsedms);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetElapsedMs: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetCpuUsedMs(pvg->handle, &pvg->usedms);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetCpuUsedMs: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetCpuStolenMs(pvg->handle, &pvg->stolenms);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetCpuStolenMs: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetMemReservationMB(pvg->handle, &pvg->reservemb);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemReservationMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetMemLimitMB(pvg->handle, &pvg->limitmb);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemLimitMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetMemShares(pvg->handle, &pvg->memshares);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemShares: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}

	ret = VMGuestLib_GetMemMappedMB(pvg->handle, &pvg->mappedsize);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemMappedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetMemActiveMB(pvg->handle, &pvg->active);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemActiveMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	ret = VMGuestLib_GetMemOverheadMB(pvg->handle, &pvg->overhead);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemOverheadMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	
	ret = VMGuestLib_GetMemBalloonedMB(pvg->handle, &pvg->ballooned);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemBalloonedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	ret = VMGuestLib_GetMemSwappedMB(pvg->handle, &pvg->swapped);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemSwappedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	ret = VMGuestLib_GetMemSharedMB(pvg->handle, &pvg->sharedmb);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemSharedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	ret = VMGuestLib_GetMemSharedSavedMB(pvg->handle,
					     &pvg->sharedsavedmb);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemSharedSavedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
	ret = VMGuestLib_GetMemUsedMB(pvg->handle, &pvg->usedmb);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetMemUsedMB: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
#ifdef RESPOOLPATH
	pvg->bufsize = BUFSIZE;
	ret = VMGuestLib_GetResourcePoolPath(pvg->handle,
					     &pvg->bufsize,
					     pvg->pathbuf);
	if (ret != VMGUESTLIB_ERROR_SUCCESS) {
		if (IS_VERBOSE(flag)) {
			printf("VMGuestLib_GetResourcePoolPath: %d (%s)\n",
			       ret, VMGuestLib_GetErrorText(ret));
		}
		return 1;
	}
#endif
	return 0;
}