|
| 1 | +# Profiling LibSass |
| 2 | + |
| 3 | +## Linux perf and pprof |
| 4 | + |
| 5 | +On Linux, you can record the profile with `perf` and inspect it with `pprof`. |
| 6 | + |
| 7 | +### Install required tools |
| 8 | + |
| 9 | +Pre-requisites: |
| 10 | + |
| 11 | +1. Linux `perf`, commonly found in the `linux-tools-generic` package. |
| 12 | +2. [go], for installing `pprof`. |
| 13 | +3. [bazel], for installing `perf_to_profile`. |
| 14 | + |
| 15 | +[go]: https://golang.org |
| 16 | +[bazel]: https://bazel.build |
| 17 | + |
| 18 | +First, install `pprof` with: |
| 19 | + |
| 20 | +```bash |
| 21 | +go get -u github.com/google/pprof |
| 22 | +``` |
| 23 | + |
| 24 | +Then, build and install `perf_to_profile`: |
| 25 | + |
| 26 | +```bash |
| 27 | +git clone https://github.com/google/perf_data_converter |
| 28 | +cd perf_data_converter |
| 29 | +bazel build -c opt src:perf_to_profile |
| 30 | +sudo cp bazel-bin/src/perf_to_profile /usr/local/bin/ |
| 31 | +``` |
| 32 | + |
| 33 | +Finally, in your libsass repository, clone and build `sassc`: |
| 34 | + |
| 35 | +```bash |
| 36 | +git clone https://github.com/sass/sassc.git |
| 37 | +make sassc |
| 38 | +``` |
| 39 | + |
| 40 | +### Record perf data |
| 41 | + |
| 42 | +```bash |
| 43 | +sudo perf record sassc/bin/sassc input.scss > /dev/null && sudo chown $USER:$USER perf.data |
| 44 | +``` |
| 45 | + |
| 46 | +This will create a `perf.data` file that you can vizualize with `pprof`. |
| 47 | + |
| 48 | +### Inspect perf data |
| 49 | + |
| 50 | +A web server with various visualization options: |
| 51 | + |
| 52 | +```bash |
| 53 | +pprof -http=localhost:3232 sassc/bin/sassc perf.data |
| 54 | +``` |
| 55 | + |
| 56 | +Simple text output: |
| 57 | + |
| 58 | +```bash |
| 59 | +pprof -text sassc/bin/sassc perf.data |
| 60 | +``` |
| 61 | + |
| 62 | +Example output: |
| 63 | + |
| 64 | +``` |
| 65 | + flat flat% sum% cum cum% |
| 66 | + 24651348 6.97% 6.97% 24651348 6.97% [[kernel.kallsyms]] |
| 67 | + 20746241 5.87% 12.84% 20746241 5.87% Sass::SharedPtr::decRefCount |
| 68 | + 18401663 5.20% 18.04% 20420896 5.78% __libc_malloc |
| 69 | + 15205959 4.30% 22.34% 15205959 4.30% [libc-2.27.so] |
| 70 | + 12974307 3.67% 26.01% 14070189 3.98% _int_malloc |
| 71 | + 10958857 3.10% 29.11% 10958857 3.10% Sass::SharedPtr::incRefCount |
| 72 | + 9837672 2.78% 31.89% 18433250 5.21% cfree |
| 73 | +``` |
0 commit comments