BaseTools: Enable block queue log agent.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1875

To support Ctrl+S and Ctrl+Q, we enable block queue
for log.

Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Feng, Bob C
2019-07-31 13:33:31 +08:00
parent 4acae2b38e
commit 1a624dd7cf
3 changed files with 31 additions and 24 deletions

View File

@ -23,13 +23,14 @@ except:
import traceback import traceback
import sys import sys
from AutoGen.DataPipe import MemoryDataPipe from AutoGen.DataPipe import MemoryDataPipe
import logging
def clearQ(q): def clearQ(q):
try: try:
while True: while True:
q.get_nowait() q.get_nowait()
except Empty: except Empty:
pass pass
import logging
class LogAgent(threading.Thread): class LogAgent(threading.Thread):
def __init__(self,log_q,log_level,log_file=None): def __init__(self,log_q,log_level,log_file=None):
@ -123,9 +124,10 @@ class AutoGenManager(threading.Thread):
def clearQueue(self): def clearQueue(self):
taskq = self.autogen_workers[0].module_queue taskq = self.autogen_workers[0].module_queue
logq = self.autogen_workers[0].log_q
clearQ(taskq) clearQ(taskq)
clearQ(self.feedback_q) clearQ(self.feedback_q)
clearQ(logq)
def TerminateWorkers(self): def TerminateWorkers(self):
self.error_event.set() self.error_event.set()
def kill(self): def kill(self):

View File

@ -95,7 +95,9 @@ except:
self.enqueue(self.prepare(record)) self.enqueue(self.prepare(record))
except Exception: except Exception:
self.handleError(record) self.handleError(record)
class BlockQueueHandler(QueueHandler):
def enqueue(self, record):
self.queue.put(record,True)
## Log level constants ## Log level constants
DEBUG_0 = 1 DEBUG_0 = 1
DEBUG_1 = 2 DEBUG_1 = 2
@ -292,19 +294,19 @@ def LogClientInitialize(log_q):
# #
# For DEBUG level (All DEBUG_0~9 are applicable) # For DEBUG level (All DEBUG_0~9 are applicable)
_DebugLogger.setLevel(INFO) _DebugLogger.setLevel(INFO)
_DebugChannel = QueueHandler(log_q) _DebugChannel = BlockQueueHandler(log_q)
_DebugChannel.setFormatter(_DebugFormatter) _DebugChannel.setFormatter(_DebugFormatter)
_DebugLogger.addHandler(_DebugChannel) _DebugLogger.addHandler(_DebugChannel)
# For VERBOSE, INFO, WARN level # For VERBOSE, INFO, WARN level
_InfoLogger.setLevel(INFO) _InfoLogger.setLevel(INFO)
_InfoChannel = QueueHandler(log_q) _InfoChannel = BlockQueueHandler(log_q)
_InfoChannel.setFormatter(_InfoFormatter) _InfoChannel.setFormatter(_InfoFormatter)
_InfoLogger.addHandler(_InfoChannel) _InfoLogger.addHandler(_InfoChannel)
# For ERROR level # For ERROR level
_ErrorLogger.setLevel(INFO) _ErrorLogger.setLevel(INFO)
_ErrorCh = QueueHandler(log_q) _ErrorCh = BlockQueueHandler(log_q)
_ErrorCh.setFormatter(_ErrorFormatter) _ErrorCh.setFormatter(_ErrorFormatter)
_ErrorLogger.addHandler(_ErrorCh) _ErrorLogger.addHandler(_ErrorCh)

View File

