summaryrefslogtreecommitdiff
path: root/qa/qt/qmc_indom/qmc_indom.cpp
blob: 6b829135344b3dbc0996efe35949db8aaddddd62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Test QmcIndom class
//

#include <QTextStream>
#include <qmc_context.h>
#include <qmc_source.h>
#include <qmc_desc.h>
#include <qmc_indom.h>

QTextStream cerr(stderr);
QTextStream cout(stdout);

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*/
    }

    fprintf(stderr, "*** Lookup an indom ***\n");
    QString source = QString("archives/oview-short");
    QmcSource *src = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false);

    if (src->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"%s\": %s\n",
		pmProgname, (const char *)source.toAscii(),
		pmErrStr(src->status()));
	pmflush();
	return 1;
    }

    pmID hinv_map_cpu = pmid_build(1, 26, 9);
    QmcDesc hinv_map_cpu_pmc(hinv_map_cpu);

    if (hinv_map_cpu_pmc.status() < 0) {
	pmprintf("\n%s: Error: hinv.map.cpu: %s\n",
		 pmProgname, pmErrStr(hinv_map_cpu_pmc.status()));
	pmflush();
	return 1;
    }

    QmcIndom indom(PM_CONTEXT_ARCHIVE, hinv_map_cpu_pmc);

    if (indom.status() < 0) {
	pmprintf("%s: Error: hinv.map.cpu: %s\n",
		 pmProgname, pmErrStr(indom.status()));
	pmflush();
	return 1;
    }

    indom.dump(cout);

    if (indom.diffProfile()) {
	pmprintf("%s: Error: Profile requires updating but there is nothing in it\n",
		 pmProgname);
	sts = 1;
    }

    fprintf(stderr, "\n*** Reference one instance ***\n");
    indom.lookup("cpu:1.3.a");

    if (!indom.diffProfile()) {
	pmprintf("%s: Error: Profile should require updating but flag not set\n",
		 pmProgname);
	sts = 1;
    }

    indom.dump(cout);
    indom.genProfile();

    __pmProfile* profile = __pmHandleToPtr(pmWhichContext())->c_instprof;
    __pmDumpProfile(stderr, PM_INDOM_NULL, profile);

    if (indom.diffProfile()) {
	pmprintf("%s: Error: Profile just generated but flag still set\n",
		 pmProgname);
	sts = 1;
    }

    fprintf(stderr, "\n*** Reference all instances ***\n");
    indom.refAll();

    if (!indom.diffProfile()) {
	pmprintf("%s: Error: All instances referenced but profile flag unset\n",
		 pmProgname);
	sts = 1;
    }

    indom.dump(cout);
    indom.genProfile();
    
    profile = __pmHandleToPtr(pmWhichContext())->c_instprof;
    __pmDumpProfile(stderr, PM_INDOM_NULL, profile);

    if (indom.diffProfile()) {
	pmprintf("%s: Error: Profile just generated but flag still set\n",
		 pmProgname);
	sts = 1;
    }

    pmflush();
    return sts;
}