🧐 Get insights from your code

Overview

Parikshan

lint test build npm version

Compiler to measure the running time of javascript functions.

InstallationUsageUsing with MongoDBFAQs

Converts

// index.js
greet('John')

To

// output/index.js
const {parikshan} = require("parikshan/build/src/parikshan");

parikshan(greet)('John');

// if compiled with -s flag then compiles to
parikshan(
  greet,
  {"start":{"line":1,"column":0},"end":{"line":1,"column":13},"filename":"index.js"}
)('John')

Installation

To install this package run:

npm i parikshan -D

or with yarn run:

yarn add parikshan -D

Usage

CLI Usage

npx parikshan@latest -h
parikshan  <files..>

Compiles code to performance.measure the functions

Positional Arguments:
  files  One or more files or glob patterns to compile

Options:
  -h, --help        Show help                                          [boolean]
  -v, --version     Show version number                                [boolean]
  -o, --output-dir  Output directory       [string] [default: "build/parikshan"]
  -s, --source-loc  Capture line, column number in performance measurement
                                                      [boolean] [default: false]

Examples:
  parikshan "{,!(node_modules)/**/}*.js"    Compile all js files except for
  -o output                                 files under node_modules to output
                                            folder
  parikshan build/src/**/*.js -so output    Compile to output folder with source
                                            location captured

API Usage

import {Compiler} from "parikshan"

const compiler = new Compiler()
const compiledFileContents = await compiler.compile(["build/src/**/*.js"], "output", true)

See docs/README.md.

Subscribing to PerformanceEntry Events

const observer = new PerformanceObserver(entryList => {
  const entries = entryList.getEntries();
  const parikshans = entries.filter(entry => entry.name === 'parikshan')
  // do anything with performance entries generated by parikshan
});

observer.observe({
  entryTypes: ['measure'],
});

Performance Entry Structure

{
  /** PerformanceEntry name */
  name: 'parikshan';
  /** A high res timeStamp representing the time value of the duration of the function */
  duration: number;
  /** A high res timeStamp representing the starting time for the performance metric. Not a UNIX timestamp */
  startTime: number;
  /** Entry type */
  entryType: 'measure';
  /** Extra details */
  detail: {
    /** Function name. 'anonymous' if function doesn't have any name */
    functionName: string;
    /** list of function's stringified arguments */
    arguments: string[];
    /** `Date` object for function called at */
    calledAt: Date;
    /** `Date` object for function returned at */
    returnedAt: Date;
    /** Location of function in source code. Will be only present when compiled with -s flag else undefined */
    location:
      | {
          start: {
            line: number;
            column: number;
          };
          end: {
            line: number;
            column: number;
          };
          filename: string;
        }
      | undefined;
  };
}

Using with MongoDB

Use package's initMongoPerfSubscriber function to store performance entries in MongoDB.

If given collection doesn't exist, it will create time series collection with given name. In case time series collection is not supported (i.e. MongoDB version below 5.0) then normal collection will be created.

Check document structure.

You can create MongoDB charts dashboard by importing Parikshan.charts file and connect it to collection. Check blog post on how to import/export dashboard.

MongoDB charts Parikshan Dashboard

Usage of initMongoPerfSubscriber

// at the start of entry/main file do
const {initMongoPerfSubscriber} = require('parikshan')
initMongoPerfSubscriber({
   dbConnectionString: process.env.DB_CONN_STRING,
   dbName: process.env.DB_NAME,
   collectionName: process.env.DB_COLLECTION,
   // optional
   deleteAfterSeconds: 60 * 60
})

FAQs

Q: Can it compile typescript ?
Not directly. But you can run typescript compiler first and then compile output js files. For example tsc && parikshan build/src/**/*.js -so output

Q: Can this be used with frontend code ?
Yes, before bundling you can compile it. Creating a webpack loader is in roadmap.

Q: When should this not be used ?

  1. When you are overwriting defintion for Promise.prototype.finally in your code. It may give max call stack exceeded error due to recursive calls
  2. Not recommended in production environment.

Q: Why not wrap in performance.timerify instead of parikshan ?

  1. To add additional details to performance entries.
  2. performance.timerify only works in NodeJS environment as it uses internal native binding.

Q: How was the example project shown in dashboard compiled ?

NOTE :- having Azure account is not required for this to run. So envs in .env of 43.complex-dialog can be left undefined.

# clone botbuilder samples repo
git clone https://github.com/microsoft/BotBuilder-Samples.git

# goto 43.complex-dialog example
cd BotBuilder-Samples/samples/javascript_nodejs/43.complex-dialog

# install dependencies
npm install

# install parikshan as dev dependency
npm i parikshan -D

# at the beginning of index.js, add
#
# const {initMongoPerfSubscriber} = require('parikshan')
# initMongoPerfSubscriber({
#   dbConnectionString: process.env.DB_CONN_STRING,
#   dbName: process.env.DB_NAME,
#   collectionName: process.env.DB_COLLECTION,
# })

