Skip to contentSkip to conversation

buildstats: tolerate absence of /proc/diskstats

PATCH Applied Jean-François Dagenais 2 participants 2 messages Jan 16, 2012 – Jan 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 buildstats: tolerate absence of /proc/diskstats

From: Jean-François Dagenais <[email protected]>

In OpenVZ containers (and probably lx containers as well), the diskstats entry is not even present. Use the "NoLogicalDrive" introduced by Elizabeth Flanagan in such case.

This allows the bitbaking to occure within such containers.

---
 meta/classes/buildstats.bbclass |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
meta/classes/buildstats.bbclass +15 -10
index 4cd8fe6..9690a04 100644
@@ -61,11 +61,13 @@ def set_device(e):
     # we do not collect diskstats as the method to collect meaningful statistics
     # for these fs types requires a bit more research. 
     ############################################################################
-    for line in open("/proc/diskstats", "r"):
-        if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
-           rdev=line.split()[2]
-        else:
-           rdev="NoLogicalDevice"
+    rdev="NoLogicalDevice"
+    try:
+        for line in open("/proc/diskstats", "r"):
+            if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
+               rdev=line.split()[2]
+    except:
+        pass
     file = open(e.data.getVar('DEVFILE', True), "w")
     file.write(rdev)
     file.close()
@@ -82,12 +84,15 @@ def get_diskstats(dev):
     # For info on what these are, see kernel doc file iostats.txt
     ############################################################################
     DSTAT_KEYS = ['ReadsComp', 'ReadsMerged', 'SectRead', 'TimeReads', 'WritesComp', 'SectWrite', 'TimeWrite', 'IOinProgress', 'TimeIO', 'WTimeIO']  
-    for x in open("/proc/diskstats", "r"):
-        if dev in x:
-            diskstats_val = x.rstrip().split()[4:]
-    diskstats = dict(itertools.izip(DSTAT_KEYS, diskstats_val))        
+    try:
+        for x in open("/proc/diskstats", "r"):
+            if dev in x:
+                diskstats_val = x.rstrip().split()[4:]
+    except IOError as e:
+        return
+    diskstats = dict(itertools.izip(DSTAT_KEYS, diskstats_val))
     return diskstats
-    
+
 def set_diskdata(var, dev, data):
     data.setVar(var, get_diskstats(dev))
 
Signature · 1 line
1.7.8.3
Applied
#1 lore raw
Quoted 47 lines · Jean-François Dagenais

From: Jean-François Dagenais<[email protected]>

In OpenVZ containers (and probably lx containers as well), the diskstats entry is not even present. Use the "NoLogicalDrive" introduced by Elizabeth Flanagan in such case.

This allows the bitbaking to occure within such containers.

---
  meta/classes/buildstats.bbclass |   25 +++++++++++++++----------
  1 files changed, 15 insertions(+), 10 deletions(-)
meta/classes/buildstats.bbclass +10 -9
index 4cd8fe6..9690a04 100644
@@ -61,11 +61,13 @@ def set_device(e):
      # we do not collect diskstats as the method to collect meaningful statistics
      # for these fs types requires a bit more research.
      ############################################################################
-    for line in open("/proc/diskstats", "r"):
-        if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
-           rdev=line.split()[2]
-        else:
-           rdev="NoLogicalDevice"
+    rdev="NoLogicalDevice"
+    try:
+        for line in open("/proc/diskstats", "r"):
+            if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
+               rdev=line.split()[2]
+    except:
+        pass
      file = open(e.data.getVar('DEVFILE', True), "w")
      file.write(rdev)
      file.close()
@@ -82,12 +84,15 @@ def get_diskstats(dev):
      # For info on what these are, see kernel doc file iostats.txt
      ############################################################################
      DSTAT_KEYS = ['ReadsComp', 'ReadsMerged', 'SectRead', 'TimeReads', 'WritesComp', 'SectWrite', 'TimeWrite', 'IOinProgress', 'TimeIO', 'WTimeIO']
-    for x in open("/proc/diskstats", "r"):
-        if dev in x:
-            diskstats_val = x.rstrip().split()[4:]
-    diskstats = dict(itertools.izip(DSTAT_KEYS, diskstats_val))
+    try:
+        for x in open("/proc/diskstats", "r"):
+            if dev in x:

meta/classes/buildstats.bbclass def get_diskstats(dev): · line 98

Quoted 10 lines
meta/classes/buildstats.bbclass +5 -1
+                diskstats_val = x.rstrip().split()[4:]
+    except IOError as e:
+        return
+    diskstats = dict(itertools.izip(DSTAT_KEYS, diskstats_val))
      return diskstats
-
+
  def set_diskdata(var, dev, data):
      data.setVar(var, get_diskstats(dev))
 

Merged into OE-Core

For future reference, please send patches for the meta layer to [email protected], as the meta layer is really OE-Core

Thanks
Sau!