<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_metrics(campaign, report, top=True):
 """Extract metrics from existing campaign :param campaign: campaign loaded with `hpcbench.campaign.from_file` :param report: instance of `hpcbench.campaign.ReportNode` :param top: this function is recursive. This parameter help distinguishing top-call. """

    if top and campaign.process.type == 'slurm':
        for path, _ in report.collect('jobid', with_path=True):
            for child in ReportNode(path).children.values():
                for metrics in get_metrics(campaign, child, top=False):
                    yield metrics
    else:

        def metrics_node_extract(report):
            metrics_file = osp.join(report.path, JSON_METRICS_FILE)
            if osp.exists(metrics_file):
                with open(metrics_file) as istr:
                    return json.load(istr)

        def metrics_iterator(report):
            return filter(
                lambda eax: eax[1] is not None,
                report.map(metrics_node_extract, with_path=True),
            )

        for path, metrics in metrics_iterator(report):
            yield report.path_context(path), metrics