# File lib/new_relic/agent/threading/thread_profile.rb, line 81
        def convert_N_trace_nodes_to_arrays(count_to_keep) #THREAD_LOCAL_ACCESS
          all_nodes = @traces.values.map { |n| n.flattened }.flatten

          NewRelic::Agent.instance.stats_engine.
            tl_record_supportability_metric_count("ThreadProfiler/NodeCount", all_nodes.size)

          all_nodes.sort! do |a, b|
            # we primarily prefer higher runnable_count
            comparison = b.runnable_count <=> a.runnable_count
            # we secondarily prefer lower depth
            comparison = a.depth          <=> b.depth if comparison == 0
            # it is thus impossible for any child to preceed their parent
            comparison
          end

          all_nodes.each_with_index do |n, i|
            break if i >= count_to_keep
            n.mark_for_array_conversion
          end
          all_nodes.each_with_index do |n, i|
            break if i >= count_to_keep
            n.complete_array_conversion
          end
        end