This package makes it easy to record proper sampling CPU profiles of Meteor on the server. You can open the profile in Chrome for detailed analysis. A CPU profile looks like this in Chrome:
This package supports profiling both the Meteor build process and the Meteor server process.
$ meteor add qualia:profile
There are two uses of
qualia:profile. The first is for profiling Meteor build and reload performance. The second is for profiling Meteor runtime performance.
To enable profiling Meteor builds, just run you application with the environment variable
QUALIA_PROFILE_FOLDER set to the folder where you'd like the CPU profiles to be saved. For example, you might start your application like:
Once this environment variable is set, four different kinds of profiles will be saved to that folder.
initial-build.cpuprofileprofiles the build process the very first time it is run.
full-rebuild.cpuprofileprofiles the build process when at least one server-side file has changed.
client-rebuild.cpuprofileprofiles the build process when only client-side files have changed. Meteor has a fast track for this scenario.
startup.cpuprofileprofiles the server process as it boots up.
When trying to figure out why your app takes so long to build/rebuild, it is important to look at all 4 of these different profiles. You should also play around with which files you are using to trigger reloads. Meteor packages rebuild somewhat independently.
To profile the Meteor server at runtime, open the Meteor shell and run the following commands:
import Profiler from "meteor/qualia:profile"; let profileName = 'myprofile'; let profilePath = '/path/to/profiles/myprofile.cpuprofile'; let profileMS = 10000; Profiler.profileDuration(profileName, profilePath, profileMS);
This will profile your code for ten seconds and save the profile to
You can call
Profiler.profileDuration from anywhere in your code, but it is often convenient to call it from the Meteor shell. If you enable the Meteor shell in prod, you can profile live production code.
*.cpuprofile files. You can now navigate between your uploaded CPU profiles by using the sidebar on the left hand side.
For guidance on how to interpret these profiles, this tutorial is a good first step.