Changeset 12024 in vbox
- Timestamp:
- Sep 3, 2008 10:39:29 AM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r11822 r12024 7593 7593 } 7594 7594 7595 static char *toBaseMetricNames(const char *metricList) 7596 { 7597 char *newList = (char*)RTMemAlloc(strlen(metricList) + 1); 7598 int cSlashes = 0; 7599 bool fSkip = false; 7600 char c, *dst = newList, *src = metricList; 7601 while ((c = *src++)) 7602 if (c == ':') 7603 fSkip = true; 7604 else if (c == '/' && ++cSlashes == 2) 7605 fSkip = true; 7606 else if (c == ',') 7607 { 7608 fSkip = false; 7609 cSlashes = 0; 7610 *dst++ = c; 7611 } 7612 else 7613 if (!fSkip) 7614 *dst++ = c; 7615 *dst = 0; 7616 return newList; 7617 } 7618 7595 7619 static int parseFilterParameters(int argc, char *argv[], 7596 7620 ComPtr<IVirtualBox> aVirtualBox, 7597 7621 ComSafeArrayOut(BSTR, outMetrics), 7622 ComSafeArrayOut(BSTR, outBaseMetrics), 7598 7623 ComSafeArrayOut(IUnknown *, outObjects)) 7599 7624 { 7600 7625 HRESULT rc = S_OK; 7601 7626 com::SafeArray<BSTR> retMetrics(1); 7627 com::SafeArray<BSTR> retBaseMetrics(1); 7602 7628 com::SafeIfaceArray <IUnknown> retObjects; 7603 7629 7604 Bstr metricNames ;7630 Bstr metricNames, baseNames; 7605 7631 7606 7632 /* Metric list */ 7607 7633 if (argc > 1) 7634 { 7608 7635 metricNames = argv[1]; 7636 char *tmp = toBaseMetricNames(argv[1]); 7637 if (!tmp) 7638 return VERR_NO_MEMORY; 7639 baseNames = tmp; 7640 RTMemFree(tmp); 7641 } 7609 7642 else 7643 { 7610 7644 metricNames = L"*"; 7645 baseNames = L"*"; 7646 } 7611 7647 metricNames.cloneTo(&retMetrics[0]); 7648 baseNames.cloneTo(&retBaseMetrics[0]); 7612 7649 7613 7650 /* Object name */ … … 7640 7677 7641 7678 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics)); 7679 retBaseMetrics.detachTo(ComSafeArrayOutArg(outBaseMetrics)); 7642 7680 retObjects.detachTo(ComSafeArrayOutArg(outObjects)); 7643 7681 … … 7665 7703 } 7666 7704 7667 static int handleMetrics(int argc, char *argv[], 7668 ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession) 7705 /********************************************************************* 7706 * list * 7707 *********************************************************************/ 7708 static int handleMetricsList(int argc, char *argv[], 7709 ComPtr<IVirtualBox> aVirtualBox, 7710 ComPtr<IPerformanceCollector> performanceCollector) 7669 7711 { 7670 7712 HRESULT rc; 7671 7713 com::SafeArray<BSTR> metrics; 7714 com::SafeArray<BSTR> baseMetrics; 7672 7715 com::SafeIfaceArray<IUnknown> objects; 7673 7716 7674 /* at least one option: sub-command name */ 7675 if (argc < 1) 7676 return errorSyntax(USAGE_METRICS, "Sub-command missing"); 7677 7678 ComPtr<IPerformanceCollector> performanceCollector; 7679 CHECK_ERROR(aVirtualBox, COMGETTER(PerformanceCollector)(performanceCollector.asOutParam())); 7680 7681 if (!strcmp(argv[0], "list")) 7682 { 7683 /********************************************************************* 7684 * list * 7685 *********************************************************************/ 7686 rc = parseFilterParameters(argc - 1, &argv[1], aVirtualBox, 7687 ComSafeArrayAsOutParam(metrics), 7688 ComSafeArrayAsOutParam(objects)); 7689 if (FAILED(rc)) 7690 return 1; 7691 7692 com::SafeIfaceArray<IPerformanceMetric> metricInfo; 7693 7694 CHECK_ERROR(performanceCollector, 7695 GetMetrics(ComSafeArrayAsInParam(metrics), 7696 ComSafeArrayAsInParam(objects), 7697 ComSafeArrayAsOutParam(metricInfo))); 7698 7699 ComPtr<IUnknown> object; 7700 Bstr metricName, unit, description; 7701 ULONG period, count; 7702 LONG minimum, maximum; 7703 RTPrintf( 7717 rc = parseFilterParameters(argc - 1, &argv[1], aVirtualBox, 7718 ComSafeArrayAsOutParam(metrics), 7719 ComSafeArrayAsOutParam(baseMetrics), 7720 ComSafeArrayAsOutParam(objects)); 7721 if (FAILED(rc)) 7722 return 1; 7723 7724 com::SafeIfaceArray<IPerformanceMetric> metricInfo; 7725 7726 CHECK_ERROR(performanceCollector, 7727 GetMetrics(ComSafeArrayAsInParam(metrics), 7728 ComSafeArrayAsInParam(objects), 7729 ComSafeArrayAsOutParam(metricInfo))); 7730 7731 ComPtr<IUnknown> object; 7732 Bstr metricName, unit, description; 7733 ULONG period, count; 7734 LONG minimum, maximum; 7735 RTPrintf( 7704 7736 "Object Metric Unit Minimum Maximum Period Count Description\n" 7705 7737 "---------- -------------------- ---- ---------- ---------- ---------- ---------- -----------\n"); 7706 for (size_t i = 0; i < metricInfo.size(); i++) 7707 { 7708 CHECK_ERROR(metricInfo[i], COMGETTER(Object)(object.asOutParam())); 7709 CHECK_ERROR(metricInfo[i], COMGETTER(MetricName)(metricName.asOutParam())); 7710 CHECK_ERROR(metricInfo[i], COMGETTER(Period)(&period)); 7711 CHECK_ERROR(metricInfo[i], COMGETTER(Count)(&count)); 7712 CHECK_ERROR(metricInfo[i], COMGETTER(MinimumValue)(&minimum)); 7713 CHECK_ERROR(metricInfo[i], COMGETTER(MaximumValue)(&maximum)); 7714 CHECK_ERROR(metricInfo[i], COMGETTER(Unit)(unit.asOutParam())); 7715 CHECK_ERROR(metricInfo[i], COMGETTER(Description)(description.asOutParam())); 7716 RTPrintf("%-10ls %-20ls %-4ls %10d %10d %10u %10u %ls\n", 7717 getObjectName(aVirtualBox, object).raw(), metricName.raw(), unit.raw(), 7718 minimum, maximum, period, count, description.raw()); 7719 } 7720 } 7721 else if (!strcmp(argv[0], "setup")) 7722 { 7723 /********************************************************************* 7724 * setup * 7725 *********************************************************************/ 7726 if (argc < 3) 7727 return errorSyntax(USAGE_METRICS, "Missing parameters for '%s' subcommand", argv[0]); 7728 7729 ULONG period, count; 7730 char *endptr = NULL; 7731 7732 period = strtoul (argv[1], &endptr, 10); 7733 if (!endptr || *endptr) 7734 return errorArgument("Invalid value for 'period' parameter: '%s'", argv[1]); 7735 7736 count = strtoul (argv[2], &endptr, 10); 7737 if (!endptr || *endptr) 7738 return errorArgument("Invalid value for 'count' parameter: '%s'", argv[2]); 7739 7740 rc = parseFilterParameters(argc - 3, &argv[3], aVirtualBox, 7741 ComSafeArrayAsOutParam(metrics), 7742 ComSafeArrayAsOutParam(objects)); 7743 if (FAILED(rc)) 7744 return 1; 7745 7746 CHECK_ERROR(performanceCollector, 7747 SetupMetrics(ComSafeArrayAsInParam(metrics), 7748 ComSafeArrayAsInParam(objects), period, count)); 7749 } 7750 else if (!strcmp(argv[0], "query")) 7751 { 7752 /********************************************************************* 7753 * query * 7754 *********************************************************************/ 7755 rc = parseFilterParameters(argc - 1, &argv[1], aVirtualBox, 7756 ComSafeArrayAsOutParam(metrics), 7757 ComSafeArrayAsOutParam(objects)); 7758 if (FAILED(rc)) 7759 return 1; 7760 7738 for (size_t i = 0; i < metricInfo.size(); i++) 7739 { 7740 CHECK_ERROR(metricInfo[i], COMGETTER(Object)(object.asOutParam())); 7741 CHECK_ERROR(metricInfo[i], COMGETTER(MetricName)(metricName.asOutParam())); 7742 CHECK_ERROR(metricInfo[i], COMGETTER(Period)(&period)); 7743 CHECK_ERROR(metricInfo[i], COMGETTER(Count)(&count)); 7744 CHECK_ERROR(metricInfo[i], COMGETTER(MinimumValue)(&minimum)); 7745 CHECK_ERROR(metricInfo[i], COMGETTER(MaximumValue)(&maximum)); 7746 CHECK_ERROR(metricInfo[i], COMGETTER(Unit)(unit.asOutParam())); 7747 CHECK_ERROR(metricInfo[i], COMGETTER(Description)(description.asOutParam())); 7748 RTPrintf("%-10ls %-20ls %-4ls %10d %10d %10u %10u %ls\n", 7749 getObjectName(aVirtualBox, object).raw(), metricName.raw(), unit.raw(), 7750 minimum, maximum, period, count, description.raw()); 7751 } 7752 7753 return 0; 7754 } 7755 7756 /********************************************************************* 7757 * setup * 7758 *********************************************************************/ 7759 static int handleMetricsSetup(int argc, char *argv[], 7760 ComPtr<IVirtualBox> aVirtualBox, 7761 ComPtr<IPerformanceCollector> performanceCollector) 7762 { 7763 HRESULT rc; 7764 com::SafeArray<BSTR> metrics; 7765 com::SafeArray<BSTR> baseMetrics; 7766 com::SafeIfaceArray<IUnknown> objects; 7767 7768 if (argc < 3) 7769 return errorSyntax(USAGE_METRICS, "Missing parameters for '%s' subcommand", argv[0]); 7770 7771 ULONG period, count; 7772 char *endptr = NULL; 7773 7774 period = strtoul (argv[1], &endptr, 10); 7775 if (!endptr || *endptr) 7776 return errorArgument("Invalid value for 'period' parameter: '%s'", argv[1]); 7777 7778 count = strtoul (argv[2], &endptr, 10); 7779 if (!endptr || *endptr) 7780 return errorArgument("Invalid value for 'count' parameter: '%s'", argv[2]); 7781 7782 rc = parseFilterParameters(argc - 3, &argv[3], aVirtualBox, 7783 ComSafeArrayAsOutParam(metrics), 7784 ComSafeArrayAsOutParam(baseMetrics), 7785 ComSafeArrayAsOutParam(objects)); 7786 if (FAILED(rc)) 7787 return 1; 7788 7789 CHECK_ERROR(performanceCollector, 7790 SetupMetrics(ComSafeArrayAsInParam(metrics), 7791 ComSafeArrayAsInParam(objects), period, count)); 7792 7793 return 0; 7794 } 7795 7796 /********************************************************************* 7797 * query * 7798 *********************************************************************/ 7799 static int handleMetricsQuery(int argc, char *argv[], 7800 ComPtr<IVirtualBox> aVirtualBox, 7801 ComPtr<IPerformanceCollector> performanceCollector) 7802 { 7803 HRESULT rc; 7804 com::SafeArray<BSTR> metrics; 7805 com::SafeArray<BSTR> baseMetrics; 7806 com::SafeIfaceArray<IUnknown> objects; 7807 7808 rc = parseFilterParameters(argc - 1, &argv[1], aVirtualBox, 7809 ComSafeArrayAsOutParam(metrics), 7810 ComSafeArrayAsOutParam(baseMetrics), 7811 ComSafeArrayAsOutParam(objects)); 7812 if (FAILED(rc)) 7813 return 1; 7814 7815 com::SafeArray<BSTR> retNames; 7816 com::SafeIfaceArray<IUnknown> retObjects; 7817 com::SafeArray<ULONG> retIndices; 7818 com::SafeArray<ULONG> retLengths; 7819 com::SafeArray<LONG> retData; 7820 CHECK_ERROR (performanceCollector, QueryMetricsData(ComSafeArrayAsInParam(metrics), 7821 ComSafeArrayAsInParam(objects), 7822 ComSafeArrayAsOutParam(retNames), 7823 ComSafeArrayAsOutParam(retObjects), 7824 ComSafeArrayAsOutParam(retIndices), 7825 ComSafeArrayAsOutParam(retLengths), 7826 ComSafeArrayAsOutParam(retData)) ); 7827 7828 RTPrintf("Object Metric Values\n" 7829 "---------- -------------------- --------------------------------------------\n"); 7830 for (unsigned i = 0; i < retNames.size(); i++) 7831 { 7832 // Get info for the metric 7833 com::SafeArray<BSTR> nameOfMetric(1); 7834 Bstr tmpName(retNames[i]); 7835 tmpName.detachTo (&nameOfMetric[0]); 7836 com::SafeIfaceArray<IUnknown> anObject(1); 7837 ComPtr<IUnknown> tmpObject(retObjects[i]); 7838 tmpObject.queryInterfaceTo(&anObject[0]); 7839 com::SafeIfaceArray <IPerformanceMetric> metricInfo; 7840 CHECK_RC_BREAK (performanceCollector->GetMetrics( ComSafeArrayAsInParam(nameOfMetric), 7841 ComSafeArrayAsInParam(anObject), 7842 ComSafeArrayAsOutParam(metricInfo) )); 7843 BSTR metricUnitBSTR; 7844 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(Unit) (&metricUnitBSTR)); 7845 Bstr metricUnit(metricUnitBSTR); 7846 Bstr metricName(retNames[i]); 7847 LONG minVal, maxVal; 7848 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MinimumValue) (&minVal)); 7849 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MaximumValue) (&maxVal)); 7850 RTPrintf("%-10ls %-20ls ", getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw()); 7851 const char *separator = ""; 7852 for (unsigned j = 0; j < retLengths[i]; j++) 7853 { 7854 if (strcmp((const char *)metricUnit.raw(), "%")) 7855 RTPrintf("%s%d %ls", separator, retData[retIndices[i] + j], metricUnit.raw()); 7856 else 7857 RTPrintf("%s%d.%02d%%", separator, retData[retIndices[i] + j] / 1000, retData[retIndices[i] + j] % 100); 7858 separator = ", "; 7859 } 7860 RTPrintf("\n"); 7861 } 7862 7863 return 0; 7864 } 7865 7866 static void getTimestamp(char *pts, size_t tsSize) 7867 { 7868 *pts = 0; 7869 AssertReturnVoid(tsSize >= 13); /* 3+3+3+3+1 */ 7870 RTTIMESPEC TimeSpec; 7871 RTTIME Time; 7872 RTTimeExplode(&Time, RTTimeNow(&TimeSpec)); 7873 pts += RTStrFormatNumber(pts, Time.u8Hour, 10, 2, 0, RTSTR_F_ZEROPAD); 7874 *pts++ = ':'; 7875 pts += RTStrFormatNumber(pts, Time.u8Minute, 10, 2, 0, RTSTR_F_ZEROPAD); 7876 *pts++ = ':'; 7877 pts += RTStrFormatNumber(pts, Time.u8Second, 10, 2, 0, RTSTR_F_ZEROPAD); 7878 *pts++ = '.'; 7879 pts += RTStrFormatNumber(pts, Time.u32Nanosecond / 1000000, 10, 3, 0, RTSTR_F_ZEROPAD); 7880 *pts = 0; 7881 } 7882 7883 /********************************************************************* 7884 * collect * 7885 *********************************************************************/ 7886 static int handleMetricsCollect(int argc, char *argv[], 7887 ComPtr<IVirtualBox> aVirtualBox, 7888 ComPtr<IPerformanceCollector> performanceCollector) 7889 { 7890 HRESULT rc; 7891 com::SafeArray<BSTR> metrics; 7892 com::SafeArray<BSTR> baseMetrics; 7893 com::SafeIfaceArray<IUnknown> objects; 7894 ULONG period = 0, samples = 0; 7895 bool isDetached = false, listMatches = false; 7896 int i; 7897 for (i = 1; i < argc; i++) 7898 { 7899 if (strcmp(argv[i], "-period") == 0) 7900 { 7901 if (argc <= i + 1) 7902 return errorArgument("Missing argument to '%s'", argv[i]); 7903 char *endptr = NULL; 7904 period = strtoul (argv[++i], &endptr, 10); 7905 if (!endptr || *endptr || !period) 7906 return errorArgument("Invalid value for 'period' parameter: '%s'", argv[i]); 7907 } 7908 else if (strcmp(argv[i], "-samples") == 0) 7909 { 7910 if (argc <= i + 1) 7911 return errorArgument("Missing argument to '%s'", argv[i]); 7912 char *endptr = NULL; 7913 samples = strtoul (argv[++i], &endptr, 10); 7914 if (!endptr || *endptr) 7915 return errorArgument("Invalid value for 'period' parameter: '%s'", argv[i]); 7916 } 7917 else if (strcmp(argv[i], "-list") == 0) 7918 listMatches = true; 7919 else if (strcmp(argv[i], "-detach") == 0) 7920 isDetached = true; 7921 else 7922 break; /* The rest of params should define the filter */ 7923 } 7924 7925 if (period == 0) 7926 return errorSyntax(USAGE_METRICS, "Parameter -period is required"); 7927 7928 rc = parseFilterParameters(argc - i, &argv[i], aVirtualBox, 7929 ComSafeArrayAsOutParam(metrics), 7930 ComSafeArrayAsOutParam(baseMetrics), 7931 ComSafeArrayAsOutParam(objects)); 7932 if (FAILED(rc)) 7933 return 1; 7934 7935 com::SafeIfaceArray<IPerformanceMetric> metricInfo; 7936 7937 CHECK_ERROR(performanceCollector, 7938 GetMetrics(ComSafeArrayAsInParam(metrics), 7939 ComSafeArrayAsInParam(objects), 7940 ComSafeArrayAsOutParam(metricInfo))); 7941 7942 if (metricInfo.size()) 7943 { 7944 if (listMatches) 7945 { 7946 ComPtr<IUnknown> object; 7947 Bstr metricName; 7948 RTPrintf("The following metrics will be collected:\n\n" 7949 "Object Metric\n" 7950 "---------- --------------------\n"); 7951 for (size_t i = 0; i < metricInfo.size(); i++) 7952 { 7953 CHECK_ERROR(metricInfo[i], COMGETTER(Object)(object.asOutParam())); 7954 CHECK_ERROR(metricInfo[i], COMGETTER(MetricName)(metricName.asOutParam())); 7955 RTPrintf("%-10ls %-20ls\n", 7956 getObjectName(aVirtualBox, object).raw(), metricName.raw()); 7957 } 7958 RTPrintf("\n"); 7959 } 7960 } 7961 else 7962 { 7963 RTPrintf("No metrics match the specified filter!\n"); 7964 return 1; 7965 } 7966 7967 CHECK_ERROR(performanceCollector, 7968 SetupMetrics(ComSafeArrayAsInParam(baseMetrics), 7969 ComSafeArrayAsInParam(objects), period, isDetached?samples:1)); 7970 7971 if (isDetached) 7972 { 7973 RTPrintf("Warning! The background process holding collected metrics will shutdown\n" 7974 "in few seconds, discarding all collected data and parameters.\n"); 7975 return 0; 7976 } 7977 7978 RTPrintf("Time stamp Object Metric Value\n"); 7979 7980 for (unsigned n = 0; n < samples || samples == 0; n++) 7981 { 7982 RTPrintf("------------ ---------- -------------------- --------------------\n"); 7983 RTThreadSleep(period * 1000); // Sleep for 'period' seconds 7984 char ts[15]; 7985 7986 getTimestamp(ts, sizeof(ts)); 7761 7987 com::SafeArray<BSTR> retNames; 7762 7988 com::SafeIfaceArray<IUnknown> retObjects; … … 7771 7997 ComSafeArrayAsOutParam(retLengths), 7772 7998 ComSafeArrayAsOutParam(retData)) ); 7773 7774 RTPrintf("Object Metric Values\n"7775 "---------- -------------------- --------------------------------------------\n");7776 7999 for (unsigned i = 0; i < retNames.size(); i++) 7777 8000 { 8001 7778 8002 // Get info for the metric 7779 8003 com::SafeArray<BSTR> nameOfMetric(1); … … 7794 8018 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MinimumValue) (&minVal)); 7795 8019 CHECK_RC_BREAK (metricInfo[0]->COMGETTER(MaximumValue) (&maxVal)); 7796 RTPrintf("%-1 0ls %-20ls ", getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw());8020 RTPrintf("%-12s %-10ls %-20ls ", ts, getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw()); 7797 8021 const char *separator = ""; 7798 8022 for (unsigned j = 0; j < retLengths[i]; j++) … … 7807 8031 } 7808 8032 } 8033 8034 return 0; 8035 } 8036 8037 static int handleMetrics(int argc, char *argv[], 8038 ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession) 8039 { 8040 int rc; 8041 8042 /* at least one option: sub-command name */ 8043 if (argc < 1) 8044 return errorSyntax(USAGE_METRICS, "Sub-command missing"); 8045 8046 ComPtr<IPerformanceCollector> performanceCollector; 8047 CHECK_ERROR(aVirtualBox, COMGETTER(PerformanceCollector)(performanceCollector.asOutParam())); 8048 8049 if (!strcmp(argv[0], "list")) 8050 rc = handleMetricsList(argc, argv, aVirtualBox, performanceCollector); 8051 else if (!strcmp(argv[0], "setup")) 8052 rc = handleMetricsSetup(argc, argv, aVirtualBox, performanceCollector); 8053 else if (!strcmp(argv[0], "query")) 8054 rc = handleMetricsQuery(argc, argv, aVirtualBox, performanceCollector); 8055 else if (!strcmp(argv[0], "collect")) 8056 rc = handleMetricsCollect(argc, argv, aVirtualBox, performanceCollector); 7809 8057 else 7810 {7811 8058 return errorSyntax(USAGE_METRICS, "Invalid subcommand '%s'", argv[0]); 7812 } 7813 7814 return SUCCEEDED(rc) ? 0 : 1; 8059 8060 return rc; 7815 8061 } 7816 8062 #endif /* !VBOX_ONLY_DOCS */ -
trunk/src/VBox/Main/Performance.cpp
r11810 r12024 118 118 } 119 119 120 AssertReturn(cCpus, VERR_NOT_IMPLEMENTED); 121 *mhz = (ULONG)(u64TotalMHz / cCpus); 120 // @todo Replace 'if' with 'AssertReturn' when done debugging 121 //AssertReturn(cCpus, VERR_NOT_IMPLEMENTED); 122 if (cCpus == 0) return VERR_NOT_IMPLEMENTED; 123 *mhz = (ULONG)(u64TotalMHz / cCpus); 122 124 123 125 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.