libreoffice-online/scripts/profile-cool
Caolán McNamara 1425b36104 merge background saves together in profile
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I016133f31f34b859dcb21b794406c7e6a1559aa9
2024-05-02 14:02:56 +02:00

54 lines
2.5 KiB
Bash
Executable file

#! /bin/bash
#
# get a flamegraph of an online session
# a) sends SIGUSR1 to get kitbrokers to dump info to logs
# b) scans likely logs for that info and scrapes out the
# document, users and pids
# c) prompts for which pid to profile
# d) profiles, then generates flamegraph on ctrl+c
if ! test `id -u` = 0; then
echo "not root, if this doesn't work try sudo profile-cool"
fi
if ! which flamegraph.pl > /dev/null 2>&1; then
REAL_USER_HOME="$(getent passwd $SUDO_USER | cut -d: -f6)"
PATH=$PATH:$HOME/FlameGraph:$REAL_USER_HOME/FlameGraph
fi
if ! which flamegraph.pl > /dev/null 2>&1; then
echo "no flamegraph.pl found"
echo "On fedora install systemwide with: sudo dnf install flamegraph"
echo "Otherwise install locally manually into ~/FlameGraph"
echo " e.g. git clone https://github.com/brendangregg/FlameGraph ~/FlameGraph"
exit 1
fi
# a deployment will log to journal, take current time to grep logs from that time point
date=`date +%s`
# a local dev build dumps to /tmp/coolwsd.log by default, take current size to grep from that size point
if [ -e /tmp/coolwsd.log ]; then
locallogsize=`du -b /tmp/coolwsd.log|cut -f1`
fi
echo using pkill -SIGUSR1 kitbroker to dump info
pkill -SIGUSR1 kitbroker
echo Waiting 1 second for results
sleep 1
echo ---systemd journal---
# We might have multiple coolwsds and we want the output from all of them.
# But we want lines from each pid to be grouped together, and each group
# of lines to be in chronological order.
# So use short-unix to retain the name[pid], stable sort on that key
# then use cut to remove the columns we only included to get the desired
# order
journalctl --since @$date -t "coolwsd" -o short-unix | sort -s -k3,3 | cut -d " " -f 4- | grep -P "\Wpid:|\WjailedUrl:|\WviewId:.*userExtraInfo:"
if [ -e /tmp/coolwsd.log ]; then
echo ---local dev log---
tail -c +$locallogsize /tmp/coolwsd.log | grep -P "\Wpid:|\WjailedUrl:|\WviewId:.*userExtraInfo:"
fi
echo -n "enter pid to measure performance of: "
read kitpid
echo now running perf to record performance data, press ctrl+c when ready to generate output
trap ' ' INT
# note a) perf version 6.4.4 doesn't unmangle c++ names correctly for me, while 6.2.6 does
perf record -F50 --call-graph dwarf,65528 --pid $kitpid
# note b) perf version 5.14.21 is agonizingly slow without --no-inline, while 6.2.6 seems ok
# merge all the background saves together as kitdbgsv
perf script --no-inline | stackcollapse-perf.pl | sed -E -s "s/^kitbgsv[^;]+/kitbgsv/" | flamegraph.pl > perf-$kitpid.svg
echo generated flamegraph output svg: perf-$kitpid.svg