[bitbake-devel,15/16] command.py: add new command to get the CPU info
Submitted by Dongxiao Xu on Jan. 6, 2012, 9:02 a.m.
|
Patch ID: 18627
Details
Commit Message
new file mode 100644
@@ -0,0 +1,39 @@
+#
+# Helper for BitBake Graphical GTK User Interface
+#
+# Copyright (C) 2011 Intel Corporation
+#
+# Authored by Shane Wang <shane.wang@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import os
+
+class CpuInfo(object):
+
+ coefficient = 4
+
+ @classmethod
+ def getNumOfCpus(cls):
+ pfile = os.popen('cat /proc/cpuinfo | grep cpu\ cores')
+ num = len(pfile.readlines())
+ return num
+
+ @classmethod
+ def getNumOfCpuCores(cls):
+ pfile = os.popen('cat /proc/cpuinfo | grep cpu\ cores | cut -d: -f2')
+ contents = pfile.readlines()
+ num = int(contents[0])
+ return num
+
@@ -30,6 +30,7 @@ Commands are queued in a CommandQueue
import bb.event
import bb.cooker
+import bb.helper
class CommandCompleted(bb.event.Event):
pass
@@ -170,6 +171,17 @@ class CommandsSync:
"""
command.cooker.reset()
+ def getDefaultNumOfThreads(self, command, params):
+ """
+ Get the default number of threads on the server = number of CPUs
+ """
+ return bb.helper.CpuInfo.getNumOfCpus()
+
+ def getMaxNumOfThreads(self, command, params):
+ """
+ Get the max number of threads that the server can tolerate
+ """
+ return bb.helper.CpuInfo.getNumOfCpus() * bb.helper.CpuInfo.coefficient
class CommandsAsync:
"""
Add new API in command.py to get the CPU core and threads information in order to set the appropriate BB_NUMBER_THREADS and PARALLEL_MAKE variables. Signed-off-by: Shane Wang <shane.wang@intel.com> --- bitbake/lib/bb/helper.py | 39 +++++++++++++++++++++++++++++++++++++++ lib/bb/command.py | 12 ++++++++++++ 2 files changed, 51 insertions(+), 0 deletions(-) create mode 100644 bitbake/lib/bb/helper.py