
Research
/Security News
npm Author Qix Compromised in Major Supply Chain Attack
npm author Qixโs account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
@pax-k/chrono-scope-js
Advanced tools
Unveil the performance mysteries of your JavaScript code! This sleek profiler ๐ hooks into your functions seamlessly, timing ๐ their execution and providing insight into async operations. Navigate your codebase with newfound clarity, optimizing ๐ ๏ธ as y
This JavaScript module provides a profiling proxy utility ๐ ๏ธ to help you monitor and log โฑ๏ธ the execution time of your functions, including async functions and iterators. It is designed to wrap around your existing functions and objects to measure their performance with high precision using the performance.now()
method. It is especially useful for developers who want to debug ๐ง and optimize ๐ their code by identifying bottlenecks in function executions.
createProfilingProxy
, not only is its direct execution time logged, but the module also delves into any subsequent function calls made within it - going "all the way down" the call stack. This allows for a comprehensive understanding of performance and potential bottlenecks that occur at any level of the stack during the execution flow.createProfilingProxy
.next
calls and supports both synchronous and asynchronous iterators.Promise
, Map
, Set
, etc., to prevent unnecessary overhead.๐ฅ Import the Profiler:
Import the createProfilingProxy
function from the module into your JavaScript codebase.
๐ Wrap Functions or Objects:
Wrap any function or object with createProfilingProxy
to start profiling. If the target is a function, it will be directly profiled. If it's an object, all enumerable properties that are functions will be profiled recursively.
๐ต๏ธโโ๏ธ Review Logs: Execute your code as usual. Check the console for logs indicating how long each function takes to execute. Asynchronous functions will log the time upon resolution or rejection.
import { createProfilingProxy } from 'chrono-scope-js';
// Your original function
function myFunction() {
// function body
}
// Wrap your function
const profiledMyFunction = createProfilingProxy(myFunction);
// Use the profiled version
profiledMyFunction();
./run-your-script > log.txt
Simple Function Execution: When a regular (synchronous) function is executed, you would see:
Function library.myFunction took 15.00 ms.
Async Function Execution: For an asynchronous function that resolves successfully, you would see:
Async function library.myAsyncFunction took 47.00 ms.
If the asynchronous function fails (i.e., rejects), then the output would be:
Async function library.myAsyncFunction failed after 47.00 ms with error: Error: Something went wrong
Iterator next
Call:
Every time the next
method of an iterator is called, the console would log:
Iterator next took 2.00 ms.
Function Throwing an Error: If a profiled function throws an error, you would see:
Function library.myFaultyFunction failed after 10.00 ms with error: Error: I always throw
Profiling a Nested Function: When profiling an object with nested functions, the output will show the path to the nested function:
Function library.myObject.myNestedFunction took 5.00 ms.
See assets/write_log.txt
Function library.dwn.agent.dwnManager._agent.didManager._agent.didResolver.cache.get took 0.00 ms.
Function library.dwn.agent.dwnManager.agent.didManager._agent.didResolver.cache.get took 0.15 ms.
Function library.dwn.agent.dwnManager._agent.didManager.agent.didResolver.cache.get took 0.21 ms.
Function library.dwn.agent.dwnManager.agent.didManager.agent.didResolver.cache.get took 0.26 ms.
Function library.dwn.agent.dwnManager._agent.didManager._agent.didResolver.cache.set took 0.00 ms.
Function library.dwn.agent.dwnManager.agent.didManager._agent.didResolver.cache.set took 0.13 ms.
Function library.dwn.agent.dwnManager._agent.didManager.agent.didResolver.cache.set took 0.20 ms.
Function library.dwn.agent.dwnManager.agent.didManager.agent.didResolver.cache.set took 0.25 ms.
Async function library.dwn.agent.dwnManager._agent.didManager._agent.didResolver.resolve took 0.47 ms.
Async function library.dwn.agent.dwnManager.agent.didManager._agent.didResolver.resolve took 0.48 ms.
Async function library.dwn.agent.dwnManager._agent.didManager.agent.didResolver.resolve took 0.48 ms.
Async function library.dwn.agent.dwnManager.agent.didManager.agent.didResolver.resolve took 0.48 ms.
Function library.dwn.agent.dwnManager._agent.didManager.getMethod took 0.01 ms.
Function library.dwn.agent.dwnManager.agent.didManager.getMethod took 0.07 ms.
Async function library.dwn.agent.dwnManager._agent.didManager.getDefaultSigningKey took 0.55 ms.
Async function library.dwn.agent.dwnManager.agent.didManager.getDefaultSigningKey took 0.55 ms.
Async function library.dwn.agent.dwnManager.getAuthorSigningKeyId took 0.59 ms.
Async function library.dwn.agent.dwnManager._agent.keyManager._store.getAuthor took 0.01 ms.
Async function library.dwn.agent.dwnManager.agent.keyManager._store.getAuthor took 0.02 ms.
Function library.dwn.agent.dwnManager._agent.keyManager._agent.dwnManager._agent.didManager._agent.didResolver.cache.get took 0.00 ms.
Function library.dwn.agent.dwnManager.agent.keyManager._agent.dwnManager._agent.didManager._agent.didResolver.cache.get took 0.06 ms.
....
The times (in milliseconds) are examples and will vary based on the actual execution time of the function. The profiler logs are formatted to two decimal places for precision and readability.
For iterators, the next
method is wrapped only once to avoid excessive performance overhead. It logs the time taken for each iteration. โฒ๏ธ
RangeError: Maximum call stack size exceeded
error typically occurs when there is an uncontrolled recursion or a circular reference. This module implements checks to prevent profiling already profiled objects, which should mitigate such issues when using iterators or recursive functions.
After running your JavaScript code with the profiling proxy enabled, you can aggregate and analyze the logged performance data using a Python script. The provided script aggregate_log.py
reads the execution logs and outputs a summary of the total execution time and call count for each profiled function or method.
console.log()
or console.error()
calls in the format used by the profiler.Save Logs to a File:
Direct the console output from your browser or Node.js to a text file. For example, in a UNIX-like terminal, you might use node myScript.js > logs.txt
to run your script and save the logs.
Run the Script:
Use the command line to run the Python script with the path to the log file as an argument. Replace <path_to_log_file>
with the actual path to your log file:
python aggregate_log.py <path_to_log_file>
If successful, the script will print a markdown-formatted table to the console, summarizing the total calls and execution time for each profiled function or method.
The aggregate_log.py
script prints the aggregated data in a table format. Here's an example of what the output might look like:
| Function/Method | Total Calls | Total Execution Time (ms) |
| --- | --- | --- |
| library.myFunction | 3 | 150.75 |
| library.myAsyncFunction | 2 | 312.60 |
See assets/write_aggregated_log.txt
| Function/Method | Total Calls | Total Execution Time (ms) |
| --- | --- | --- |
| next | 1710 | 2856.950000000003 |
| library.dwn.agent.dwnManager.agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.keyEncoding.decode | 556 | 417.7499999999996 |
| library.dwn.agent.dwnManager._agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.keyEncoding.decode | 556 | 387.59000000000066 |
| library.dwn.agent.dwnManager.agent.keyManager._agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.keyEncoding.decode | 556 | 358.52000000000027 |
| library.dwn.agent.dwnManager.agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.valueEncoding.decode | 556 | 357.94999999999965 |
| library.dwn.agent.dwnManager._agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.valueEncoding.decode | 556 | 325.91000000000014 |
| library.dwn.agent.dwnManager._agent.keyManager._agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.keyEncoding.decode | 556 | 322.85999999999893 |
| library.dwn.agent.dwnManager.agent.keyManager._agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.valueEncoding.decode | 556 | 292.78999999999996 |
| library.dwn.agent.dwnManager._agent.keyManager._agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db.valueEncoding.decode | 556 | 258.2699999999995 |
| library.dwn.agent.dwnManager.agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.index.db.db._db.newIterator.valid | 1144 | 243.2599999999978 |
| library.dwn.agent.dwnManager.agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.blockstore.db.db.sublevel.get | 16 | 230.73000000000005 |
| library.dwn.agent.dwnManager._agent.keyManager.agent.dwnManager._dwn.methodHandlers.RecordsQuery.messageStore.blockstore.db.db.sublevel.get | 16 | 230.66 |
Each row represents a profiled function, showing how many times it was called and the total time spent executing it.
const profiledMyLibrary = createProfilingProxy(myLibrary);
./run-your-startup-script > log.txt
python aggregate_log.py log.txt > aggregated_log.md
open aggregated_log.md
If you encounter errors while running the script, ensure that:
The aggregation script is part of the open-source effort. If you have improvements or encounter issues with the script, please contribute by opening an issue or pull request on GitHub, just as with the JavaScript module.
Start profiling and get insights into your function performance now! ๐
FAQs
Unveil the performance mysteries of your JavaScript code! This sleek profiler ๐ hooks into your functions seamlessly, timing ๐ their execution and providing insight into async operations. Navigate your codebase with newfound clarity, optimizing ๐ ๏ธ as y
We found that @pax-k/chrono-scope-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 1 open source maintainer 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.
Research
/Security News
npm author Qixโs account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.