⏰ Parikshan - Compiler to measure the running time of javascript functions

Gajanan Patil - Jan 13 '22 - - Dev Community

Word "parikshan" is originated from Sanskrit language meaning "examine"

Parikshan MongoDB Charts

Overview of My Submission

  1. Compiles code and wraps function calls in source with Performance hooks.
  2. Reports duration along with details like arguments, calledAt, returnedAt, functionName and location in source code (optional). In case the function returns a promise then finally handler will be attached to the promise and is reported once the finally handler is invoked.
  3. A PerformanceObserver stores the performance entries generated by parikshan in time series collection.
  4. Use this project's MongoDB Charts dashboard file when creating a new dashboard by importing it and connect it to collection created by parikshan.
  5. You can check dashboard for analysis done on botbuilder example repository here.
  6. Check project's README for usage, docs and more information.

Submission Category:

Prime Time

Link to Code

GitHub logo gajananpp / parikshan

🧐 Get insights from your code

Parikshan

lint test build npm version

Transpiler to measure the running time of javascript functions.

InstallationUsageUsing with MongoDBFAQs

Converts

// index.js
greet('John')
Enter fullscreen mode Exit fullscreen mode

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')
Enter fullscreen mode Exit fullscreen mode

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..&gt
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]

Additional Resources / Info

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
Enter fullscreen mode Exit fullscreen mode

Dashboard for analysis done on botbuilder example

. . . . . . . .