timer-set
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "timer-set", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Code timing class", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/BrenPatF/timer-set_nodejs#readme", |
@@ -9,3 +9,3 @@ /*************************************************************************************************** | ||
npm: $ npm install timer-set | ||
npm: $ npm install timer-set | ||
@@ -43,8 +43,8 @@ See 'Code Timing and Object Orientation and Zombies' for the original idea implemented in Oracle | ||
const DELIM = '|'; | ||
const [CON, INC, INI, GET, GETF, SELF, SELFF, RES] = | ||
const [CON, INC, INI, GET, GETF, SELF, SELFF, RES] = | ||
["CON", "INC", "INI", "GET", "GETF", "SELF", "SELFF", "RES"]; | ||
const [EVENT_SEQUENCE, SCALARS] = ["Event Sequence", "Scalars"]; | ||
const [TIMER_SET_1, TIMER_SET_1_F, TIMER_SET_2, TIMER_SET_2_F] = | ||
["Set 1", "Set 1 (formatted)", "Set 2", "Set 2 (formatted)"]; | ||
const [SELF_GRP, SELF_GRP_F, RES_GRP, EXCEPTION] = | ||
const [TIMER_SET_1, TIMER_SET_1_F, TIMER_SET_2, TIMER_SET_2_F] = | ||
["Set 1", "Set 1 (formatted)", "Set 2", "Set 2 (formatted)"]; | ||
const [SELF_GRP, SELF_GRP_F, RES_GRP, EXCEPTION] = | ||
["Self (unmocked)", "Self (unmocked, formatted)", "Results", "Exception"]; | ||
@@ -55,101 +55,101 @@ const testData = Trapit.getUTData(INPUT_JSON); | ||
const [mock_yn, timeWidth, dpTotals, dpPerCall, callsWidth] = | ||
[...Utils.csvToLis(callScenario.inp[SCALARS][0]).map(v => v === '' ? undefined : v)]; | ||
const events = callScenario.inp[EVENT_SEQUENCE]; | ||
const times = events.map(e => Utils.csvToLis(e)); | ||
let timerSet = {}; | ||
let counter_n = 0; | ||
const [mock_yn, timeWidth, dpTotals, dpPerCall, callsWidth] = | ||
[...Utils.csvToLis(callScenario.inp[SCALARS][0]).map(v => v === '' ? undefined : v)]; | ||
const events = callScenario.inp[EVENT_SEQUENCE]; | ||
const times = events.map(e => Utils.csvToLis(e)); | ||
let timerSet = {}; | ||
let counter_n = 0; | ||
function now() { | ||
counter_n += 1; | ||
counter_n += 1; | ||
return times[counter_n - 1][3]; | ||
} | ||
let counter_c = 0; | ||
function cpus() { | ||
} | ||
let counter_c = 0; | ||
function cpus() { | ||
counter_c += 1; | ||
return [ | ||
{times: {user: times[counter_c - 1][4], sys: times[counter_c - 1][5]}}, | ||
{times: {user: times[counter_c - 1][6], sys: times[counter_c - 1][7]}} | ||
{times: {user: times[counter_c - 1][4], sys: times[counter_c - 1][5]}}, | ||
{times: {user: times[counter_c - 1][6], sys: times[counter_c - 1][7]}} | ||
]; | ||
} | ||
let [outArr, outArrF, exceptions, selfTimer, selfTimerF, results] = | ||
[{[TIMER_SET_1]: [], [TIMER_SET_2]: []}, {[TIMER_SET_1]: [], [TIMER_SET_2]: []}, [], [], [], []]; | ||
for (const i in events) { | ||
const eLis = Utils.csvToLis(events[i]); | ||
const [setNm, timerNm, event, sleepTime, ela, usr, sys] = [...eLis]; | ||
if (mock_yn != 'Y') Utils.sleep(sleepTime); | ||
switch(event) { | ||
case CON: | ||
if (mock_yn === 'Y') { | ||
timerSet[setNm] = new TimerSet(setNm, now, cpus); | ||
} else { | ||
timerSet[setNm] = new TimerSet(setNm); | ||
} | ||
} | ||
let [outArr, outArrF, exceptions, selfTimer, selfTimerF, results] = | ||
[{[TIMER_SET_1]: [], [TIMER_SET_2]: []}, {[TIMER_SET_1]: [], [TIMER_SET_2]: []}, [], [], [], []]; | ||
for (const i in events) { | ||
const eLis = Utils.csvToLis(events[i]); | ||
const [setNm, timerNm, event, sleepTime, ela, usr, sys] = [...eLis]; | ||
if (mock_yn != 'Y') Utils.sleep(sleepTime); | ||
switch(event) { | ||
case CON: | ||
if (mock_yn === 'Y') { | ||
timerSet[setNm] = new TimerSet(setNm, now, cpus); | ||
} else { | ||
timerSet[setNm] = new TimerSet(setNm); | ||
} | ||
break; | ||
case INC: | ||
timerSet[setNm].incrementTime(timerNm); | ||
case INC: | ||
timerSet[setNm].incrementTime(timerNm); | ||
break; | ||
case INI: | ||
timerSet[setNm].initTime(); | ||
case INI: | ||
timerSet[setNm].initTime(); | ||
break; | ||
case GET: | ||
case GET: | ||
outArr[setNm] = timerSet[setNm].getTimers().map(t => Object.values(t).join(DELIM)); | ||
break; | ||
case GETF: | ||
try { | ||
outArrF[setNm] = timerSet[setNm].formatTimers(timeWidth, dpTotals, dpPerCall, callsWidth); | ||
case GETF: | ||
try { | ||
outArrF[setNm] = timerSet[setNm].formatTimers(timeWidth, dpTotals, dpPerCall, callsWidth); | ||
} catch(e) { | ||
exceptions[0] = e.message; | ||
exceptions[1] = e.stack; | ||
exceptions[0] = e.message; | ||
exceptions[1] = e.stack; | ||
} | ||
break; | ||
case SELF: | ||
case SELF: | ||
selfTimer = [Object.values(TimerSet.getSelfTimer()).join(DELIM)]; | ||
break; | ||
case SELFF: | ||
case SELFF: | ||
selfTimerF = [TimerSet.formatSelfTimer()]; | ||
break; | ||
case RES: | ||
case RES: | ||
results = [timerSet[setNm].formatResults()]; | ||
break; | ||
default: | ||
default: | ||
throw `Error event ${event} not known`; | ||
} | ||
} | ||
return { | ||
inp: callScenario.inp, | ||
out: { | ||
[TIMER_SET_1] : { | ||
exp: callScenario.out[TIMER_SET_1], | ||
act: outArr[TIMER_SET_1] | ||
}, | ||
[TIMER_SET_1_F] : { | ||
exp: callScenario.out[TIMER_SET_1_F], | ||
act: outArrF[TIMER_SET_1] | ||
}, | ||
[TIMER_SET_2] : { | ||
exp: callScenario.out[TIMER_SET_2], | ||
act: outArr[TIMER_SET_2] | ||
}, | ||
[TIMER_SET_2_F] : { | ||
exp: callScenario.out[TIMER_SET_2_F], | ||
act: outArrF[TIMER_SET_2] | ||
}, | ||
[SELF_GRP] : { | ||
exp: callScenario.out[SELF_GRP], | ||
act: selfTimer | ||
}, | ||
[SELF_GRP_F] : { | ||
exp: callScenario.out[SELF_GRP_F], | ||
act: selfTimerF | ||
}, | ||
[RES_GRP] : { | ||
exp: callScenario.out[RES_GRP], | ||
act: results | ||
}, | ||
[EXCEPTION] : { | ||
exp: callScenario.out[EXCEPTION], | ||
act: exceptions | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
return { | ||
inp: callScenario.inp, | ||
out: { | ||
[TIMER_SET_1] : { | ||
exp: callScenario.out[TIMER_SET_1], | ||
act: outArr[TIMER_SET_1] | ||
}, | ||
[TIMER_SET_1_F] : { | ||
exp: callScenario.out[TIMER_SET_1_F], | ||
act: outArrF[TIMER_SET_1] | ||
}, | ||
[TIMER_SET_2] : { | ||
exp: callScenario.out[TIMER_SET_2], | ||
act: outArr[TIMER_SET_2] | ||
}, | ||
[TIMER_SET_2_F] : { | ||
exp: callScenario.out[TIMER_SET_2_F], | ||
act: outArrF[TIMER_SET_2] | ||
}, | ||
[SELF_GRP] : { | ||
exp: callScenario.out[SELF_GRP], | ||
act: selfTimer | ||
}, | ||
[SELF_GRP_F] : { | ||
exp: callScenario.out[SELF_GRP_F], | ||
act: selfTimerF | ||
}, | ||
[RES_GRP] : { | ||
exp: callScenario.out[RES_GRP], | ||
act: results | ||
}, | ||
[EXCEPTION] : { | ||
exp: callScenario.out[EXCEPTION], | ||
act: exceptions | ||
} | ||
} | ||
}; | ||
} | ||
@@ -159,7 +159,7 @@ | ||
for (const s in callScenarios) { | ||
if (!(callScenarios[s].enabled_yn === 'N')) { // optional in input json | ||
scenarios[s] = purelyWrapUnit(callScenarios[s]); | ||
} | ||
if (!(callScenarios[s].enabled_yn === 'N')) { // optional in input json | ||
scenarios[s] = purelyWrapUnit(callScenarios[s]); | ||
} | ||
}; | ||
Trapit.prUTResultsTextAndHTML(meta, scenarios, ROOT); |
2462250