Ejemplo n.º 1
0
    def check_and_prepare(self, experiment_dir: str,
                          target_config: TargetConfiguration,
                          instr_config: InstrumentConfig) -> str:
        cur_ep_dir = self.get_extrap_dir_name(
            target_config, instr_config.get_instrumentation_iteration())
        if not u.is_valid_file_name(cur_ep_dir):
            log.get_logger().log(
                'ExtrapProfileSink::check_and_prepare: Generated directory name no good. Abort\n'
                + cur_ep_dir,
                level='error')
        else:
            if u.check_provided_directory(cur_ep_dir):
                new_dir_name = cur_ep_dir + '_' + u.generate_random_string()
                log.get_logger().log(
                    'ExtrapProfileSink::check_and_prepare: Moving old experiment directory to: '
                    + new_dir_name,
                    level='info')
                u.rename(cur_ep_dir, new_dir_name)

            u.create_directory(cur_ep_dir)
            cubex_name = experiment_dir + '/' + target_config.get_flavor(
            ) + '-' + target_config.get_target() + '.cubex'
            log.get_logger().log(cubex_name)

            if not u.is_file(cubex_name):
                log.get_logger().log(
                    'ExtrapProfileSink::check_and_prepare: Returned experiment cube name is no file: '
                    + cubex_name)
            else:
                return cubex_name

        raise ProfileSinkException(
            'ExtrapProfileSink: Could not create target directory or Cube dir bad.'
        )
Ejemplo n.º 2
0
    def set_up(self, target_config: TargetConfiguration,
               instrumentation_config: InstrumentConfig,
               compile_time_filter: bool) -> None:
        if not target_config.is_compile_time_filtering():
            scorep_filter_file = self.prepare_scorep_filter_file(
                target_config.get_instr_file())
            self.set_filter_file(scorep_filter_file)

        self._set_up(target_config.get_build(), target_config.get_target(),
                     target_config.get_flavor(),
                     instrumentation_config.get_instrumentation_iteration(),
                     instrumentation_config.is_instrumentation_run())
Ejemplo n.º 3
0
    def run(self, target_config: TargetConfiguration,
            instrument_config: InstrumentConfig,
            compile_time_filtering: bool) -> float:
        """ Implements the actual invocation """
        functor_manager = fm.FunctorManager()
        run_functor = functor_manager.get_or_load_functor(
            target_config.get_build(), target_config.get_target(),
            target_config.get_flavor(), 'run')
        default_provider = defaults.BackendDefaults()
        kwargs = default_provider.get_default_kwargs()
        kwargs['util'] = util
        kwargs['LD_PRELOAD'] = default_provider.get_MPI_wrap_LD_PRELOAD()
        runtime = .0

        if run_functor.get_method()['active']:
            run_functor.active(target_config.get_target(), **kwargs)
            log.get_logger().log(
                'For the active functor we can barely measure runtime',
                level='warn')
            runtime = 1.0

        try:
            util.change_cwd(target_config.get_place())

            invoke_arguments = target_config.get_args_for_invocation()
            kwargs['args'] = invoke_arguments
            if invoke_arguments is not None:
                log.get_logger().log('LocalBaseRunner::run: (args) ' +
                                     str(invoke_arguments))

            command = run_functor.passive(target_config.get_target(), **kwargs)
            _, runtime = util.shell(command, time_invoc=True)
            log.get_logger().log(
                'LocalBaseRunner::run::passive_invocation -> Returned runtime: '
                + str(runtime),
                level='debug')

        except Exception as e:
            log.get_logger().log('LocalBaseRunner::run Exception\n' + str(e),
                                 level='error')
            raise RuntimeError('LocalBaseRunner::run caught exception. ' +
                               str(e))

        # TODO: Insert the data into the database
        return runtime
Ejemplo n.º 4
0
def execute_with_config(runner: Runner, analyzer: A, pira_iters: int,
                        target_config: TargetConfiguration,
                        csv_config: CSVConfiguration) -> None:
    try:
        instrument = False
        pira_iterations = pira_iters
        hybrid_filtering = target_config.is_hybrid_filtering()
        compile_time_filtering = target_config.is_compile_time_filtering()
        hybrid_filter_iters = target_config.get_hybrid_filter_iters()

        rr_exporter = E.RunResultExporter()

        # Build without any instrumentation
        L.get_logger().log(
            'Building vanilla version for baseline measurements', level='info')
        vanilla_builder = BU(target_config, instrument)
        tracker = T.TimeTracker()
        tracker.m_track('Vanilla Build', vanilla_builder, 'build')

        # Run without instrumentation for baseline
        L.get_logger().log('Running baseline measurements', level='info')
        vanilla_rr = runner.do_baseline_run(target_config)
        L.get_logger().log('Pira::execute_with_config: RunResult: ' +
                           str(vanilla_rr) + ' | avg: ' +
                           str(vanilla_rr.get_average()),
                           level='debug')
        instr_file = ''

        if (csv_config.should_export()):
            rr_exporter.add_row('Vanilla', vanilla_rr)

        for x in range(0, pira_iterations):
            L.get_logger().log('Running instrumentation iteration ' + str(x),
                               level='info')

            # Only run the pgoe to get the functions name
            iteration_tracker = T.TimeTracker()

            # Analysis Phase
            instr_file = analyzer.analyze(target_config, x)
            L.get_logger().log('[WHITELIST] $' + str(x) + '$ ' +
                               str(U.lines_in_file(instr_file)),
                               level='perf')
            U.shell('stat ' + instr_file)

            # After baseline measurement is complete, do the instrumented build/run
            # This is only necessary in every iteration when run in compile-time mode.
            # For hybrid-filtering this is done after the specified amount of iterations
            if (hybrid_filtering and (x % hybrid_filter_iters is 0)
                ) or x is 0 or compile_time_filtering:
                instrument = True
                instr_builder = BU(target_config, instrument, instr_file)
                tracker.m_track('Instrument Build', instr_builder, 'build')

            #Run Phase
            L.get_logger().log('Running profiling measurements', level='info')
            instr_rr = runner.do_profile_run(target_config, x)

            if (csv_config.should_export()):
                rr_exporter.add_row('Instrumented ' + str(x), instr_rr)

            # Compute overhead of instrumentation
            ovh_percentage = instr_rr.compute_overhead(vanilla_rr)
            L.get_logger().log('[RUNTIME] $' + str(x) + '$ ' +
                               str(instr_rr.get_average()),
                               level='perf')
            L.get_logger().log('[OVERHEAD] $' + str(x) + '$ ' +
                               str(ovh_percentage),
                               level='perf')

            iteration_tracker.stop()
            user_time, system_time = iteration_tracker.get_time()
            L.get_logger().log('[ITERTIME] $' + str(x) + '$ ' +
                               str(user_time) + ', ' + str(system_time),
                               level='perf')

        if (csv_config.should_export()):
            file_name = target_config.get_target(
            ) + '_' + target_config.get_flavor() + '.csv'
            csv_file = os.path.join(csv_config.get_csv_dir(), file_name)
            try:
                U.make_dir(csv_config.get_csv_dir())
                rr_exporter.export(csv_file, csv_config.get_csv_dialect())
            except Exception as e:
                L.get_logger().log(
                    'Pira::execute_with_config: Problem writing CSV file\nMessage:\n'
                    + str(e),
                    level='error')

    except Exception as e:
        L.get_logger().log(
            'Pira::execute_with_config: Problem during preparation of run.\nMessage:\n'
            + str(e),
            level='error')
        raise RuntimeError(str(e))