Skip to content

Commit

Permalink
Add --collapsethreads flame-graph option
Browse files Browse the repository at this point in the history
In some cases (crbug.com/1231683) multiple processes are consuming CPU
together and having a separate flame graph for each thread is not
helpful. In this case it is helpful to be able to collapse the samples
from all threads in a process together. This change does that by
removing the thread ID from the collation key and by adding a fake call
stack entry to represent the thread ID within the flame graph.
  • Loading branch information
randomascii committed Jan 7, 2022
1 parent a39a71f commit daccee6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bin/xperf_to_collapsedstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
parser.add_argument('-n', '--numshow', help='Number of top processes to generate flame graph for. Default is 1', type=int)
parser.set_defaults(numshow=1)
parser.add_argument('-d', '--dontopen', help='Do not open the generated SVG file automatically. Default is open', action='store_true')
parser.add_argument('-c', '--collapsethreads', help='Collapse all threads in a process together. Default is to keep threads separate', action='store_true')
parser.set_defaults(dontopen=False)
args = parser.parse_args()

Expand Down Expand Up @@ -140,7 +141,13 @@
stackSummary = stackSummary.replace('/', ';')
#stackSummary = 'A;B;C'

processAndThread = '%s_%s' % (process.replace(' ', '_'), threadID)
if args.collapseprocesses:
# Omit the thread ID from the collation ID and final file name.
processAndThread = '%s' % (process.replace(' ', '_'))
# Add a fake stack entry at the root that is the thread ID.
stackSummary = ('TID:%s;' % threadID) + stackSummary
else:
processAndThread = '%s_%s' % (process.replace(' ', '_'), threadID)
processAndThread = processAndThread.replace('(', '')
processAndThread = processAndThread.replace(')', '')
# Add the record to the nested dictionary, and increment the count
Expand Down

0 comments on commit daccee6

Please sign in to comment.