Class: Vernier::Output::Firefox::Categorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/output/firefox.rb

Defined Under Namespace

Classes: Category

Constant Summary collapse

RAILS_COMPONENTS =
%w[ activesupport activemodel activerecord actionview
actionpack activejob actionmailer actioncable
activestorage actionmailbox actiontext railties ]
AVAILABLE_COLORS =
%w[ transparent purple green orange yellow lightblue
blue brown magenta red lightred darkgrey grey ]
ORDERED_CATEGORIES =

This is in the order of preference

%w[ Kernel Rails gem Ruby ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCategorizer

Returns a new instance of Categorizer.



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
60
61
62
63
64
65
66
67
68
# File 'lib/vernier/output/firefox.rb', line 26

def initialize
  @categories = []
  @categories_by_name = {}

  add_category(name: "Kernel", color: "magenta") do |c|
    c.add_subcategory(
      name: "Kernel",
      matcher: starts_with("<internal")
    )
  end

  add_category(name: "gem", color: "lightblue") do |c|
    c.add_subcategory(
      name: "gem",
      matcher: starts_with(*Gem.path)
    )
  end

  add_category(name: "Rails", color: "red") do |c|
    RAILS_COMPONENTS.each do |subcategory|
      c.add_subcategory(
        name: subcategory,
        matcher: gem_path(subcategory)
      )
    end
  end

  add_category(name: "Ruby", color: "purple") do |c|
    c.add_subcategory(
      name: "stdlib",
      matcher: starts_with(RbConfig::CONFIG["rubylibdir"])
    )
  end

  add_category(name: "Idle", color: "transparent")
  add_category(name: "Stalled", color: "transparent")

  add_category(name: "GC", color: "red")

  add_category(name: "cfunc", color: "yellow", matcher: "<cfunc>")

  add_category(name: "Thread", color: "grey")
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



24
25
26
# File 'lib/vernier/output/firefox.rb', line 24

def categories
  @categories
end

Instance Method Details

#add_category(name:, **kw) {|category| ... } ⇒ Object

Yields:

  • (category)


70
71
72
73
74
75
76
77
# File 'lib/vernier/output/firefox.rb', line 70

def add_category(name:, **kw)
  category = Category.new(@categories.length, name: name, **kw)
  @categories << category
  @categories_by_name[name] = category
  category.add_subcategory(name: "Other")
  yield category if block_given?
  category
end

#categorize(path) ⇒ Object



91
92
93
# File 'lib/vernier/output/firefox.rb', line 91

def categorize(path)
  @categories.detect { |category| category.matches?(path) } || @categories.first
end

#gem_path(*names) ⇒ Object



87
88
89
# File 'lib/vernier/output/firefox.rb', line 87

def gem_path(*names)
  %r{\A#{Regexp.union(Gem.path)}/gems/#{Regexp.union(names)}}
end

#get_category(name) ⇒ Object



79
80
81
# File 'lib/vernier/output/firefox.rb', line 79

def get_category(name)
  @categories_by_name[name]
end

#starts_with(*paths) ⇒ Object



83
84
85
# File 'lib/vernier/output/firefox.rb', line 83

def starts_with(*paths)
  %r{\A#{Regexp.union(paths)}}
end