summaryrefslogtreecommitdiff
path: root/qa/qt/qmc_metric
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qt/qmc_metric')
-rw-r--r--qa/qt/qmc_metric/GNUmakefile27
-rw-r--r--qa/qt/qmc_metric/GNUmakefile.install18
-rw-r--r--qa/qt/qmc_metric/qmc_metric.cpp280
-rw-r--r--qa/qt/qmc_metric/qmc_metric.pro13
4 files changed, 338 insertions, 0 deletions
diff --git a/qa/qt/qmc_metric/GNUmakefile b/qa/qt/qmc_metric/GNUmakefile
new file mode 100644
index 0000000..3be53f3
--- /dev/null
+++ b/qa/qt/qmc_metric/GNUmakefile
@@ -0,0 +1,27 @@
+TOPDIR = ../../..
+include $(TOPDIR)/src/include/builddefs
+
+COMMAND = qmc_metric
+PROJECT = $(COMMAND).pro
+SOURCES = $(COMMAND).cpp
+TESTDIR = $(PCP_VAR_DIR)/testsuite/qt/$(COMMAND)
+
+LSRCFILES = $(PROJECT) $(SOURCES)
+LDIRDIRT = build $(COMMAND).xcodeproj
+LDIRT = $(COMMAND) *.o Makefile
+
+default default_pcp:
+ifeq "$(ENABLE_QT)" "true"
+ $(QTMAKE)
+ $(LNMAKE)
+endif
+
+install install_pcp: default
+ $(INSTALL) -m 755 -d $(TESTDIR)
+ $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile
+ $(INSTALL) -m 644 $(PROJECT) $(SOURCES) $(TESTDIR)
+ifeq "$(ENABLE_QT)" "true"
+ $(INSTALL) -m 755 $(BINARY) $(TESTDIR)/$(COMMAND)
+endif
+
+include $(BUILDRULES)
diff --git a/qa/qt/qmc_metric/GNUmakefile.install b/qa/qt/qmc_metric/GNUmakefile.install
new file mode 100644
index 0000000..daf4be2
--- /dev/null
+++ b/qa/qt/qmc_metric/GNUmakefile.install
@@ -0,0 +1,18 @@
+ifdef PCP_CONF
+include $(PCP_CONF)
+else
+include $(PCP_DIR)/etc/pcp.conf
+endif
+PATH = $(shell . $(PCP_DIR)/etc/pcp.env; echo $$PATH)
+include $(PCP_INC_DIR)/builddefs
+
+COMMAND = qmc_metric
+PROJECT = $(COMMAND).pro
+
+default setup install:
+ifeq "$(ENABLE_QT)" "true"
+ $(QTMAKE)
+ $(LNMAKE)
+endif
+
+include $(BUILDRULES)
diff --git a/qa/qt/qmc_metric/qmc_metric.cpp b/qa/qt/qmc_metric/qmc_metric.cpp
new file mode 100644
index 0000000..3df5487
--- /dev/null
+++ b/qa/qt/qmc_metric/qmc_metric.cpp
@@ -0,0 +1,280 @@
+//
+// Test QmcMetric class
+//
+
+#include <errno.h>
+#include <QTextStream>
+#include <qmc_context.h>
+#include <qmc_group.h>
+#include <qmc_metric.h>
+#include <qmc_indom.h>
+
+QTextStream cerr(stderr);
+QTextStream cout(stdout);
+
+void
+changeConf(const char* str)
+{
+ char name[MAXPATHLEN];
+ FILE *fp;
+
+ sprintf(name, "%s/pmdas/simple/simple.conf", pmGetConfig("PCP_VAR_DIR"));
+ fp = fopen(name, "w");
+ if (fp == NULL) {
+ cerr << pmProgname << ": /var/pcp/pmdas/simple/simple.conf: "
+ << strerror(errno) << endl;
+ exit(1);
+ /*NOTREACHED*/
+ }
+
+ fprintf(fp, "%s\n", str);
+ fclose(fp);
+}
+
+int
+main(int argc, char* argv[])
+{
+ int sts = 0;
+ int c;
+
+ pmProgname = basename(argv[0]);
+
+ while ((c = getopt(argc, argv, "D:?")) != EOF) {
+ switch (c) {
+ case 'D':
+ sts = __pmParseDebug(optarg);
+ if (sts < 0) {
+ pmprintf("%s: unrecognized debug flag specification (%s)\n",
+ pmProgname, optarg);
+ sts = 1;
+ }
+ else {
+ pmDebug |= sts;
+ sts = 0;
+ }
+ break;
+ case '?':
+ default:
+ sts = 1;
+ break;
+ }
+ }
+
+ if (sts) {
+ pmprintf("Usage: %s\n", pmProgname);
+ pmflush();
+ exit(1);
+ /*NOTREACHED*/
+ }
+
+ cerr << "*** Create a single fetch group ***" << endl;
+ QmcGroup group1;
+ pmflush();
+
+ cerr << endl << "*** Simple metric ***" << endl;
+ QmcMetric* hinv_ncpu = group1.addMetric("hinv.ncpu");
+ pmflush();
+
+ if (hinv_ncpu->status() < 0)
+ sts = 1;
+ else
+ hinv_ncpu->dump(cerr);
+
+ cerr << endl << "*** Metric with an Indom ***" << endl;
+ QmcMetric* percpu_user = group1.addMetric("sample.bin");
+ pmflush();
+
+ if (percpu_user->status() < 0)
+ sts = 1;
+ else
+ percpu_user->dump(cerr);
+
+ cerr << endl << "*** proc style specific instance ***" << endl;
+ QmcMetric* load_avg = group1.addMetric("kernel.all.load[1,5]");
+ pmflush();
+
+ if (load_avg->status() < 0)
+ sts = 1;
+ else
+ load_avg->dump(cerr);
+
+ cerr << endl << "*** String metric ***" << endl;
+ QmcMetric* sample_hullo = group1.addMetric("sample.string.hullo");
+
+ if (sample_hullo->status() < 0)
+ sts = 1;
+ else
+ sample_hullo->dump(cerr);
+
+ cerr << endl << "*** Rate converted metric ***" << endl;
+ QmcMetric* sample_seconds = group1.addMetric("sample.seconds");
+
+ if (sample_seconds->status() < 0)
+ sts = 1;
+ else
+ sample_seconds->dump(cerr);
+
+ cerr << endl << "*** Bogus metric ***" << endl;
+ QmcMetric* bogus_metric = group1.addMetric("bogus.metric");
+ pmflush();
+
+ if (bogus_metric->status() >= 0) {
+ pmprintf("%s: Error: bogus.metric was not invalid!\n",
+ pmProgname);
+ pmflush();
+ sts = 1;
+ }
+
+ cerr << endl << "*** Bogus instance ***" << endl;
+ QmcMetric* bogus_inst = group1.addMetric("kernel.all.load[2]");
+ pmflush();
+
+ if (bogus_inst->status() >= 0) {
+ pmprintf("%s: Error: kernel.all.load[2] was not invalid!\n",
+ pmProgname);
+ pmflush();
+ sts = 1;
+ }
+
+ pmflush();
+
+ sleep(1);
+
+ cerr << endl << "*** Group 1 Fetch 1 ***" << endl;
+ group1.fetch();
+ hinv_ncpu->dump(cerr);
+ percpu_user->dump(cerr);
+ load_avg->dump(cerr);
+ sample_hullo->dump(cerr);
+ sample_seconds->dump(cerr);
+
+ sleep(1);
+
+ cerr << endl << "*** Group 1 Fetch 2 ***" << endl;
+ group1.fetch();
+ hinv_ncpu->dump(cerr);
+ percpu_user->dump(cerr);
+ load_avg->dump(cerr);
+ sample_hullo->dump(cerr);
+ sample_seconds->dump(cerr);
+
+ cerr << endl << "*** Remove an instance ***" << endl;
+ load_avg->removeInst(0);
+ load_avg->dump(cerr);
+
+ sleep(1);
+
+ cerr << endl << "*** Group 1 Fetch 3 ***" << endl;
+ group1.fetch();
+ hinv_ncpu->dump(cerr);
+ percpu_user->dump(cerr);
+ load_avg->dump(cerr);
+ sample_hullo->dump(cerr);
+ sample_seconds->dump(cerr);
+
+ cerr << endl << "*** Add an instance ***" << endl;
+ load_avg->addInst("15");
+ load_avg->dump(cerr);
+
+ sleep(1);
+
+ cerr << endl << "*** Group 1 Fetch 4 ***" << endl;
+ group1.fetch();
+ hinv_ncpu->dump(cerr);
+ percpu_user->dump(cerr);
+ load_avg->dump(cerr);
+ sample_hullo->dump(cerr);
+ sample_seconds->dump(cerr);
+
+ cerr << endl << "*** Creating a new group ***" << endl;
+ QmcGroup group2;
+
+ cerr << endl << "*** Adding a metric with a dynamic indom ***" << endl;
+ QmcMetric* simple_now = group2.addMetric("simple.now");
+ pmflush();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Group 2 Fetch 1 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Change the indom ***" << endl;
+ changeConf("sec,min,hour");
+
+ cerr << endl << "*** Group 2 Fetch 2 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Updating indom ***" << endl;
+ if (simple_now->indom()->changed())
+ simple_now->updateIndom();
+ else
+ cerr << "Nothing to update!" << endl;
+
+ simple_now->dump(cerr);
+ simple_now->indom()->dump(cerr);
+
+ cerr << endl << "*** Group 2 Fetch 3 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Remove instance from PMDA ***" << endl;
+ changeConf("sec,hour");
+
+ cerr << endl << "*** Group 2 Fetch 4 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Remove an instance ***" << endl;
+ simple_now->removeInst(1);
+ simple_now->dump(cerr);
+ simple_now->indom()->dump(cerr);
+
+ cerr << endl << "*** Updating indom ***" << endl;
+ if (simple_now->indom()->changed())
+ simple_now->updateIndom();
+ else
+ cerr << "Nothing to update!" << endl;
+
+ simple_now->dump(cerr);
+ simple_now->indom()->dump(cerr);
+
+ cerr << endl << "*** Group 2 Fetch 5 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+
+ cerr << endl << "*** Add another metric with the same indom ***" << endl;
+ QmcMetric* simple_now2 = group2.addMetric("simple.now");
+ simple_now2->dump(cerr);
+ simple_now2->indom()->dump(cerr);
+
+ cerr << endl << "*** Group 2 Fetch 6 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+ simple_now2->dump(cerr);
+
+ cerr << endl << "*** Add an instance to the PMDA ***" << endl;
+ changeConf("sec,min,hour");
+
+ cerr << endl << "*** Group 2 Fetch 7 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+ simple_now2->dump(cerr);
+
+ cerr << endl << "*** Updating indom ***" << endl;
+ if (simple_now2->indom()->changed())
+ simple_now2->updateIndom();
+ else
+ cerr << "Nothing to update!" << endl;
+
+ simple_now2->dump(cerr);
+ simple_now2->indom()->dump(cerr);
+
+ cerr << endl << "*** Group 2 Fetch 8 ***" << endl;
+ group2.fetch();
+ simple_now->dump(cerr);
+ simple_now2->dump(cerr);
+
+ cerr << endl << "*** Exiting ***" << endl;
+ return sts;
+}
diff --git a/qa/qt/qmc_metric/qmc_metric.pro b/qa/qt/qmc_metric/qmc_metric.pro
new file mode 100644
index 0000000..49262c9
--- /dev/null
+++ b/qa/qt/qmc_metric/qmc_metric.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+LANGUAGE = C++
+SOURCES = qmc_metric.cpp
+CONFIG += qt warn_on
+release:DESTDIR = build/debug
+debug:DESTDIR = build/release
+INCLUDEPATH += ../../../src/include
+INCLUDEPATH += ../../../src/libpcp_qmc/src
+LIBS += -L../../../src/libpcp/src
+LIBS += -L../../../src/libpcp_qmc/src
+LIBS += -L../../../src/libpcp_qmc/src/$$DESTDIR
+LIBS += -lpcp_qmc -lpcp
+QT -= gui