Firefox Profiler (https://profiler.firefox.com/) visualizes performance profiles, primarily from the Gecko Profiler built into Firefox. It has two frontends: a client-side React + Redux + TypeScript web app and profiler-cli (aliased as pq) for querying profiles from the terminal. Both share the profile logic in src/profile-logic/, so put profile computations there instead of duplicating them in either frontend.
Use the Node version from .nvmrc. Always go through yarn scripts. The test scripts set LC_ALL=C TZ=UTC NODE_ENV=test, so calling jest directly produces different results.
yarn start- production build on port 4242 (service worker disabled).yarn start-devfor a development build on 4241. Override withFX_PROFILER_PORT.yarn build/yarn build-prod- build intodist/.yarn serve-staticservesdist/on port 4243.yarn ts- type checkyarn lint/yarn lint-fix- oxlint, Stylelint and oxfmt. Runyarn lint-fixafter every change.yarn test [path] [-t "name"]- Jest, browser project only (allsrc/**/*.test.*). Add-uto update snapshots.yarn test-cli- builds profiler-cli, then runs its unit and integration tests (profiler-cli/src/test/)yarn test-all- everything above plus a few extra checks. Runs on pre-push.
src/actions,src/reducers,src/selectors- Redux with redux-thunk and reselect.src/app-logic- store creation, URL state (url-handling.ts), constants, WebChannel, IndexedDB storagesrc/components/<feature>- React components with co-located plain CSS files (not CSS Modules). Shared UI incomponents/shared.src/profile-logic- profile processing (process-profile.ts), transforms (transforms.ts), symbolication, source maps, upgraderssrc/profile-logic/import- non-Gecko importers: Chrome, Linux perf, simpleperf, ART trace, DHAT, flame graph textsrc/profile-query- query library used by profiler-clisrc/types- shared type definitions,src/utils- generic helperssrc/test/{unit,components,store,integration}- tests. Fixtures and profile builders insrc/test/fixtures, custom matchers insrc/test/fixtures/custom-assertions.ts.docs-developer/- architecture, profile formats, symbolication, markers. Read the relevant doc before changing those areas.
Import aliases: firefox-profiler -> src/, firefox-profiler-res -> res/.
- Performance is very important. Profiles can exceed 100MB, and sample, stack, frame and marker tables can have millions of rows. Prefer typed arrays and column-oriented tables, and avoid per-sample allocations.
- The profile format is documented in
src/types/{profile,profile-derived,gecko-profile}.ts. Read them before making assumptions about profile structure. - The stack, frame, func, resource, native symbol and source tables and the string array live in
profile.sharedand are shared across all threads. Samples, markers and allocations are per thread. - Put derived data in memoized Redux selectors instead of components, so it's computed once and doesn't cause extra rerenders. Per-thread selectors come from
getThreadSelectors()insrc/selectors/per-thread/index.ts, which caches a selector set per thread, because a selector that takes a thread index as an argument breaks memoization. - Changing the Gecko or processed profile format requires bumping
GECKO_PROFILE_VERSION/PROCESSED_PROFILE_VERSIONinsrc/app-logic/constants.ts, adding an upgrader ingecko-profile-versioning.ts/processed-profile-versioning.ts, and documenting it indocs-developer/CHANGELOG-formats.md. Seedocs-developer/upgrading-profiles.mdfor the process. - Profile upgraders must never change once deployed. Don't import helpers from
profile-logicor elsewhere into an upgrader, because those helpers can change later. Inline the logic instead.
- Import from
firefox-profiler/...instead of relative../../paths. Import shared types fromfirefox-profiler/types. - When branching on a union type or enum, prefer a
switchwith athrow assertExhaustiveCheck(..)default branch. PreferensureExists(x, msg)over non-null assertions. Both live insrc/utils/types.ts. - Avoid
Pick<>andOmit<>. Prefer a named type that says what the subset is for. - Index types should have semantic names like
IndexIntoCallNodeTable, not plainnumber. - Don't create a new file for a single small function unless it's a logically separate module.
- Anything that should survive a reload or be shareable belongs in URL state, and shape changes need a
CURRENT_URL_VERSIONbump plus an upgrader insrc/app-logic/url-handling.ts. - Test behavior, not implementation details. Don't add unit tests that just restate the code.
- Build test profiles with
getProfileFromTextSamples()fromsrc/test/fixtures/profiles/processed-profile.tsinstead of writing them by hand. Store tests create a store withstoreWithProfile()fromsrc/test/fixtures/stores.ts, dispatch actions and assert on selectors. Component tests use React Testing Library throughsrc/test/fixtures/testing-library.tsx. - Timeline, flame graph and stack chart render to canvas, so component tests assert on draw calls or snapshots rather than DOM text.
User-facing strings go through Fluent (<Localized> or localize()). Only edit locales/en-US/app.ftl. Other locales come from Pontoon. IDs follow ComponentName--string-summary.
- When the meaning of a string that is already on
mainchanges, including what one of its variables means, or when an attribute (like.title) is added or removed, rename its key so the change is picked up. Strings that only exist on your branch can be edited in place. - Localizers see one string at a time in Pontoon, so every comment must make sense on its own. Never write "same as the previous string" or "see above".
- Document every variable under a
# Variables:line as# $name (Type) - meaning. A variable name must mean the same thing in every string of a group. - Don't comment strings that are already clear. Add a comment when a short string doesn't tell where it's shown or what it refers to.
- Translations can be much longer than English. Let text wrap, or in single-line controls like tabs, truncate or scroll.
Keep comments to a strict minimum. Comment only non-trivial code, functions whose arguments aren't self-explanatory, and type definitions and their members. Don't remove existing comments unless they relate to what you are changing.
Gecko is the ground truth for the profile format, marker schemas, thread structure, symbolication and WebChannel behavior. Never assume how Gecko behaves. Check the Firefox source with searchfox-cli instead of guessing, and suggest installing it if it's missing. Most relevant code lives under tools/profiler/ in mozilla-central, but it might be anywhere (especially for markers).
searchfox-cli -q ProfileBufferEntry # Text/symbol search
searchfox-cli -q StackFrame -p ^tools/profiler # Restrict to a path prefix
searchfox-cli --define 'ProfileBuffer::AddEntry' # Full definition
searchfox-cli --get-file tools/profiler/core/platform.cpp --lines 100-200Useful flags: -R mozilla-beta|mozilla-release, --exclude-tests, --exclude-generated, and --permalink for commit-pinned links when citing sources. See searchfox-cli --help for more.
profiler-cli/ is a CLI for querying profiles from the terminal. A daemon keeps the profile in memory and short-lived clients talk to it over Unix domain sockets. Query logic belongs in src/profile-query/. The daemon only routes requests. pq is an alias, so treat any mention of pq as profiler-cli. Start a session with pq load <PATH|URL> and run pq guide for the full command set.
To run it from source, build with yarn build-cli and run profiler-cli/dist/profiler-cli.js. Set PROFILER_CLI_SESSION_DIR=.profiler-cli-dev to keep dev sessions separate from an installed pq.
profiler-cli/README.md covers usage and sessions. profiler-cli/CONTRIBUTING.md covers the architecture, IPC protocol and how to add commands.
profiler-cli/guide.txt (shown by pq guide) is read by agents, so every word costs context. Keep it minimal and leave out anything that isn't needed.