def PerformStage(self):
        version_info = self._run.GetVersionInfo()
        build_version = [
            int(x) for x in version_info.VersionString().split('.')
        ]
        chrome_version = int(version_info.chrome_branch)
        target_version = [chrome_version] + build_version
        profile_versions = afdo.GetAvailableKernelProfiles()
        candidates = sorted(afdo.FindKernelEbuilds())
        expire_soon = set()
        not_found = set()
        expired = set()
        for candidate, kver in candidates:
            profile_version = None
            if kver in afdo.KERNEL_SKIP_AFDO_UPDATE:
                continue
            if kver in profile_versions:
                profile_version = afdo.FindLatestProfile(
                    target_version, profile_versions[kver])
            if not profile_version:
                not_found.add(kver)
                continue
            if afdo.ProfileAge(
                    profile_version) > afdo.KERNEL_ALLOWED_STALE_DAYS:
                expired.add('%s: %s' % (kver, profile_version))
                continue
            if afdo.ProfileAge(profile_version) > afdo.KERNEL_WARN_STALE_DAYS:
                expire_soon.add('%s: %s' % (kver, profile_version))

            afdo.PatchKernelEbuild(candidate, profile_version)
            # If the *-9999.ebuild is not the last entry in its directory, Manifest
            # will contain an unused line for previous profile which is still fine.
            if candidate.endswith('-9999.ebuild'):
                afdo.UpdateManifest(path_util.ToChrootPath(candidate))
        afdo.CommitIfChanged(afdo.KERNEL_EBUILD_ROOT,
                             'Update profiles and manifests for Kernel.')

        if not_found or expired:
            raise afdo.NoValidProfileFound(
                'Cannot find AutoFDO profiles: %s or expired: %s' %
                (not_found, expired))

        if expire_soon:
            self._WarnSheriff(expire_soon)
Example #2
0
 def testProfileAge(self):
     self.assertEqual(0, afdo.ProfileAge([0, 0, 0, int(time.time())]))
     self.assertEqual(1,
                      afdo.ProfileAge([0, 0, 0,
                                       int(time.time() - 86400)]))