# compile with parikshan
npx parikshan "{,!(node_modules)/**/}*.js" -s

# run compiled code
node build/parikshan/index.js

# converse with bot using botframework emulator. Check README of 43.complex-dialog for info on this.

# performance entries will be stored in collection as users are using bot.
# create your own MongoDB charts dashboard or import dashboard of this project to get insights of your code.

# Adjust refresh time in `Auto-refresh settings` of dashboard according to your need

Q: What does word "parikshan" means ?
Word "parikshan" is originated from Sanskrit language meaning "examine"

You might also like...

Get the last logs of your /var/log folder

var-log-crawler Get the last logs of your /var/log folder Requirements: Node installed. Hot to use: Rename .env.sample to .env and fill with your valu

Jan 5, 2022

Get better insight on why your Remix app crashed during development 💥

Get better insight on why your Remix app crashed during development 💥

Remix Crash A root development ErrorBoundary / for your Remix apps. Overview Remix Crash is a development overlay to simplify debugging during your

Jul 19, 2022

Get discord application's assets in case you don't have them on your PC

Get discord application's assets in case you don't have them on your PC

get-discord-app-assets Get discord application's assets in case you don't have them on your PC (this is also the reason why I made this script) I came

Dec 25, 2022

A chrome extension that inserts dream signs into your browsing experience. Get points when you recognize the dream signs.

There are 3 parts to this repo: Backend Nodejs Frontend React Chrome Extension How to Start frontend and backend $ cd frontend $ npm run start In the

Apr 3, 2022

Get a diff view of your Obsidian Sync, File Recovery and Git version history

Get a diff view of your Obsidian Sync, File Recovery and Git version history

Version History Diff (for Sync and File Recovery Core plugins and Git) Note This plugin uses private APIs, so it may break at any time. Use at your ow

Dec 26, 2022

📝 [WIP] Write your reports in markdown, and get them in docx.

md-report What's md-report The repo name md-report stands for both "Write your reports in markdown, and get them in docx." and "Made report again." ("

Jun 12, 2022

Get Your Weather Details Now.

Get Your Weather Details Now.

Weatherly React WebApp to Get Your Weather Now Local Installation : Clone the repository: git clone https://github.com/PrajjwalDatir/Weatherly.git cd

Nov 25, 2022

Get, change, and otherwise interact with your notes in Obsidian via a REST API.

Local REST API for Obsidian See our interactive docs: https://coddingtonbear.github.io/obsidian-local-rest-api/ Have you ever needed to automate inter

Dec 22, 2022

Get a desktop notification every time a new correction slot is available for your 42 project.

42_slot_watcher A simple node.js corrections slots watcher for 42, working on Windows - MacOS - Linux. What is this I was bored of having to refresh t

Dec 20, 2022
Releases(v1.0.0)
Owner
Gajanan Patil
Gajanan Patil
AWS SAM project that adds the snippets from serverlessland.com/snippets as saved queries in CloudWatch Logs Insights

cw-logs-insights-snippets Serverlessland.com/snippets hosts a growing number of community provided snippets. Many of these are useful CloudWatch Logs

Lars Jacobsson 12 Nov 8, 2022
A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

Warm Up ?? ??‍?? A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snipp

Arhun Saday 34 Dec 12, 2022
Fastest way to get financial data from Plaid into your Postgres database. Go from zero to live in 5 minutes without a single line of code.

Venice Venice is a the fastest way to get financial data from Plaid into your Postgres database. Zero to production in 5 minutes without a single line

Venice 93 Dec 12, 2022
Get the latest Flashbots blocks and Flashbots transactions using TypeScript in two lines of code !

mev-blocks-js This package can let you query the Flashbots blocks API easily from any JavaScript or TypeScript project. You can access the Flashbots b

Luca G.F. 6 May 14, 2022
A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

Instagram Without APIs Instagram Scraping in August 2022, no credentials required This is a Node.js library, are you looking for the same in PHP? go t

Francesco Orsi 28 Dec 29, 2022
Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. Get a jumpstart on Remix with this workshop.

?? Remix Fundamentals Build Better websites with Remix Remix enables you to build fantastic user experiences for the web and feel happy with the code

Frontend Masters 204 Dec 25, 2022
Get dynamically generated your github contributor stats on your READMEs!

GitHub Readme Contributor Stats Get dynamically generated your github contributor stats on your READMEs! Features GitHub Contributor Stats Card Themes

Taehyun Hwang 20 Dec 11, 2022
📸 A command-line tool to generate code images of your local code right away from the terminal

?? rayli ?? A command-line tool to generate code images of your local code right away from the terminal Usage Commands Usage $ npm install -g rayli $

buidler's hub 45 Nov 4, 2022
VS Code extension that adds a red error squiggle to every word in your code.

Dumbisense Dumbisense is a VS Code extension that adds a red error squiggle to every word in your code, with an interesting error message and dino ima

Maggie Liu 9 Sep 3, 2022