Class: XCActivityLog::IDEActivityLogSection

Inherits:
SerializedObject show all
Includes:
Enumerable
Defined in:
lib/xcactivitylog/objects.rb

Defined Under Namespace

Classes: Severity, TargetInfo

Instance Method Summary collapse

Methods inherited from SerializedObject

#==, attribute, attributes, #eql?, #hash

Instance Method Details

#duration_usecObject



106
107
108
# File 'lib/xcactivitylog/objects.rb', line 106

def duration_usec
  time_stopped_recording_usec - time_started_recording_usec
end

#each {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



92
93
94
95
96
97
# File 'lib/xcactivitylog/objects.rb', line 92

def each(&blk)
  return enum_for(__method__) unless block_given?

  yield self
  subsections&.each { |s| s.each(&blk) }
end

#each_trace_eventObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/xcactivitylog/objects.rb', line 116

def each_trace_event
  thread_id_map_by_section_type = Hash.new { |h, k| h[k] = [] }
  each_with_parent.sort_by { |s, _| s.time_started_recording }.each do |section, parent|
    thread_id_map = thread_id_map_by_section_type[section.section_type]
    best_thread, thread_id = thread_id_map.each_with_index.select do |thread, _tid|
      section.time_started_recording > thread.last.time_stopped_recording
    end.min_by do |thread, _tid|
      (section.time_started_recording - thread.last.time_stopped_recording) +
        (thread.last.time_stopped_recording - thread_id_map.map(&:last).map(&:time_stopped_recording).min)
    end
    unless thread_id
      thread_id = thread_id_map.size
      best_thread = []
      thread_id_map << best_thread
    end
    best_thread << section

    yield(section: section, parent: parent, thread_id: thread_id)
  end
end

#each_with_parent(parent: nil) {|_self, parent| ... } ⇒ Object

Yields:

  • (_self, parent)

Yield Parameters:



99
100
101
102
103
104
# File 'lib/xcactivitylog/objects.rb', line 99

def each_with_parent(parent: nil, &blk)
  return enum_for(__method__) unless block_given?

  yield self, parent
  subsections&.each { |s| s.each_with_parent(parent: self, &blk) }
end

#severityObject



170
171
172
173
# File 'lib/xcactivitylog/objects.rb', line 170

def severity
  severity = (messages || []).reduce(Severity::SUCCESS) { |a, e| [a, Severity.new(e.severity)].max }
  (subsections || []).reduce(severity) { |a, e| [a, e.severity].max }
end

#target_info(parent: nil) ⇒ Object



110
111
112
113
114
# File 'lib/xcactivitylog/objects.rb', line 110

def target_info(parent: nil)
  parent&.target_info ||
    (title =~ /=== BUILD TARGET (.+?) OF PROJECT (.+?) WITH CONFIGURATION (.+?) ===/ &&
      TargetInfo.new(name: Regexp.last_match(1), configuration: Regexp.last_match(3), workspace: Regexp.last_match(2)))
end

#write_chrome_trace_file(section_type:, to:) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/xcactivitylog/objects.rb', line 137

def write_chrome_trace_file(section_type:, to:)
  to << '{"traceEvents":[' << "\n"
  written_comma = false
  each_trace_event do |section:, parent:, thread_id:|
    case section.section_type
    when section_type
      if written_comma
        to << ",\n"
      else
        written_comma = true
      end
      require 'json'
      to << JSON.generate(
        pid: section.section_type.to_s,
        tid: thread_id,
        ts: section.time_started_recording_usec,
        ph: 'X',
        name: section.title.dup&.force_encoding('UTF-8'),
        dur: section.duration_usec,
        args: {
          subtitle: section.subtitle.dup&.force_encoding('UTF-8'),
          target: section.target_info(parent: parent).to_h,
          severity: section.severity
        }
      )
    end
  end

  to << "\n]}"

  to
end