<commit_before>from perfrunner.tests import target_hash, PerfTest


class XDCRTest(PerfTest):

    def _start_replication(self, m1, m2):
        name = target_hash(m1, m2)
        self.rest.add_remote_cluster(m1, m2, name)

        for bucket in self.test_config.get_buckets():
            self.rest.start_replication(m1, bucket, bucket, name)

    def _init_xdcr(self):
        xdcr_settings = self.test_config.get_xdcr_settings()

        c1, c2 = self.cluster_spec.get_clusters()
        m1, m2 = c1[0], c2[0]

        if xdcr_settings.replication_type == 'unidir':
            self._start_replication(m1, m2)
        if xdcr_settings.replication_type == 'bidir':
            self._start_replication(m1, m2)
            self._start_replication(m2, m1)

        for target in self.target_iterator:
            self.monitor.monitor_xdcr_replication(target)

    def run(self):
        self._run_load_phase()

        self.reporter.start()
        self._init_xdcr()
        value = self.reporter.finish('Initial replication')
        self.reporter.post_to_sf(self, value)<commit_msg>enable instrumentation in xdcr tests<commit_after>from perfrunner.helpers.cbmonitor import with_stats
from perfrunner.tests import target_hash, PerfTest


class XDCRTest(PerfTest):

    def _start_replication(self, m1, m2):
        name = target_hash(m1, m2)
        self.rest.add_remote_cluster(m1, m2, name)

        for bucket in self.test_config.get_buckets():
            self.rest.start_replication(m1, bucket, bucket, name)

    @with_stats()
    def _init_xdcr(self):
        xdcr_settings = self.test_config.get_xdcr_settings()

        c1, c2 = self.cluster_spec.get_clusters()
        m1, m2 = c1[0], c2[0]

        if xdcr_settings.replication_type == 'unidir':
            self._start_replication(m1, m2)
        if xdcr_settings.replication_type == 'bidir':
            self._start_replication(m1, m2)
            self._start_replication(m2, m1)

        for target in self.target_iterator:
            self.monitor.monitor_xdcr_replication(target)

    def run(self):
        self._run_load_phase()

        self.reporter.start()
        self._init_xdcr()
        value = self.reporter.finish('Initial replication')
        self.reporter.post_to_sf(self, value)
{'fraction_non_alphanumeric': 0.10048694112439133, 'fraction_numerical': 0.01859229747675963, 'mean_word_length': 2.791946308724832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4004848', 'n_tokens_mistral': 784, 'n_tokens_neox': 758, 'n_words': 134}