Comparing version 1.0.0 to 1.1.0
1.1.0 / 2018-05-24 | ||
================== | ||
* improve output formatting | ||
* add support for enabling by setting AKUKU env variable | ||
1.0.0 / 2018-05-23 | ||
@@ -3,0 +9,0 @@ ================== |
19
index.js
@@ -1,1 +0,18 @@ | ||
module.exports = require('./lib/akuku'); | ||
const akuku = require('./lib/akuku'); | ||
const dummy = require('./lib/dummy'); | ||
module.exports = checkEnvironment() ? akuku : dummy; | ||
function checkEnvironment() { | ||
let env = process.env.AKUKU; | ||
if (!env) { | ||
return false; | ||
} | ||
switch (env.toLowerCase()) { | ||
case '1': | ||
case 'on': | ||
case 'true': | ||
return true; | ||
} | ||
return false; | ||
} |
@@ -1,2 +0,2 @@ | ||
const { addNanos, toHuman } = require('./tools'); | ||
const { addNanos, formatTiming, formatCounters } = require('./tools'); | ||
const makeCounters = require('./counters'); | ||
@@ -22,5 +22,4 @@ | ||
function toString() { | ||
let activeStr = toHuman(active); | ||
return `${counter} ${name}: ${activeStr}`; | ||
function toString(prefix = '') { | ||
return formatTiming(counter, name, active, prefix); | ||
} | ||
@@ -39,3 +38,5 @@ | ||
console.log(toString()); | ||
console.log(counters.toString()); | ||
if (!counters.empty()) { | ||
console.log(formatCounters(counters.toObject())); | ||
} | ||
} | ||
@@ -45,4 +46,4 @@ | ||
process.on('SIGUSR2', function() { | ||
let active = activeFrom ? '+++ active' : '--- inactive'; | ||
console.log(active + '\t' + toString()); | ||
let active = activeFrom ? '+++ active ' : '--- inactive'; | ||
console.log(toString(active)); | ||
}); | ||
@@ -49,0 +50,0 @@ } |
@@ -0,1 +1,3 @@ | ||
const { formatCounters } = require('./tools'); | ||
module.exports = makeCounter; | ||
@@ -18,7 +20,3 @@ | ||
function toString() { | ||
let strings = new Array(counters.length); | ||
for(let i = 0; i < strings.length; i++) { | ||
strings[i] = `${counters[i]} ${labels[i]}`; | ||
} | ||
return strings.join('\n'); | ||
return formatCounters(toObject()); | ||
} | ||
@@ -34,4 +32,9 @@ | ||
function empty() { | ||
return counters.length === 0; | ||
} | ||
return { | ||
add, | ||
empty, | ||
toString, | ||
@@ -38,0 +41,0 @@ toObject |
module.exports = { | ||
addNanos, | ||
toHuman | ||
toHuman, | ||
formatCounters, | ||
formatTiming | ||
}; | ||
@@ -38,1 +40,18 @@ | ||
} | ||
const NUMBER_LEN = Number.MAX_SAFE_INTEGER.toString().length; | ||
const NAME_LEN = 25; | ||
function formatCounters(counters, prefix = '') { | ||
let strings = Object.entries(counters) | ||
.map(([n, v]) => `${prefix}${v.toString().padStart(NUMBER_LEN)} ${n}`); | ||
return strings.join('\n'); | ||
} | ||
function formatTiming(counter, name, nanos, prefix = '') { | ||
let nanosStr = toHuman(nanos); | ||
let counterStr = counter.toString().padStart(NUMBER_LEN); | ||
let nameStr = name.padEnd(NAME_LEN); | ||
return `${prefix}${counterStr} ${nameStr} ${nanosStr}`; | ||
} |
{ | ||
"name": "akuku", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Small timing counter utility.", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6670
8
167
2