-
Notifications
You must be signed in to change notification settings - Fork 38
/
vim-plugins-profile.rb
executable file
·59 lines (49 loc) · 1.91 KB
/
vim-plugins-profile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
# encoding: utf-8
# Copyright 2015-2022, Hörmet Yiltiz <[email protected]>
# Released under GNU GPL version 3 or later.
# Users can pass "nvim" as a first argument to use neovim.
vim = ARGV.first || 'vim'
puts "Testing #{vim} performance..."
PLOT_WIDTH = 120
LOG = "vim-plugins-profile.#{$$}.log"
XDG_CONFIG_HOME = ENV['XDG_CONFIG_HOME'] || File.join(ENV['HOME'], '.config')
VIMFILES_DIR = vim == "nvim" ? File.join(XDG_CONFIG_HOME, 'nvim') : File.join(ENV['HOME'], '.vim')
puts "Assuming your vimfiles folder is #{VIMFILES_DIR}."
puts "Generating #{vim} startup profile..."
system(vim, '--startuptime', LOG, '-c', 'q')
# detect plugin manager
plug_dir=""
if File.directory? File.join(VIMFILES_DIR, 'plugged')
puts "vim-plug has been detected."
plug_dir="plugged"
elsif File.directory? File.join(VIMFILES_DIR, 'bundle')
puts "NeoBundle/Vundle/Pathogen has been detected."
plug_dir="bundle"
else
puts "Cannot tell your plugin-manager. Adjust this script to meet your own needs for now."
puts "Cue: `plug_dir` variable would be a good starting place."
exit 1
end
# parse
exec_times_by_name = Hash.new(0)
lines = File.readlines(LOG).select { |line| line =~ /sourcing.*#{Regexp.escape(plug_dir)}/ }
lines.each do |line|
trace_time, source_time, exec_time, _, path = line.split(' ')
relative_path = path.gsub(File.join(VIMFILES_DIR, plug_dir) + '/', '')
name = File.basename(relative_path.split('/')[0], '.vim')
time = exec_time.to_f
exec_times_by_name[name] += time
end
# plot
max = exec_times_by_name.values.max
relatives = exec_times_by_name.reduce({}) do |hash, (name, time)|
hash.merge!(name => time/max.to_f)
end
max_name_length = relatives.keys.map(&:length).max
puts
Hash[ relatives.sort_by { |k, v| -v } ].each do |name, rel_time|
time = exec_times_by_name[name]
puts "#{name.rjust(max_name_length)}: (#{time.round(3).to_s.ljust(5)}ms) #{'*' * (rel_time*PLOT_WIDTH)}"
end
File.delete(LOG)