Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
heimdalljs
Advanced tools
HeimdallJS is a lightweight performance monitoring library for JavaScript applications. It allows developers to track and measure the performance of their code by creating performance metrics and visualizing them. This can be particularly useful for identifying bottlenecks and optimizing the performance of web applications.
Creating a Monitor
This feature allows you to create a performance monitor that tracks the execution time of a specific block of code. You start the monitor before the code block and stop it after the code block.
const heimdall = require('heimdalljs');
const monitor = heimdall.start('my-monitor');
// Your code here
monitor.stop();
Tracking Performance Metrics
This feature allows you to track specific performance metrics by starting and stopping named metrics. You can then retrieve and log the statistics for these metrics.
const heimdall = require('heimdalljs');
heimdall.start('my-metric');
// Your code here
heimdall.stop('my-metric');
const stats = heimdall.statsFor('my-metric');
console.log(stats);
Visualizing Performance Data
This feature allows you to visualize the performance data collected by HeimdallJS. You can convert the performance data into a JSON format and log it for further analysis.
const heimdall = require('heimdalljs');
const monitor = heimdall.start('my-monitor');
// Your code here
monitor.stop();
const tree = heimdall.toJSON();
console.log(JSON.stringify(tree, null, 2));
The 'performance-now' package provides a high-resolution timer for measuring performance in JavaScript applications. It is simpler and more lightweight compared to HeimdallJS, focusing solely on providing precise timestamps.
The 'statsd' package is a network daemon that listens for statistics, like counters and timers, sent over UDP or TCP and sends aggregates to one or more pluggable backend services. It is more comprehensive and can be used for a broader range of performance monitoring tasks compared to HeimdallJS.
The 'node-perf' package is a performance monitoring tool for Node.js applications. It provides similar functionality to HeimdallJS, such as tracking execution time and performance metrics, but is specifically designed for Node.js environments.
var heimdall = require('heimdall');
function BroccoliNodeSchema() {
this.builds = 0;
}
heimdall.node('broccoli', function () {
heimdall.node('node:babel', BroccoliNodeSchema, function (h) {
h.builds++;
heimdall.node('node:persistent-filter', BroccoliNodeSchema, function (h) {
h.builds++;
});
heimdall.node('node:caching-writer', BroccoliNodeSchema, function (h) {
h.builds++;
});
});
});
{
"nodes": [{
"id": 0,
"name": "broccoli",
"stats": {
"cpu": {
"self": 10,
},
},
"children": {
"start": [1],
"end": [1],
},
}, {
"id": 1,
"name": "node:babel",
"stats": {
"builds": 1,
"cpu": {
"self": 20,
},
},
"children": {
"start": [2, 3],
"end": [2, 3],
},
}, {
"id": 2,
"name": "node:persistent-filter",
"stats": {
"builds": 1,
"cpu": {
"self": 30,
},
},
}, {
"id": 3,
"name": "node:caching-writer",
"stats": {
"builds": 1,
"cpu": {
"self": 40,
},
},
}],
}
var heimdall = require('heimdall');
var fs = require('fs');
var origLstatSync = fs.lstatSync;
var origMkdirSync = fs.mkdirSync;
heimdall.registerMonitor('fs', function FSSchema() {
this.lstatCount = 0;
this.mkdirCount = 0;
});
fs.lstatSync = function () {
heimdall.statsFor('fs').lstatCount++;
return origLstatSync.apply(fs, arguments);
}
fs.mkdirSync = function () {
heimdall.statsFor('fs').mkdirCount++;
return origMkdirSync.apply(fs, arguments);
}
function BroccoliNodeSchema() {
this.builds = 0;
}
heimdall.node('broccoli', function () {
heimdall.node('node:babel', BroccoliNodeSchema, function (h) {
h.builds++;
heimdall.node('node:persistent-filter', BroccoliNodeSchema, function (h) {
h.builds++;
fs.mkdirSync('./tmp');
});
heimdall.node('node:caching-writer', BroccoliNodeSchema, function (h) {
h.builds++;
fs.lstatSync('./tmp');
});
});
});
{
"nodes": [{
"id": 0,
"name": "broccoli",
"stats": {
"cpu": {
"self": 10,
},
"fs": {
lstatCount: 0,
mkdirCount: 0,
},
},
"children": {
"start": [1],
"end": [1],
},
}, {
"id": 1,
"name": "node:babel",
"stats": {
"builds": 1,
"cpu": {
"self": 20,
},
"fs": {
lstatCount: 0,
mkdirCount: 0,
},
},
"children": {
"start": [2, 3],
"end": [2, 3],
},
}, {
"id": 2,
"name": "node:persistent-filter",
"stats": {
"builds": 1,
"cpu": {
"self": 30,
},
"fs": {
lstatCount: 0,
mkdirCount: 1,
},
},
}, {
"id": 3,
"name": "node:caching-writer",
"stats": {
"builds": 1,
"cpu": {
"self": 40,
},
"fs": {
lstatCount: 1,
mkdirCount: 0,
},
},
}],
}
FAQs
Structured instrumentation library
The npm package heimdalljs receives a total of 369,317 weekly downloads. As such, heimdalljs popularity was classified as popular.
We found that heimdalljs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.