@ -709,7 +709,7 @@ class Build():
self.FvList = BuildOptions.FvImage self.FvList = BuildOptions.FvImage
self.CapList = BuildOptions.CapName self.CapList = BuildOptions.CapName
self.SilentMode = BuildOptions.SilentMode self.SilentMode = BuildOptions.SilentMode
self.ThreadNumber = BuildOptions.ThreadNumber self.ThreadNumber = 1
self.SkipAutoGen = BuildOptions.SkipAutoGen self.SkipAutoGen = BuildOptions.SkipAutoGen
self.Reparse = BuildOptions.Reparse self.Reparse = BuildOptions.Reparse
self.SkuId = BuildOptions.SkuId self.SkuId = BuildOptions.SkuId
@ -882,19 +882,6 @@ class Build():
ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool]) ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool])
self.ToolChainFamily = ToolChainFamily self.ToolChainFamily = ToolChainFamily
if self.ThreadNumber is None:
self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]
if self.ThreadNumber == '':
self.ThreadNumber = 0
else:
self.ThreadNumber = int(self.ThreadNumber, 0)
if self.ThreadNumber == 0:
try:
self.ThreadNumber = multiprocessing.cpu_count()
except (ImportError, NotImplementedError):
self.ThreadNumber = 1
if not self.PlatformFile: if not self.PlatformFile:
PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM] PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM]
if not PlatformFile: if not PlatformFile:
@ -912,7 +899,7 @@ class Build():
ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n") ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n")
self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir) self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir)
self.ThreadNumber = ThreadNum()
## Initialize build configuration ## Initialize build configuration
# #
# This method will parse DSC file and merge the configurations from # This method will parse DSC file and merge the configurations from
@ -2056,12 +2043,13 @@ class Build():
data_pipe_file = os.path.join(Pa.BuildDir, "GlobalVar_%s_%s.bin" % (str(Pa.Guid),Pa.Arch)) data_pipe_file = os.path.join(Pa.BuildDir, "GlobalVar_%s_%s.bin" % (str(Pa.Guid),Pa.Arch))
Pa.DataPipe.dump(data_pipe_file) Pa.DataPipe.dump(data_pipe_file)
autogen_rt, errorcode = self.StartAutoGen(mqueue, Pa.DataPipe, self.SkipAutoGen, PcdMaList,self.share_data) autogen_rt, errorcode = self.StartAutoGen(mqueue, Pa.DataPipe, self.SkipAutoGen, PcdMaList,self.share_data)
self.Progress.Stop("done!")
self.AutoGenTime += int(round((time.time() - AutoGenStart)))
if not autogen_rt: if not autogen_rt:
self.AutoGenMgr.TerminateWorkers() self.AutoGenMgr.TerminateWorkers()
self.AutoGenMgr.join(0.1) self.AutoGenMgr.join(0.1)
raise FatalError(errorcode) raise FatalError(errorcode)
self.AutoGenTime += int(round((time.time() - AutoGenStart)))
self.Progress.Stop("done!")
for Arch in Wa.ArchList: for Arch in Wa.ArchList:
MakeStart = time.time() MakeStart = time.time()
for Ma in self.BuildModules: for Ma in self.BuildModules:
@ -2297,7 +2285,21 @@ def LogBuildTime(Time):
return TimeDurStr return TimeDurStr
else: else:
return None return None
def ThreadNum():
ThreadNumber = BuildOption.ThreadNumber
if ThreadNumber is None:
ThreadNumber = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]
if ThreadNumber == '':
ThreadNumber = 0
else:
ThreadNumber = int(ThreadNumber, 0)
if ThreadNumber == 0:
try:
ThreadNumber = multiprocessing.cpu_count()
except (ImportError, NotImplementedError):
ThreadNumber = 1
return ThreadNumber
## Tool entrance method ## Tool entrance method
# #
# This method mainly dispatch specific methods per the command line options. # This method mainly dispatch specific methods per the command line options.
@ -2307,13 +2309,14 @@ def LogBuildTime(Time):
# @retval 0 Tool was successful # @retval 0 Tool was successful
# @retval 1 Tool failed # @retval 1 Tool failed
# #
LogQMaxSize = ThreadNum() * 10
def Main(): def Main():
StartTime = time.time() StartTime = time.time()
# #
# Create a log Queue # Create a log Queue
# #
LogQ = mp.Queue() LogQ = mp.Queue(LogQMaxSize)
# Initialize log system # Initialize log system
EdkLogger.LogClientInitialize(LogQ) EdkLogger.LogClientInitialize(LogQ)
GlobalData.gCommand = sys.argv[1:] GlobalData.gCommand = sys.argv[1:]