Skip to content

Commit e66df88

Browse files
authored
Merge pull request #142 from perftool-incubator/get-primary-periods.js
new util
2 parents 68f93d8 + 87c05f0 commit e66df88

2 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=javascript
2+
var cdm = require('./cdm');
3+
var yaml = require('js-yaml');
4+
var program = require('commander');
5+
var instances = [];
6+
var summary = {};
7+
8+
function list(val) {
9+
return val.split(',');
10+
}
11+
12+
function save_host(host) {
13+
var host_info = { host: host, header: { 'Content-Type': 'application/json' } };
14+
instances.push(host_info);
15+
}
16+
17+
function save_userpass(userpass) {
18+
if (instances.length == 0) {
19+
console.log('You must specify a --host before a --userpass');
20+
process.exit(1);
21+
}
22+
instances[instances.length - 1]['header'] = {
23+
'Content-Type': 'application/json',
24+
Authorization: 'Basic ' + btoa(userpass)
25+
};
26+
}
27+
28+
function save_ver(ver) {
29+
if (instances.length == 0) {
30+
console.log('You must specify a --host before a --ver');
31+
process.exit(1);
32+
}
33+
if (/^v[7|8|9]dev$/.exec(ver)) {
34+
instances[instances.length - 1]['ver'] = ver;
35+
} else {
36+
console.log('The version must be v7dev, v8dev, or v9dev, not: ' + ver);
37+
process.exit(1);
38+
}
39+
}
40+
41+
program
42+
.version('0.1.0')
43+
.option('--run <run-ID>')
44+
.option('--host <host[:port]>', 'The host and optional port of the OpenSearch instance', save_host)
45+
.option('--userpass <user:pass>', 'The user and password for the most recent --host', save_userpass)
46+
.option('--ver <v7dev|v8dev|v9dev>', 'The Common Data Model version to use for the most recent --host', save_ver)
47+
.option('--output-dir <path>, if not used, output is to console only')
48+
.option('--output-format <fmt>, fmta[,fmtb]', 'one or more output formats: txt, json, yaml', list, [])
49+
.parse(process.argv);
50+
51+
var termKeys = [];
52+
var values = [];
53+
54+
if (program.run) {
55+
termKeys.push('run.run-uuid');
56+
values.push([program.run]);
57+
}
58+
59+
async function main() {
60+
// If the user does not specify any hosts, assume localhost:9200 is used
61+
if (instances.length == 0) {
62+
save_host('localhost:9200');
63+
}
64+
65+
getInstancesInfo(instances);
66+
cdm.debuglog(JSON.stringify(instances, null, 2));
67+
68+
// Since this query is looking for run ids (and may not inlcude run-uuid as a search term), we
69+
// need to check all instances.
70+
var allInstanceRunIds = [];
71+
for (const instance of instances) {
72+
if (invalidInstance(instance)) {
73+
continue;
74+
}
75+
cdm.debuglog('main(): calling cdm.mSearch()');
76+
var instanceRunIds = await cdm.mSearch(instance, 'run', '@*', termKeys, values, 'run.run-uuid', null, 1000);
77+
cdm.debuglog('main(): returned from cdm.mSearch()');
78+
cdm.debuglog('instanceRunIds:\n' + JSON.stringify(instanceRunIds, null, 2));
79+
if (typeof instanceRunIds[0] != 'undefined') {
80+
allInstanceRunIds.push(instanceRunIds[0]);
81+
}
82+
}
83+
cdm.debuglog('allInstanceRunIds:\n' + JSON.stringify(allInstanceRunIds, null, 2));
84+
85+
var runIds = cdm.consolidateAllArrays(allInstanceRunIds);
86+
cdm.debuglog('(consolidated)allInstanceRunIds:\n' + JSON.stringify(runIds, null, 2));
87+
88+
if (typeof runIds == 'undefined' || runIds.length == 0) {
89+
console.log('The run ID could not be found, exiting');
90+
process.exit(1);
91+
}
92+
93+
cdm.debuglog('runIds:\n' + JSON.stringify(runIds, null, 2));
94+
summary['runs'] = [];
95+
for (runIdx = 0; runIdx < runIds.length; runIdx++) {
96+
cdm.debuglog('runIdx:\n' + runIdx);
97+
var thisRun = {};
98+
const runId = runIds[runIdx];
99+
var instance = await findInstanceFromRun(instances, runId);
100+
var yearDotMonth = await findYearDotMonthFromRun(instance, runId);
101+
thisRun['run-id'] = runId;
102+
thisRun['iterations'] = [];
103+
var benchName = await cdm.getBenchmarkName(instance, runId, yearDotMonth);
104+
var benchmarks = list(benchName);
105+
var benchIterations = await cdm.getIterations(instance, runId, yearDotMonth);
106+
if (benchIterations.length == 0) {
107+
cdm.debuglog('There were no iterations found, exiting');
108+
process.exit(1);
109+
}
110+
111+
var iterPrimaryMetrics = await cdm.mgetPrimaryMetric(instance, benchIterations, yearDotMonth);
112+
//returns 1D array [iter]
113+
var iterPrimaryPeriodNames = await cdm.mgetPrimaryPeriodName(instance, benchIterations, yearDotMonth);
114+
//input: 1D array
115+
//output: 2D array [iter][samp]
116+
var iterSampleIds = await cdm.mgetSamples(instance, benchIterations, yearDotMonth);
117+
//input: 2D array iterSampleIds: [iter][samp]
118+
//output: 2D array [iter][samp]
119+
var iterSampleStatuses = await cdm.mgetSampleStatuses(instance, iterSampleIds, yearDotMonth);
120+
//needs 2D array iterSampleIds: [iter][samp] and 1D array iterPrimaryPeriodNames [iter]
121+
//returns 2D array [iter][samp]
122+
var iterPrimaryPeriodIds = await cdm.mgetPrimaryPeriodId(
123+
instance,
124+
iterSampleIds,
125+
iterPrimaryPeriodNames,
126+
yearDotMonth
127+
);
128+
129+
var data = {};
130+
var numIter = {};
131+
var idx = 0;
132+
for (var i = 0; i < benchIterations.length; i++) {
133+
var primaryMetrics = list(iterPrimaryMetrics[i]);
134+
for (var j = 0; j < iterSampleIds[i].length; j++) {
135+
if (iterSampleStatuses[i][j] == 'pass') {
136+
console.log(iterPrimaryPeriodIds[i][j] + ' Iteration: ' + (i + 1) + ' Sample: ' + (j + 1));
137+
}
138+
}
139+
}
140+
}
141+
}
142+
143+
main();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=bash
3+
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4 -*-
4+
5+
# This script will call get-primary-periods.js to find all
6+
# primary periods
7+
8+
project_dir=$(dirname `readlink -e $0`)
9+
pushd "$project_dir" >/dev/null
10+
node ./get-primary-periods.js "$@"
11+
rc=$?
12+
popd >/dev/null
13+
exit $rc

0 commit comments

Comments
 (0)