{"id":16888074,"url":"https://github.com/otbe/profilr","last_synced_at":"2025-03-20T06:43:34.627Z","repository":{"id":57155021,"uuid":"61118379","full_name":"otbe/profilr","owner":"otbe","description":"tiny profiling library","archived":false,"fork":false,"pushed_at":"2017-05-22T07:36:12.000Z","size":73,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T12:47:02.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/otbe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-14T11:45:26.000Z","updated_at":"2021-03-07T21:50:02.000Z","dependencies_parsed_at":"2022-09-07T18:11:07.555Z","dependency_job_id":null,"html_url":"https://github.com/otbe/profilr","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Fprofilr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Fprofilr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Fprofilr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Fprofilr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otbe","download_url":"https://codeload.github.com/otbe/profilr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244566930,"owners_count":20473451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:48:45.938Z","updated_at":"2025-03-20T06:43:34.603Z","avatar_url":"https://github.com/otbe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# profilr\n\n[![Build Status](https://travis-ci.org/otbe/profilr.svg?branch=master)](https://travis-ci.org/otbe/profilr)\n[![Coverage Status](https://coveralls.io/repos/github/otbe/profilr/badge.svg?branch=master)](https://coveralls.io/github/otbe/profilr?branch=master)\n\n*profilr* is a very tiny profiling library for your functions. It tracks down the execution time of each call and emits events.\nIt also supports functions that return a ```Promise```, so ```async```/```await``` can be tracked too. :)\nIt tries to add as less as possible overhead to the decorated or wrapped functions.\n\nBasically *profilr* is unoptionated in what you're doing with this events. It does not log or evaluate something.\nYou have to add a consumer for this events. See the ```Consumers``` section.\n\n## Install\n\n```npm i profilr --save```\n\n## Usage\n*profilr* is written in TypeScript and typings are available. It can be used with TypeScript decorators, babel decorators and as a function wrapper.\n\n```javascript\nimport { profile, useProfilr } from 'profilr';\n\nuseProfilr(true);\n\nclass MyService {\n  constructor() {\n    // fnName will be an empty string, but events will be labeled with 'getNumberOfRows'\n    const getNumberOfRows = profile(() =\u003e 5, 'getNumberOfRows');\n\n    // fnName will be 'getNumberOfColumns'\n    const getNumberOfColumns = profile(function getNumberOfColumns() { return 5 });\n  }\n\n  @profile() // fnName will be 'expensiveComputation'\n  expensiveComputation (): number {\n    return 1*1;\n  }\n\n  @profile({ custom: 'foo' }) // fnName will be 'remoteApiCall'\n  remoteApiCall (): Promise\u003cnumber\u003e {\n    return new Promise((resolve) =\u003e resolve(5));\n  }\n}\n```\nSee tests for more usage information.\n\n## Consumers\nFirst consumer will be a react devtool like known from redux and mobx, but its not finished yet.\n\nStay tuned!\n\n## API\nAll functions are available at the top level import.\n\n### useProfilr\n```\nuseProfilr(active: boolean)\n```\nEnables or disables *profilr*. The decorated or wrapped functions will still have some logic from *profilr*, but the overhead\nis negligible. *profilr* is enabled by default.\n\n### profile\n```profile``` is a function wrapper or class method decorator which can be used to profile your function calls.\n\nFunction wrapper signatures:\n```javascript\nfunction profile\u003cT extends Function\u003e (fn: T): T;\nfunction profile\u003cT extends Function\u003e (fn: T, label: string): T;\nfunction profile\u003cT extends Function\u003e (fn: T, options: ProfileOptions): T;\nfunction profile\u003cT extends Function\u003e (fn: T, label: string, options: ProfileOptions): T;\n```\n\nClass method decorators:\n```javascript\nfunction profile (): (target: any, propertyKey: string, descriptor: PropertyDescriptor) =\u003e PropertyDescriptor;\nfunction profile (label: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) =\u003e PropertyDescriptor;\nfunction profile (options: ProfileOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) =\u003e PropertyDescriptor;\nfunction profile (label: string, options: ProfileOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) =\u003e PropertyDescriptor;\n```\n\nParameter | Description\n------------ | -------------\n```fn``` | Function to be profiled\n```label``` | Consumers can group several functions based on this string.\n```options``` | Configuration object. For now it only holds a ```custom``` field, which can be used to send custom data to a consumer.\n\n### registerEventCallback\n```\nfunction registerEventCallback(cb: EventCallback): () =\u003e void\n```\nRegisters a callback for events produced by *profilr*. It returns a dispose function.\nOnly one parameter will be passed to the callback and it looks like this example:\n\n```javascript\n{\n  id: 1,                            // each profiled function has an unique id\n  fnName: 'map',                    // inferred name of function\n  label: 'Part of Array prototype', // label\n  duration: 50,                     // duration in ms\n  result: [],                       // result of this call\n  options: {\n    custom: 'test'                  // custom data\n  }\n}\n```\n\n## Dependencies\n*profilr* comes without dependencies, but it needs a [Reflect Metadata API](https://www.npmjs.com/package/reflect-metadata)\npolyfill if your environment does not support it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Fprofilr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotbe%2Fprofilr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Fprofilr/lists"}