diff options
author | Tom Rini <trini@konsulko.com> | 2021-07-22 11:15:52 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-07-22 11:15:52 -0400 |
commit | a15fa1ba67d7b3c8061b515e7713f733fa328018 (patch) | |
tree | f7746e2e7a3410043e9ea3f3f7c0a97e2c5e6dbb /tools/binman/state.py | |
parent | 806734f41b25931798fdf667b5a2ae830229c13f (diff) | |
parent | 1b098b3e655451572054ce933a87231ee16f7133 (diff) |
Merge tag 'dm-pull-21jul21' of https://gitlab.denx.de/u-boot/custodians/u-boot-dm
dtoc improvements to show better warnings
minor test build fixes
sandbox fixes for SDL2 and running TPL
bloblist resize feature
binman multithreading
Diffstat (limited to 'tools/binman/state.py')
-rw-r--r-- | tools/binman/state.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/binman/state.py b/tools/binman/state.py index dfb1760455..9e5b8a3931 100644 --- a/tools/binman/state.py +++ b/tools/binman/state.py @@ -5,8 +5,11 @@ # Holds and modifies the state information held by binman # +from collections import defaultdict import hashlib import re +import time +import threading from dtoc import fdt import os @@ -55,6 +58,30 @@ allow_entry_expansion = True # to the new ones, the compressed size increases, etc. allow_entry_contraction = False +# Number of threads to use for binman (None means machine-dependent) +num_threads = None + + +class Timing: + """Holds information about an operation that is being timed + + Properties: + name: Operation name (only one of each name is stored) + start: Start time of operation in seconds (None if not start) + accum:: Amount of time spent on this operation so far, in seconds + """ + def __init__(self, name): + self.name = name + self.start = None # cause an error if TimingStart() is not called + self.accum = 0.0 + + +# Holds timing info for each name: +# key: name of Timing info (Timing.name) +# value: Timing object +timing_info = {} + + def GetFdtForEtype(etype): """Get the Fdt object for a particular device-tree entry @@ -420,3 +447,71 @@ def AllowEntryContraction(): raised """ return allow_entry_contraction + +def SetThreads(threads): + """Set the number of threads to use when building sections + + Args: + threads: Number of threads to use (None for default, 0 for + single-threaded) + """ + global num_threads + + num_threads = threads + +def GetThreads(): + """Get the number of threads to use when building sections + + Returns: + Number of threads to use (None for default, 0 for single-threaded) + """ + return num_threads + +def GetTiming(name): + """Get the timing info for a particular operation + + The object is created if it does not already exist. + + Args: + name: Operation name to get + + Returns: + Timing object for the current thread + """ + threaded_name = '%s:%d' % (name, threading.get_ident()) + timing = timing_info.get(threaded_name) + if not timing: + timing = Timing(threaded_name) + timing_info[threaded_name] = timing + return timing + +def TimingStart(name): + """Start the timer for an operation + + Args: + name: Operation name to start + """ + timing = GetTiming(name) + timing.start = time.monotonic() + +def TimingAccum(name): + """Stop and accumlate the time for an operation + + This measures the time since the last TimingStart() and adds that to the + accumulated time. + + Args: + name: Operation name to start + """ + timing = GetTiming(name) + timing.accum += time.monotonic() - timing.start + +def TimingShow(): + """Show all timing information""" + duration = defaultdict(float) + for threaded_name, timing in timing_info.items(): + name = threaded_name.split(':')[0] + duration[name] += timing.accum + + for name, seconds in duration.items(): + print('%10s: %10.1fms' % (name, seconds * 1000)) |