float(osys["module_counts"][libname]["count"]) /
                 osys["count"],
               "in_os_versions":
                 osys["module_counts"][libname]["version_counts"]
             }
             for libname, modinfo in sig["module_counts"].items()]
 modules = [ module for module in modules
               if module["in_sig_ratio"] - module["in_os_ratio"] >=
                  MIN_BASELINE_DIFF ]
 modules.sort(key = lambda module: module["in_sig_ratio"] -
                                   module["in_os_ratio"],
              reverse = True)
 for module in modules:
     libname = module["libname"]
     if options.addons:
         info = addonids.info_for_id(libname)
         if info is not None:
             libname = libname + u" ({0}, {1})".format(info.name,
                                                       info.url)
     if options.show_versions and len(module["in_os_versions"]) == 1:
         onlyver = module["in_os_versions"].keys()[0]
         if osname.startswith("Mac OS X"):
             info = macdebugids.info_for_id(libname, onlyver)
             if info is not None:
                 onlyver = onlyver + "; " + info
         if (onlyver != ""):
             libname = libname + " (" + onlyver + ")"
     print u"    {0:3d}% ({1:d}/{2:d}) vs. {3:3d}% ({4:d}/{5:d}) {6}"\
             .format(int(round(module["in_sig_ratio"] * 100)),
                     module["in_sig_count"],
                     sig["count"],
Example #2
0
    def _summary_for_a_product_version_pair(self, a_pv_accumulator):
        """in the original code, the counter structures were walked and
        manipulated to form the statistics.  Once a stat was determined,
        it was printed to stdout.  Since we want to have various means of
        outputting the data, instead of printing to stdout, this method
        save the statistic in a "summary_structure"  This structure will
        later be walked for printing or output to some future storage scheme

        The summary structure looks like this:
        pv_summary
            .date_key  # a list of the last six UUID characters present
            .notes  # any notes added by the algorithm to tell of problems
            .os_counters[os_name*]
                 .count
                 .signatures[a_signature*]
                     .count
                     .in_sig_ratio
                     .in_os_ratio
                     .in_os_count
                     .osys_count
                     .modules[a_module*]  # may be addons
                         .in_sig_ratio
                         .in_os_ratio
                         .in_os_count
                         .osys_count
                         .verisons[a_version*]  # may be addon versions
                             .sig_ver_ratio
                             .sig_ver_count
                             .sig_count
                             .os_ver_ratio
                             .os_ver_count
                             .osys_count
                             .version
        """

        options = self.config
        pv_summary = SocorroDotDict({"notes": []})
        if len(self.date_suffix) > 1:
            message = "crashes from more than one day %s" % str(tuple(self.date_suffix.keys()))
            ##            self.config.logger.debug(message)
            pv_summary.notes.append(message)
        pv_summary.date_key = self.date_suffix.keys()[0]
        pv_summary.os_counters = {}

        MIN_CRASHES = self.config.min_crashes
        counters_for_multiple_os = a_pv_accumulator.osyses

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # begin - refactored code section
        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        infostr_re = re.compile("^(.*) with (\d+) cores$")  # unused?

        for os_name in counters_for_multiple_os.keys():
            counters_for_an_os = counters_for_multiple_os[os_name]

            pv_summary.os_counters[os_name] = SocorroDotDict()
            pv_summary.os_counters[os_name].count = counters_for_multiple_os[os_name].count
            pv_summary.os_counters[os_name].signatures = {}
            filtered_signatures = [
                (signature, signature_counter)
                for (signature, signature_counter) in counters_for_an_os["signatures"].items()
                if signature_counter.count >= MIN_CRASHES
            ]
            for a_signature, a_signtaure_counter in filtered_signatures:
                pv_summary.os_counters[os_name].signatures[a_signature] = SocorroDotDict()
                pv_summary.os_counters[os_name].signatures[a_signature].count = a_signtaure_counter.count
                pv_summary.os_counters[os_name].signatures[a_signature].modules = {}
                modules_list = [
                    SocorroDotDict(
                        {
                            "libname": module_name,
                            "in_sig_count": a_module_counter.count,
                            "in_sig_ratio": float(a_module_counter.count) / a_signtaure_counter.count,
                            "in_sig_versions": a_module_counter.versions,
                            "in_os_count": counters_for_an_os.modules[module_name].count,
                            "in_os_ratio": (
                                float(counters_for_an_os.modules[module_name].count) / counters_for_an_os.count
                            ),
                            "in_os_versions": counters_for_an_os.modules[module_name].versions,
                        }
                    )
                    for module_name, a_module_counter in a_signtaure_counter.modules.iteritems()
                ]

                modules_list = [
                    module
                    for module in modules_list
                    if module.in_sig_ratio - module.in_os_ratio >= self.config.min_baseline_diff
                ]

                modules_list.sort(key=lambda module: module.in_sig_ratio - module.in_os_ratio, reverse=True)

                for module in modules_list:
                    module_name = module.libname
                    if options.addons:
                        info = addonids.info_for_id(module_name)
                        if info is not None:
                            module_name = module_name + u" ({0}, {1})".format(info.name, info.url)
                    if options.show_versions and len(module["in_os_versions"]) == 1:
                        onlyver = module.in_os_versions.keys()[0]
                        if os_name.startswith("Mac OS X"):
                            info = macdebugids.info_for_id(module_name, onlyver)
                            if info is not None:
                                onlyver = onlyver + "; " + info
                        if onlyver != "":
                            module_name = module_name + " (" + onlyver + ")"
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name] = SocorroDotDict()
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[
                        module_name
                    ].in_sig_count = module.in_sig_count
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].in_sig_ratio = int(
                        round(module["in_sig_ratio"] * 100)
                    )
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].in_os_ratio = int(
                        round(module.in_os_ratio * 100)
                    )
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[
                        module_name
                    ].in_os_count = module.in_os_count
                    pv_summary.os_counters[os_name].signatures[a_signature].modules[
                        module_name
                    ].osys_count = counters_for_an_os.count

                    if options.show_versions and len(module.in_os_versions) != 1:
                        versions = module.in_os_versions.keys()
                        versions.sort()
                        pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions = {}
                        for version in versions:
                            sig_ver_count = module.in_sig_versions.get(version, 0)
                            os_ver_count = module.in_os_versions[version]
                            if os_name.startswith("Mac OS X"):
                                info = macdebugids.info_for_id(module_name, version)
                                if info is not None:
                                    version = version + " (" + info + ")"
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ] = SocorroDotDict()
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].sig_ver_ratio = int(round(float(sig_ver_count) / a_signtaure_counter.count * 100))
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].sig_ver_count = sig_ver_count
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].sig_count = a_signtaure_counter.count
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].os_ver_ratio = int(round(float(os_ver_count) / counters_for_an_os.count * 100))
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].os_ver_count = os_ver_count
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].osys_count = counters_for_an_os.count
                            pv_summary.os_counters[os_name].signatures[a_signature].modules[module_name].versions[
                                version
                            ].version = version
        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        # end - refactored code section
        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        return pv_summary