VBoxManageMetrics.cpp revision 07bf154df97af02974bb89d4f1ad36afa2b45443
/* $Id$ */
/** @file
* VBoxManage - The 'metrics' command.
*/
/*
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef VBOX_ONLY_DOCS
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
using namespace com;
// funcs
///////////////////////////////////////////////////////////////////////////////
static char *toBaseMetricNames(const char *metricList)
{
int cSlashes = 0;
bool fSkip = false;
const char *src = metricList;
while ((c = *src++))
if (c == ':')
fSkip = true;
fSkip = true;
else if (c == ',')
{
fSkip = false;
cSlashes = 0;
*dst++ = c;
}
else
if (!fSkip)
*dst++ = c;
*dst = 0;
return newList;
}
{
/* Metric list */
if (argc > 1)
{
if (!tmp)
return VERR_NO_MEMORY;
}
else
{
metricNames = L"*";
baseNames = L"*";
}
/* Object name */
{
{
}
else
{
{
}
else
{
return rc;
}
}
}
return rc;
}
{
return Bstr("host");
{
return name;
}
return Bstr("unknown");
}
{
{
RTPrintf("The following metrics were modified:\n\n"
"Object Metric\n"
"---------- --------------------\n");
{
RTPrintf("%-10ls %-20ls\n",
}
RTPrintf("\n");
}
else
{
RTPrintf("No metrics match the specified filter!\n");
}
}
/**
* list *
*/
{
return 1;
"Object Metric Unit Minimum Maximum Period Count Description\n"
"---------- -------------------- ---- ---------- ---------- ---------- ---------- -----------\n");
{
RTPrintf("%-10ls %-20ls %-4ls %10d %10d %10u %10u %ls\n",
}
return 0;
}
/**
* Metics setup
*/
{
bool listMatches = false;
int i;
for (i = 1; i < argc; i++)
{
{
if (argc <= i + 1)
|| !period)
}
{
if (argc <= i + 1)
|| !samples)
}
listMatches = true;
else
break; /* The rest of params should define the filter */
}
return 1;
if (listMatches)
return 0;
}
/**
* metrics query
*/
{
return 1;
RTPrintf("Object Metric Values\n"
"---------- -------------------- --------------------------------------------\n");
{
const char *separator = "";
for (unsigned j = 0; j < retLengths[i]; j++)
{
if (retScales[i] == 1)
else
separator = ", ";
}
RTPrintf("\n");
}
return 0;
}
{
*pts = 0;
*pts++ = ':';
*pts++ = ':';
*pts++ = '.';
*pts = 0;
}
/** Used by the handleMetricsCollect loop. */
static bool volatile g_fKeepGoing = true;
#ifdef RT_OS_WINDOWS
/**
* Handler routine for catching Ctrl-C, Ctrl-Break and closing of
* the console.
*
* @returns true if handled, false if not handled.
* @param dwCtrlType The type of control signal.
*
* @remarks This is called on a new thread.
*/
{
switch (dwCtrlType)
{
/* Ctrl-C or Ctrl-Break or Close */
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
/* Let's shut down gracefully. */
ASMAtomicWriteBool(&g_fKeepGoing, false);
return TRUE;
}
/* Don't care about the rest -- let it die a horrible death. */
return FALSE;
}
#endif /* RT_OS_WINDOWS */
/**
* collect
*/
{
bool isDetached = false, listMatches = false;
int i;
for (i = 1; i < argc; i++)
{
{
if (argc <= i + 1)
|| !period)
}
{
if (argc <= i + 1)
|| !samples)
}
listMatches = true;
isDetached = true;
else
break; /* The rest of params should define the filter */
}
return 1;
if (listMatches)
if (!affectedMetrics.size())
return 1;
if (isDetached)
{
RTPrintf("Warning! The background process holding collected metrics will shutdown\n"
"in few seconds, discarding all collected data and parameters.\n");
return 0;
}
#ifdef RT_OS_WINDOWS
SetConsoleCtrlHandler(ctrlHandler, true);
#endif /* RT_OS_WINDOWS */
RTPrintf("Time stamp Object Metric Value\n");
while (g_fKeepGoing)
{
RTPrintf("------------ ---------- -------------------- --------------------\n");
char ts[15];
{
RTPrintf("%-12s %-10ls %-20ls ", ts, getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw());
const char *separator = "";
for (unsigned j = 0; j < retLengths[i]; j++)
{
if (retScales[i] == 1)
else
separator = ", ";
}
RTPrintf("\n");
}
}
#ifdef RT_OS_WINDOWS
SetConsoleCtrlHandler(ctrlHandler, false);
#endif /* RT_OS_WINDOWS */
return 0;
}
int handleMetrics(HandlerArg *a)
{
int rc;
/* at least one option: subcommand name */
if (a->argc < 1)
else
return rc;
}
#endif /* VBOX_ONLY_DOCS */