Patchwork [bitbake-devel,7/9] command.py: add new API to get the cpu count on the server

login
register
mail settings
Submitter Dongxiao Xu
Date Jan. 13, 2012, 8:30 a.m.
Message ID <44369e95249adee9818d8a79b723eb27f08cbdbc.1326442655.git.dongxiao.xu@intel.com>
Download mbox | patch
Permalink /patch/19263/
State Accepted
Commit 335047b2e440e65713e88fabb24b47a9c82f939b
Headers show

Comments

Dongxiao Xu - Jan. 13, 2012, 8:30 a.m.
From: Shane Wang <shane.wang@intel.com>

Add a new API in command.py to get the cpu count in order to set the appropriate default BB_NUMBER_THREADS and PARALLEL_MAKE variables.

Signed-off-by: Shane Wang <shane.wang@intel.com>
---
 lib/bb/command.py |    6 ++++++
 lib/bb/utils.py   |    4 ++++
 2 files changed, 10 insertions(+), 0 deletions(-)

Patch

diff --git a/lib/bb/command.py b/lib/bb/command.py
index 05555c5..43875f7 100644
--- a/lib/bb/command.py
+++ b/lib/bb/command.py
@@ -173,6 +173,12 @@  class CommandsSync:
         """
         command.cooker.reset()
 
+    def getCpuCount(self, command, params):
+        """
+        Get the CPU count on the bitbake server
+        """
+        return bb.utils.cpu_count()
+
 
 class CommandsAsync:
     """
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index a26635a..d7cefb2 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -25,6 +25,7 @@  import errno
 import logging
 import bb
 import bb.msg
+import multiprocessing
 from commands import getstatusoutput
 from contextlib import contextmanager
 
@@ -862,3 +863,6 @@  def contains(variable, checkvalues, truevalue, falsevalue, d):
     if checkvalues.issubset(val): 
         return truevalue
     return falsevalue
+
+def cpu_count():
+    return multiprocessing.cpu_count()