⏰ Parikshan - Compiler to measure the running time of javascript functions
Tags: atlashackathon, mongodb, javascript, programming
Published: 2022-01-13 14:21:10

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

[![Parikshan MongoDB Charts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwyzq7zgal8snpjxd47z.png)](https://charts.mongodb.com/charts-hackathon-xezpo/public/dashboards/61ddb47a-69ec-49df-8061-145da7025f8b)

### Overview of My Submission

1. Compiles code and wraps function calls in source with [Performance](https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API) 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](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver) stores the performance entries generated by `parikshan` in [time series collection](https://docs.mongodb.com/manual/core/timeseries-collections/). 
4. Use this project's MongoDB Charts [dashboard file](https://github.com/gajananpp/parikshan/blob/main/assets/Parikshan.charts) when creating a new dashboard by [importing](https://www.mongodb.com/blog/post/import-export-your-charts-dashboards) it and connect it to collection created by parikshan. 
5. You can check dashboard for analysis done on [botbuilder example](https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/43.complex-dialog) repository [here](https://charts.mongodb.com/charts-hackathon-xezpo/public/dashboards/61ddb47a-69ec-49df-8061-145da7025f8b).
6. Check project's [README](https://github.com/gajananpp/parikshan/blob/main/README.md) for usage, docs and more information.

### Submission Category: 

Prime Time

### Link to Code

{% github gajananpp/parikshan %}


### Additional Resources / Info

<br />

**Q: How was the example project shown in [dashboard](https://charts.mongodb.com/charts-hackathon-xezpo/public/dashboards/61ddb47a-69ec-49df-8061-145da7025f8b) compiled ?**

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

```bash
# 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
```


Dashboard for analysis done on [botbuilder example](https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/43.complex-dialog)

{% codepen https://codepen.io/gajananpp/pen/rNGqZLb %}