gecko-dev/servo/components/profile
Alan Jeffrey 07258edab3 servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck
<!-- Please describe your changes on the following line: -->

This PR removes the `util` crate.

* Replaced the `spawn_named` and `clamp` functions by appropriate uses of `std:🧵:Builder::spawn`, `std::cmp::min` and `std::cmp::max`.
* Moved `opts`, `prefs` and `resource_files` into a new `config` crate.
* Moved `remutex` and `geometry` into their own crates.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because they are refactorings

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 4eb653817f87e5fb47de34356f558eb76ecbca9f

--HG--
rename : servo/components/util/Cargo.toml => servo/components/config/Cargo.toml
rename : servo/components/util/basedir.rs => servo/components/config/basedir.rs
rename : servo/components/util/lib.rs => servo/components/config/lib.rs
rename : servo/components/util/opts.rs => servo/components/config/opts.rs
rename : servo/components/util/prefs.rs => servo/components/config/prefs.rs
rename : servo/components/util/resource_files.rs => servo/components/config/resource_files.rs
rename : servo/components/util/geometry.rs => servo/components/geometry/lib.rs
rename : servo/components/util/remutex.rs => servo/components/remutex/lib.rs
rename : servo/tests/unit/util/lib.rs => servo/tests/unit/servo_config/lib.rs
rename : servo/tests/unit/util/opts.rs => servo/tests/unit/servo_config/opts.rs
rename : servo/tests/unit/util/prefs.rs => servo/tests/unit/servo_config/prefs.rs
rename : servo/tests/unit/util/remutex.rs => servo/tests/unit/servo_remutex/lib.rs
2016-12-14 16:48:42 -08:00
..
Cargo.toml servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck 2016-12-14 16:48:42 -08:00
README.md servo: Merge #7593 - Add documentation to profile crate on Heartbeats and energy-profiling (from connorimes:energy-profiling-doc); r=larsbergstrom 2015-09-10 11:29:29 -06:00
heartbeats.rs servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck 2016-12-14 16:48:42 -08:00
lib.rs servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck 2016-12-14 16:48:42 -08:00
mem.rs servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck 2016-12-14 16:48:42 -08:00
time.rs servo: Merge #14592 - Remove the util crate (from asajeffrey:util-goodbye); r=mbrubeck 2016-12-14 16:48:42 -08:00
trace-dump-epilogue-1.html servo: Merge #10694 - Add a method for dumping profiles as self-contained HTML w/ timeline visualization (from fitzgen:profile-traces-to-file); r=SimonSapin 2016-04-28 02:47:35 -07:00
trace-dump-epilogue-2.html servo: Merge #10694 - Add a method for dumping profiles as self-contained HTML w/ timeline visualization (from fitzgen:profile-traces-to-file); r=SimonSapin 2016-04-28 02:47:35 -07:00
trace-dump-prologue-1.html servo: Merge #10694 - Add a method for dumping profiles as self-contained HTML w/ timeline visualization (from fitzgen:profile-traces-to-file); r=SimonSapin 2016-04-28 02:47:35 -07:00
trace-dump-prologue-2.html servo: Merge #10694 - Add a method for dumping profiles as self-contained HTML w/ timeline visualization (from fitzgen:profile-traces-to-file); r=SimonSapin 2016-04-28 02:47:35 -07:00
trace-dump.css servo: Merge #11098 - Update `trace-dump.{js,css}` from upstream (from fitzgen:update-trace-dump); r=jdm 2016-05-10 06:34:32 -07:00
trace-dump.js servo: Merge #11098 - Update `trace-dump.{js,css}` from upstream (from fitzgen:update-trace-dump); r=jdm 2016-05-10 06:34:32 -07:00
trace_dump.rs servo: Merge #11329 - Report use statements that use {} with only one entry (from c-rhodes:11320); r=jdm 2016-05-27 07:11:17 -05:00

README.md

This crate hosts the Servo profiler. Its APIs can be found in the profile_traits crate.

Heartbeats

Heartbeats allow fine-grained timing and energy profiling of Servo tasks specified in the ProfilerCategory enum (see the profile_traits::time module). When enabled, a heartbeat is issued for each profiler category event. They also compute the average performance and power for three levels of granularity:

  • Global: the entire runtime.
  • Window: the category's last N events, where N is the size of a sliding window.
  • Instant: the category's most recent event.

Enabling

Heartbeats are enabled for categories by setting proper environment variables prior to launching Servo.

For each desired category, set the SERVO_HEARTBEAT_ENABLE_MyCategory environment variable to any value (an empty string will do) where MyCategory is the ProfilerCategory name exactly as it appears in the enum. For example:

SERVO_HEARTBEAT_ENABLE_LayoutPerform=""

Then set the SERVO_HEARTBEAT_LOG_MyCategory environment variable so Servo knows where to write the results. For example:

SERVO_HEARTBEAT_LOG_LayoutPerform="/tmp/heartbeat-LayoutPerform.log"

The target directory must already exist and be writeable. Results are written to the log file every N heartbeats and when the profiler shuts down.

You can optionally specify the size of the sliding window by setting SERVO_HEARTBEAT_WINDOW_MyCategory to a positive integer value. The default value is 20. For example:

SERVO_HEARTBEAT_WINDOW_LayoutPerform=20

The window size is also how many heartbeats will be stored in memory.

Log Files

Log files are whitespace-delimited.

HB is the heartbeat number, ordered by when they are registered (not necessarily start or end time!). The count starts at 0.

Tag is a client-specified identifier for each heartbeat. Servo does not use this, so the value is always 0.

Work is the amount of work completed for a particular heartbeat and is used in computing performance. At this time, Servo simply specifies 1 unit of work for each heartbeat.

Time and Energy have Start and End values as captured during runtime. Time is measured in nanoseconds and energy is measured in microjoules.

Work, Time, and Energy also have Global and Window values which are the summed over the entire runtime and sliding window period, respectively.

Perf (performance) and Pwr (power) have Global, Window, and Instant values as described above.

Energy Profiling

Energy monitoring is hardware and platform-specific, so it is only enabled with the energy-profiling feature.

To use energy profiling, you must have a compatible energymon-default implementation installed to your system as energymon-default-static when building Servo. Otherwise a default dummy implementation is used. The library is linked through a chain of dependencies:

  • servo::profile_traits
    • energymon - Rust abstractions
      • energymon-default-sys - Rust bindings to energymon-default.h
        • energymon-default-static: A statically linked C library installed to the system that implements energymon.h and energymon-default.h

For instructions on building existing native libraries, visit the energymon project source. You may also write your own implementation of energymon.h and energymon-default.h and install it as energymon-default-static where pkg-config can find it.

Once you install the proper library, you will need to rebuild the energymon-default-sys crate. The most straightforward way to do this is to do a clean build of Servo.

To build Servo with the energy-profiling feature enabled, pass --features "energy-profiling" to the mach command, e.g.:

./mach build -r --features "energy-profiling"

When running Servo, you will want to enable the desired Heartbeats to record the results.