<commit_before>require 'io/console'

module Origen
  class Generator
    # Manages a single pattern sequence, i.e. an instance of PatternSequence is
    # created for every Pattern.sequence do ... end block
    class PatternSequence
      def initialize(name, block)
        @number_of_threads = 1
        @name = name
        # The contents of the main Pattern.sequence block will be executed as a thread and treated
        # like any other parallel block
        thread = PatternThread.new(:main, self, block, true)
        threads << thread
        active_threads << thread
      end

      # Execute the given pattern
      def run(pattern_name)
        pattern = Origen.generator.pattern_finder.find(pattern_name.to_s, {})
        pattern = pattern[:pattern] if pattern.is_a?(Hash)
        load pattern
      end
      alias_method :call, :run

      def in_parallel(id = nil, &block)
        @number_of_threads += 1
        id ||= "thread#{@number_of_threads}".to_sym
        # Just stage the request for now, it will be started at the end of the current execute loop
        @parallel_blocks_waiting_to_start ||= []
        @parallel_blocks_waiting_to_start << [id, block]
      end

      private

      def log_execution_profile
        if threads.size > 1
          thread_id_size = threads.map { |t| t.id.to_s.size }.max
          line_size = IO.console.winsize[1] - 35 - thread_id_size
          cycles_per_tick = (@cycle_count_stop / (line_size * 1.0)).ceil
          execution_time = Origen.app.stats.execution_time_for(Origen.app.current_job.output_pattern)
          Origen.log.info ''
          tick_time = execution_time / line_size

          Origen.log.info "Concurrent execution profile (#{pretty_time(tick_time)}/increment):"
          Origen.log.info

          number_of_ticks = @cycle_count_stop / cycles_per_tick

          ticks_per_step = 0
          step_size = 0.1.us

          while ticks_per_step < 10
            step_size = step_size * 10
            ticks_per_step = step_size / tick_time
          end

          ticks_per_step = ticks_per_step.ceil
          step_size = tick_time * ticks_per_step

          padding = ' ' * (thread_id_size + 2)<commit_msg>Log concurrent execution profile while simulating<commit_after>require 'io/console'

module Origen
  class Generator
    # Manages a single pattern sequence, i.e. an instance of PatternSequence is
    # created for every Pattern.sequence do ... end block
    class PatternSequence
      def initialize(name, block)
        @number_of_threads = 1
        @name = name
        # The contents of the main Pattern.sequence block will be executed as a thread and treated
        # like any other parallel block
        thread = PatternThread.new(:main, self, block, true)
        threads << thread
        active_threads << thread
      end

      # Execute the given pattern
      def run(pattern_name)
        pattern = Origen.generator.pattern_finder.find(pattern_name.to_s, {})
        pattern = pattern[:pattern] if pattern.is_a?(Hash)
        load pattern
      end
      alias_method :call, :run

      def in_parallel(id = nil, &block)
        @number_of_threads += 1
        id ||= "thread#{@number_of_threads}".to_sym
        # Just stage the request for now, it will be started at the end of the current execute loop
        @parallel_blocks_waiting_to_start ||= []
        @parallel_blocks_waiting_to_start << [id, block]
      end

      private

      def log_execution_profile
        if threads.size > 1
          thread_id_size = threads.map { |t| t.id.to_s.size }.max
          line_size = IO.console.winsize[1] - 35 - thread_id_size
          line_size -= 15 if tester.try(:sim?)
          cycles_per_tick = (@cycle_count_stop / (line_size * 1.0)).ceil
          if tester.try(:sim?)
            execution_time = tester.execution_time_in_ns / 1_000_000_000.0
          else
            execution_time = Origen.app.stats.execution_time_for(Origen.app.current_job.output_pattern)
          end
          Origen.log.info ''
          tick_time = execution_time / line_size

          Origen.log.info "Concurrent execution profile (#{pretty_time(tick_time)}/increment):"
          Origen.log.info

          number_of_ticks = @cycle_count_stop / cycles_per_tick

          ticks_per_step = 0
          step_size = 0.1.us

          while ticks_per_step < 10
            step_size = step_size * 10
            ticks_per_step = step_size / tick_time
          end

          ticks_per_step = ticks_per_step.ceil
          step_size = tick_time * ticks_per_step

          if tester.try(:sim?)
            padding = '.' + (' ' * (thread_id_size + 1))
          else
            padding = ' ' * (thread_id_size + 2)
          end
{'fraction_non_alphanumeric': 0.08116677235256817, 'fraction_numerical': 0.009723102938068062, 'mean_word_length': 2.23224043715847, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6258061', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1377, 'n_words': 358}