• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This script profiles the execution of a process and all its children.
6 // Execute like this:
7 //   sudo dtrace -s profile.d $(pgrep -x "Google Chrome")
8 
9 // Note on results produced:
10 //
11 // This script will produce a data file suitable to be converted to a pprof by
12 // export_dtrace.py. The flamegraph generated will present time spent on-cpu as
13 // a fraction of the total. More time spent on-cpu does not necessarily mean
14 // more power consumed. A CPU running at a low frequency will take a long time
15 // to execute work but might do it in a more power-efficient way than if it was
16 // running at a higher frequency. The same can be said about core selection in
17 // a big.LITTLE style architecture.
18 
19 // Profile with a high frequency that is prime to avoid unfortunate alignement
20 // with periods of repeating tasks internal to the process. The frequency was
21 // verified as supported by macOS Monterey running on Intel. See
22 // illumos.org/books/dtrace/chp-profile.html#chp-profile-5 for details.
23 profile-997/(pid == $1 || ppid == $1)/
24 {
25   @[ustack(512)] = count();
26 }
27 
28 // Future work:
29 // Currently the frequency data is not filled in within the |curcpu| variable
30 // on macOS. The |cpu| variable is correctly filled in so applying some notion
31 // of per-core type weight will be integrated into this script eventually.