]> code.ossystems Code Review - openembedded-core.git/commitdiff
buildhistory: record additional image info
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Thu, 19 Jan 2012 10:32:09 +0000 (10:32 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 19 Jan 2012 14:31:08 +0000 (14:31 +0000)
Record some additional information about images - the uncompressed size
of the final image as well as the values of various variables that may
have influenced its contents. This is recorded in a machine-readable
"image-info.txt" file similar in structure to the package history files.

Also add some code to analyse changes to these values. (Most of the
variable values aren't monitored directly but will be used as contextual
information when they change at the same time as the content of the
image changing.)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/buildhistory.bbclass
meta/lib/oe/buildhistory_analysis.py

index 34cc2979097ed1b28ccd2ed2a4c76018b6ddaa8b..69a9d02a5ac094c640480c3231eaa8d1978160a6 100644 (file)
@@ -312,6 +312,14 @@ buildhistory_get_imageinfo() {
        # This awk script is somewhat messy, but handles where the size is not printed for device files under pseudo
        ( cd ${IMAGE_ROOTFS} && find . -ls | awk '{ if ( $7 ~ /[0-9]/ ) printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, $7, $11, $12, $13 ; else printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, 0, $10, $11, $12 }' > ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt )
 
+       # Record some machine-readable meta-information about the image
+       echo -n > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
+       cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END
+${@buildhistory_get_imagevars(d)}
+END
+       imagesize=`du -ks ${IMAGE_ROOTFS} | awk '{ print $1 }'`
+       echo "IMAGESIZE = $imagesize" >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
+
        # Add some configuration information
        echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id
 
@@ -330,6 +338,16 @@ def buildhistory_get_layers(d):
        return layertext
 
 
+def buildhistory_get_imagevars(d):
+       imagevars = "DISTRO DISTRO_VERSION USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS ROOTFS_POSTPROCESS_COMMAND IMAGE_POSTPROCESS_COMMAND"
+
+       ret = ""
+       for var in imagevars.split():
+               value = d.getVar(var, True) or ""
+               ret += "%s = %s\n" % (var, value)
+       return ret.rstrip('\n')
+
+
 buildhistory_commit() {
        if [ ! -d ${BUILDHISTORY_DIR} ] ; then
                # Code above that creates this dir never executed, so there can't be anything to commit
index 9f42fe38acb8ed927f75b3c44fff8bd1814d1b49..d3c0448fd18271fe7b5ca245fd5cf8ad4e482c32 100644 (file)
@@ -15,16 +15,15 @@ import git
 
 
 # How to display fields
-pkg_list_fields = ['DEPENDS', 'RDEPENDS', 'RRECOMMENDS', 'PACKAGES', 'FILES', 'FILELIST']
-pkg_numeric_fields = ['PKGSIZE']
+list_fields = ['DEPENDS', 'RDEPENDS', 'RRECOMMENDS', 'PACKAGES', 'FILES', 'FILELIST', 'USER_CLASSES', 'IMAGE_CLASSES', 'IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS']
+numeric_fields = ['PKGSIZE', 'IMAGESIZE']
 # Fields to monitor
-pkg_monitor_fields = ['RDEPENDS', 'RRECOMMENDS', 'PACKAGES', 'FILELIST', 'PKGSIZE']
+monitor_fields = ['RDEPENDS', 'RRECOMMENDS', 'PACKAGES', 'FILELIST', 'PKGSIZE', 'IMAGESIZE']
 # Percentage change to alert for numeric fields
-pkg_monitor_numeric_threshold = 20
-# Image files to monitor
+monitor_numeric_threshold = 20
+# Image files to monitor (note that image-info.txt is handled separately)
 img_monitor_files = ['installed-package-names.txt', 'files-in-image.txt']
 
-
 class ChangeRecord:
     def __init__(self, path, fieldname, oldvalue, newvalue):
         self.path = path
@@ -34,13 +33,13 @@ class ChangeRecord:
         self.filechanges = None
 
     def __str__(self):
-        if self.fieldname in pkg_list_fields:
+        if self.fieldname in list_fields:
             aitems = self.oldvalue.split(' ')
             bitems = self.newvalue.split(' ')
             removed = list(set(aitems) - set(bitems))
             added = list(set(bitems) - set(aitems))
             return '%s: %s:%s%s' % (self.path, self.fieldname, ' removed "%s"' % ' '.join(removed) if removed else '', ' added "%s"' % ' '.join(added) if added else '')
-        elif self.fieldname in pkg_numeric_fields:
+        elif self.fieldname in numeric_fields:
             aval = int(self.oldvalue)
             bval = int(self.newvalue)
             percentchg = ((bval - aval) / float(aval)) * 100
@@ -190,6 +189,25 @@ def compare_lists(alines, blines):
     return filechanges
 
 
+def compare_dict_blobs(path, ablob, bblob, report_all):
+    adict = blob_to_dict(ablob)
+    bdict = blob_to_dict(bblob)
+
+    changes = []
+    for key in adict:
+        if report_all or key in monitor_fields:
+            if adict[key] != bdict[key]:
+                if (not report_all) and key in numeric_fields:
+                    aval = int(adict[key])
+                    bval = int(bdict[key])
+                    percentchg = ((bval - aval) / float(aval)) * 100
+                    if percentchg < monitor_numeric_threshold:
+                        continue
+                chg = ChangeRecord(path, key, adict[key], bdict[key])
+                changes.append(chg)
+    return changes
+
+
 def process_changes(repopath, revision1, revision2 = 'HEAD', report_all = False):
     repo = git.Repo(repopath)
     assert repo.bare == False
@@ -200,20 +218,7 @@ def process_changes(repopath, revision1, revision2 = 'HEAD', report_all = False)
     for d in diff.iter_change_type('M'):
         path = os.path.dirname(d.a_blob.path)
         if path.startswith('packages/'):
-            adict = blob_to_dict(d.a_blob)
-            bdict = blob_to_dict(d.b_blob)
-
-            for key in adict:
-                if report_all or key in pkg_monitor_fields:
-                    if adict[key] != bdict[key]:
-                        if (not report_all) and key in pkg_numeric_fields:
-                            aval = int(adict[key])
-                            bval = int(bdict[key])
-                            percentchg = ((bval - aval) / float(aval)) * 100
-                            if percentchg < pkg_monitor_numeric_threshold:
-                                continue
-                        chg = ChangeRecord(path, key, adict[key], bdict[key])
-                        changes.append(chg)
+            changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all))
         elif path.startswith('images/'):
             filename = os.path.basename(d.a_blob.path)
             if filename in img_monitor_files:
@@ -236,5 +241,7 @@ def process_changes(repopath, revision1, revision2 = 'HEAD', report_all = False)
                 else:
                     chg = ChangeRecord(path, filename, d.a_blob.data_stream.read(), d.b_blob.data_stream.read())
                     changes.append(chg)
+            elif filename == 'image-info.txt':
+                changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all))
 
     return changes