{"id":45718,"library":"p-profiler","title":"p-profiler","description":"p-profiler is a JavaScript library (v0.2.1, stable) from Microsoft that wraps promise-returning functions to generate Chrome DevTools-compatible profiling JSON. It integrates with concurrency libraries like p-queue and p-graph to trace async task execution, helping developers visualize bottlenecks in promise-heavy workflows. Unlike generic profilers, it targets promise queues and graph-based task scheduling, outputting a trace file that can be loaded into browser DevTools for flamechart analysis. Ships TypeScript definitions. Release cadence is low; primarily a utility for debugging concurrent async operations.","status":"active","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/microsoft/p-profiler","tags":["javascript","typescript"],"install":[{"cmd":"npm install p-profiler","lang":"bash","label":"npm"},{"cmd":"yarn add p-profiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add p-profiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for TypeScript type checking of Node.js APIs (e.g., fs.writeFileSync used in output())","package":"@types/node","optional":true}],"imports":[{"note":"Package is ESM-only; no CommonJS export. TypeScript types are shipped.","wrong":"const Profiler = require('p-profiler')","symbol":"Profiler","correct":"import Profiler from 'p-profiler'"},{"note":"The package exports a single default class. Named import will fail.","wrong":"import { Profiler } from 'p-profiler'","symbol":"default import","correct":"import Profiler from 'p-profiler'"},{"note":"For dynamic imports, use ESM top-level await or import(). require() is not supported.","wrong":"const Profiler = require('p-profiler').default","symbol":"Profiler","correct":"const Profiler = await import('p-profiler')"}],"quickstart":{"code":"import Profiler from 'p-profiler';\nimport PQueue from 'p-queue';\n\nconst concurrency = 2;\nconst profiler = new Profiler({ concurrency });\nconst queue = new PQueue({ concurrency });\n\nconst task1 = () => queue.add(profiler.run(() => Promise.resolve('task1')));\nconst task2 = () => queue.add(profiler.run(() => Promise.resolve('task2')));\n\nawait Promise.all([task1(), task2()]);\nprofiler.output({ fullPath: './profile.json' });\nconsole.log('Profile written to ./profile.json');","lang":"typescript","description":"Creates a Profiler instance, wraps two async tasks with p-queue, and outputs a Chrome DevTools trace file."},"warnings":[{"fix":"Consider calling output() after all tasks complete, or use a custom stream to write asynchronously.","message":"output() writes synchronously; for large profiles it may block the event loop","severity":"gotcha","affected_versions":"<=0.2.1"},{"fix":"Create a new Profiler instance for each profiling session.","message":"Profiler instance is not reusable after output() is called unless you reset internal state manually","severity":"gotcha","affected_versions":"<=0.2.1"},{"fix":"Use p-queue or similar to control actual concurrency. The concurrency option only affects how tasks appear in the profiler timeline.","message":"The 'concurrency' option is used for trace visualization but does not limit actual execution; it's only metadata.","severity":"deprecated","affected_versions":"<=0.2.1"},{"fix":"Always pass an options object with fullPath: 'path/to/profile.json'.","message":"output() with no arguments throws a TypeError if fullPath is required but not provided","severity":"gotcha","affected_versions":"<=0.2.1"},{"fix":"Ensure the callback passed to profiler.run() returns a promise (use async or wrap in Promise.resolve()).","message":"The run() method expects the wrapped function to return a Promise; if it returns a value directly, the profiler will not track it correctly","severity":"gotcha","affected_versions":"<=0.2.1"}],"env_vars":null,"search_vec":"'analysi':82 'async':44,96 'base':66 'bottleneck':50 'browser':78 'cadenc':87 'chrome':23 'compat':26 'concurr':32,95 'debug':94 'definit':85 'develop':48 'devtool':25,79 'devtools-compat':24 'execut':46 'file':72 'flamechart':81 'function':20 'generat':22 'generic':57 'graph':41,65 'graph-bas':64 'heavi':54 'help':47 'integr':30 'javascript':9,98 'json':28 'librari':10,33 'like':34 'load':76 'low':89 'microsoft':14 'oper':97 'output':69 'p':2,5,36,40 'p-graph':39 'p-profil':1,4 'p-queue':35 'primarili':90 'profil':3,6,27,58 'promis':18,53,61 'promise-heavi':52 'promise-return':17 'queue':37,62 'releas':86 'return':19 'schedul':68 'ship':83 'stabl':12 'target':60 'task':45,67 'trace':43,71 'typescript':84,99 'unlik':56 'util':92 'v0.2.1':11 'visual':49 'workflow':55 'wrap':16","created_at":"2026-06-07T12:56:23.610220+00:00","updated_at":"2026-06-07T12:56:23.610220+00:00","problems":[{"fix":"Use default import: import Profiler from 'p-profiler' then const profiler = new Profiler(...).","cause":"Importing as named instead of default: import { Profiler } from 'p-profiler' creates a class, not instance.","error":"TypeError: profiler.output is not a function"},{"fix":"Switch to ESM (\"type\": \"module\" in package.json) or use dynamic import: const Profiler = (await import('p-profiler')).default.","cause":"Using require() in a CommonJS environment; package is ESM-only.","error":"Error: Cannot find module 'p-profiler'"},{"fix":"Call profiler.output({ fullPath: './profile.json' }).","cause":"Calling profiler.output() without options.fullPath.","error":"TypeError [ERR_INVALID_ARG_TYPE]: The \"path\" argument must be of type string. Received undefined"},{"fix":"Wrap the function body in an async function or Promise.resolve().","cause":"The wrapped function returns a non-Promise value; profiler adds metadata that expects a promise.","error":"ReferenceError: args is not defined (in profiler output JSON)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/microsoft/p-profiler#readme","github":"https://github.com/microsoft/p-profiler","docs":null,"changelog":null,"pypi":null,"npm":"p-profiler","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}