libreoffice-online/scripts/profile-cool
Caolán McNamara 7999601398 add info to profiling script how to install dependencies
and how to sudo it, and tweak PATH to use the suggested info
automatically when sudoed

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I977f04bd38ad76393203c06d21f4a27abd0705ef
2024-01-31 10:10:42 +00:00

48 lines
2.1 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---
journalctl --since @$date -u coolwsd --output=cat | 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
perf script --no-inline | stackcollapse-perf.pl > perf-$kitpid.log
flamegraph.pl perf-$kitpid.log > perf-$kitpid.svg
echo generated flamegraph output svg: perf-$kitpid.svg