Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
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.
Heimdall tracks a graph of timing and domain-specific stats for performance. Stat collection and monitoring is separated from graph construction to provide control over context detail. Users can create fewer nodes to have reduced performance overhead, or create more nodes to provide more detail.
The graph obviously needs to be global. This is not a problem in the browser,
but in node we may have multiple different versions of heimdalljs loaded at
once. Each one will have its own Heimdall
instance, but will use the same
session, saved on process
. This means that the session will have a
heterogeneous graph of HeimdallNode
s. For this reason, versions of heimdalljs
that change Session
, or the APIs of HeimdallNode
or Cookie
will use a
different property to store their session (process._heimdall_session_<n>
). It
is quite easy for this to result in lost detail & lost stats, although it is
also easy to detect this situation and issue a warning.
require('heimdalljs')
to access an instance using the globally shared session.
You can create your own instance with its own session, but this is generally reommended only for testing.
var Heimdall = require('heimdalljs/heimdall');
// this will create its own session and not use the global session
var myInstance = new Heimdall();
heimdall.current
Return the leaf HeimdallNode
of the currently active nodes.heimdall.root
Return the root HeimdallNode
heimdall.start(id, Schema)
Create a new node with id id
. This node becomes the
active node. Its parent is the currently active node. Return this node's
Cookie
.heimdall.node(id, [Schema], callback, [context])
Create a new node, invoke
callback
passing in the newly created node's stats
object and then stop
the node.registerMonitor(name, Schema)
register a monitor under namespace name
. An
error will be thrown if the reserved names own
or time
are used, or if a
monitor with that name has already been registered for this session.statsFor(name)
return the stats object for the monitor under namespace
name
.configFor(name)
return the config object under name
. Heimdall does not do
anything with these config objects: it is a place for downstream consumers to
share config across a heimdall session (see eg
heimdalljs-logger).toJSON()
return the json for the entire graph. This is intended to be
written via JSON.stringify
and then consumed by downstream apps (see eg
broccoli-viz).visitPreOrder(callback)
sugar for root.visitPreOrder(callback)
visitPostOrder(callback)
sugar for root.visitPostOrder(callback)
isRoot
returns true for the root node, and false for all other nodes.visitPreOrder(callback)
visit the subtree rooted at this node with a
depth-first pre-order traversal.visitPostOrder(callback)
visit the subtree rooted at this node with a
depth-first post-order traversal.forEachChild(callback)
invoke callback
for each child of this node (but
not other descendants).remove
remove this node from its parent. May only be called on an inactive,
non-root node. Intended for long-running applications to free up memory after
saving a subgraph via toJSONSubgraph
.toJSON()
Return the serialized representation of this ndoe.toJSONSubgraph()
Return the serialized representation of the subtree rooted at
this node.stop()
stop the node associated with this cookie. May only be called on the
current node.resume()
resume a stopped node. This is useful for nodes that are restarted
asynchronously.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
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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.