mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Switch to flamegraph-rs script
This cleans up the Alacritty scripts a bit by removing some of them which are not recommended to be used anymore and switching from the official FlameGraph tool to the more specialized Rust FlameGraph implementation.
This commit is contained in:
parent
4cc6421daa
commit
0f15dc05d9
4 changed files with 23 additions and 175 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,6 +1,3 @@
|
|||
# FlameGraph script
|
||||
FlameGraph
|
||||
|
||||
# Rust build directory
|
||||
**/target
|
||||
|
||||
|
@ -33,3 +30,7 @@ alacritty_*_source.tar.bz2
|
|||
*.msi
|
||||
*.wixobj
|
||||
*.wixpdb
|
||||
|
||||
# Perf tools
|
||||
perf.data*
|
||||
flamegraph.svg
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import collections
|
||||
import logging
|
||||
import shutil
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
|
||||
ALACONF_FN = os.path.join(XDG_CONFIG_HOME, 'alacritty', 'alacritty.yml')
|
||||
|
||||
Palette = collections.namedtuple('Pallete', ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'])
|
||||
|
||||
|
||||
class AttrDict(dict):
|
||||
"""
|
||||
>>> m = AttrDict(omg=True, whoa='yes')
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AttrDict, self).__init__(*args, **kwargs)
|
||||
self.__dict__ = self
|
||||
|
||||
|
||||
def slurp_yaml(fn):
|
||||
with open(fn, 'r') as fh:
|
||||
# JSON is a subset of YAML.
|
||||
contents = yaml.load(fh)
|
||||
return contents
|
||||
|
||||
|
||||
def fixup_hex_color(*args):
|
||||
for arg in args:
|
||||
val = '0x%s' % arg.strip('#')
|
||||
yield val
|
||||
|
||||
|
||||
def convert(tilix_scheme):
|
||||
j = AttrDict(tilix_scheme)
|
||||
palette = list(fixup_hex_color(*j.palette))
|
||||
|
||||
pal_normal = Palette(*palette[:8])
|
||||
pal_bold = Palette(*palette[8:])
|
||||
|
||||
colors = {
|
||||
'primary': dict(zip(
|
||||
['background', 'foreground'],
|
||||
fixup_hex_color(j['background-color'], j['foreground-color']),
|
||||
)),
|
||||
'cursor': dict(zip(
|
||||
['text', 'cursor'],
|
||||
fixup_hex_color(j['cursor-background-color'], j['cursor-foreground-color']),
|
||||
)),
|
||||
'normal': dict(pal_normal._asdict()),
|
||||
'bright': dict(pal_bold._asdict()),
|
||||
}
|
||||
|
||||
return colors
|
||||
|
||||
|
||||
def patch_alaconf_colors(colors, alaconf_fn=ALACONF_FN):
|
||||
with open(alaconf_fn, 'r') as fh:
|
||||
ac_raw = fh.read()
|
||||
|
||||
# Write config file taking care to not remove delicious comments.
|
||||
# Sure, it's janky, but less so than losing comments.
|
||||
skipping = False
|
||||
lines = []
|
||||
for line in ac_raw.splitlines():
|
||||
if skipping:
|
||||
if line and line[0].isalpha():
|
||||
skipping = False
|
||||
|
||||
elif line.startswith('colors:'):
|
||||
skipping = True
|
||||
|
||||
if not skipping:
|
||||
if not line and lines and not lines[-1]:
|
||||
continue
|
||||
lines.append(line)
|
||||
|
||||
temp_fn = '%s.tmp' % alaconf_fn
|
||||
backup_fn = '%s.bak' % alaconf_fn
|
||||
|
||||
with open(temp_fn, 'w') as fh:
|
||||
fh.write('\n'.join(lines))
|
||||
fh.write('\n')
|
||||
yaml.safe_dump(dict(colors=colors), fh)
|
||||
|
||||
shutil.copyfile(alaconf_fn, backup_fn)
|
||||
os.rename(temp_fn, alaconf_fn)
|
||||
|
||||
|
||||
def main(argv=sys.argv):
|
||||
if len(argv) != 2:
|
||||
print("Usage: %s TILIX_SCHEME_JSON_FILE" % sys.executable, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
fn = argv[1]
|
||||
|
||||
tilix_scheme = slurp_yaml(fn)
|
||||
colors = convert(tilix_scheme)
|
||||
patch_alaconf_colors(colors)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -3,36 +3,29 @@
|
|||
# The full path to the script directory, regardless of pwd.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
# Current UNIX time.
|
||||
TIME=$(date +%s)
|
||||
|
||||
# Make sure FlameGraph scripts are available.
|
||||
if [ ! -e $DIR/FlameGraph ]
|
||||
then
|
||||
git clone https://github.com/BrendanGregg/FlameGraph \
|
||||
$DIR/create-flamegraph/FlameGraph
|
||||
fi
|
||||
|
||||
# Make sure a release build of Alacritty is available.
|
||||
if [ ! -e $DIR/../target/release/alacritty ]
|
||||
then
|
||||
echo "Must build alacritty first: cargo build --release"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure perf is available.
|
||||
if [ ! -x "$(command -v perf)" ]
|
||||
then
|
||||
echo "Cannot find perf, please make sure it's installed"
|
||||
echo "Cannot find perf, please make sure it's installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run perf, this will block while alacritty runs.
|
||||
perf record -g -F 99 $DIR/../target/release/alacritty
|
||||
perf script \
|
||||
| $DIR/create-flamegraph/FlameGraph/stackcollapse-perf.pl \
|
||||
| $DIR/create-flamegraph/FlameGraph/flamegraph.pl --width 1920 \
|
||||
> flame-$TIME.svg
|
||||
# Install cargo-flamegraph
|
||||
installed_flamegraph=0
|
||||
if [ ! -x "$(command -v cargo-flamegraph)" ]; then
|
||||
echo "cargo-flamegraph not installed; installing ..."
|
||||
cargo install flamegraph
|
||||
installed_flamegraph=1
|
||||
fi
|
||||
|
||||
# Tell users where the file is.
|
||||
echo "Flame graph created at: file://$(pwd)/flame-$TIME.svg"
|
||||
# Create flamegraph
|
||||
cargo flamegraph --bin=alacritty -- $@
|
||||
|
||||
# Unintall cargo-flamegraph if it has been installed with this script
|
||||
if [ $installed_flamegraph == 1 ]; then
|
||||
read -p "Would you like to uninstall cargo-flamegraph? [Y/n] " -n 1 -r
|
||||
echo
|
||||
if [[ "$REPLY" =~ ^[^Nn]*$ ]]; then
|
||||
cargo uninstall flamegraph
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'json'
|
||||
|
||||
Dir.glob('./tests/ref/**/grid.json').each do |path|
|
||||
puts "Migrating #{path}"
|
||||
|
||||
# Read contents
|
||||
s = File.open(path) { |f| f.read }
|
||||
|
||||
# Parse
|
||||
grid = JSON.parse(s)
|
||||
|
||||
# Normalize Storage serialization
|
||||
if grid['raw'].is_a? Array
|
||||
grid['raw'] = {
|
||||
'inner' => grid['raw'][0],
|
||||
'zero' => grid['raw'][1],
|
||||
'visible_lines' => grid['raw'][2]
|
||||
}
|
||||
end
|
||||
|
||||
# Migrate Row serialization
|
||||
grid['raw']['inner'].map! do |row|
|
||||
if row.is_a? Hash
|
||||
row
|
||||
else
|
||||
{ inner: row, occ: row.length }
|
||||
end
|
||||
end
|
||||
|
||||
# Write updated grid
|
||||
File.open(path, 'w') { |f| f << JSON.generate(grid) }
|
||||
end
|
Loading…
Reference in a new issue