summaryrefslogtreecommitdiffstats
path: root/bitbake/contrib/dump_cache.py
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2018-02-07 16:01:59 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-02-14 15:26:03 +0000
commit3e76b1b50c18e5e1d87d19df49fc5fb598cb84f9 (patch)
treeecbb2673d769a4497a68e64efaf2654cabe096bb /bitbake/contrib/dump_cache.py
parent85fa5ee8254846af269af61c214f81cce4c5b4a8 (diff)
downloadpoky-3e76b1b50c18e5e1d87d19df49fc5fb598cb84f9.tar.gz
bitbake: contrib/dump_cache.py: make it can dump everything
Have a simple tool to dump bb_cache.dat is useful for investigating and studying bitbake cache. The old contrib/dump_cache.py can dump pn, pv and packages for it, now enhance it dump everything. Here is the usage: $ /path/to/dump_cache.py --help usage: dump_cache.py [-h] [-r RECIPE] [-m MEMBERS] [-s] cachefile bb_cache.dat's dumper positional arguments: cachefile specify bb_cache.dat optional arguments: -h, --help show this help message and exit -r RECIPE, --recipe RECIPE specify the recipe, default: all recipes -m MEMBERS, --members MEMBERS specify the member, use comma as separator for multiple ones, default: all members -s, --skip skip skipped recipes Use dump_cache.py --help to get help (Bitbake rev: 104572438dfedf6025fbfd125aef1d56134012e7) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/contrib/dump_cache.py')
-rwxr-xr-xbitbake/contrib/dump_cache.py85
1 files changed, 51 insertions, 34 deletions
diff --git a/bitbake/contrib/dump_cache.py b/bitbake/contrib/dump_cache.py
index f4d4c1b123..8963ca4b06 100755
--- a/bitbake/contrib/dump_cache.py
+++ b/bitbake/contrib/dump_cache.py
@@ -2,7 +2,7 @@
2# ex:ts=4:sw=4:sts=4:et 2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- 3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4# 4#
5# Copyright (C) 2012 Wind River Systems, Inc. 5# Copyright (C) 2012, 2018 Wind River Systems, Inc.
6# 6#
7# This program is free software; you can redistribute it and/or modify 7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as 8# it under the terms of the GNU General Public License version 2 as
@@ -18,51 +18,68 @@
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 19
20# 20#
21# This is used for dumping the bb_cache.dat, the output format is: 21# Used for dumping the bb_cache.dat
22# recipe_path PN PV PACKAGES
23# 22#
24import os 23import os
25import sys 24import sys
26import warnings 25import argparse
27 26
28# For importing bb.cache 27# For importing bb.cache
29sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib')) 28sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib'))
30from bb.cache import CoreRecipeInfo 29from bb.cache import CoreRecipeInfo
31 30
32import pickle as pickle 31import pickle
33 32
34def main(argv=None): 33class DumpCache(object):
35 """ 34 def __init__(self):
36 Get the mapping for the target recipe. 35 parser = argparse.ArgumentParser(
37 """ 36 description="bb_cache.dat's dumper",
38 if len(argv) != 1: 37 epilog="Use %(prog)s --help to get help")
39 print("Error, need one argument!", file=sys.stderr) 38 parser.add_argument("-r", "--recipe",
40 return 2 39 help="specify the recipe, default: all recipes", action="store")
40 parser.add_argument("-m", "--members",
41 help = "specify the member, use comma as separator for multiple ones, default: all members", action="store", default="")
42 parser.add_argument("-s", "--skip",
43 help = "skip skipped recipes", action="store_true")
44 parser.add_argument("cachefile",
45 help = "specify bb_cache.dat", nargs = 1, action="store", default="")
41 46
42 cachefile = argv[0] 47 self.args = parser.parse_args()
43 48
44 with open(cachefile, "rb") as cachefile: 49 def main(self):
45 pickled = pickle.Unpickler(cachefile) 50 with open(self.args.cachefile[0], "rb") as cachefile:
46 while cachefile: 51 pickled = pickle.Unpickler(cachefile)
47 try: 52 while True:
48 key = pickled.load() 53 try:
49 val = pickled.load() 54 key = pickled.load()
50 except Exception: 55 val = pickled.load()
51 break 56 except Exception:
52 if isinstance(val, CoreRecipeInfo) and (not val.skipped): 57 break
53 pn = val.pn 58 if isinstance(val, CoreRecipeInfo):
54 # Filter out the native recipes. 59 pn = val.pn
55 if key.startswith('virtual:native:') or pn.endswith("-native"):
56 continue
57 60
58 # 1.0 is the default version for a no PV recipe. 61 if self.args.recipe and self.args.recipe != pn:
59 if "pv" in val.__dict__: 62 continue
60 pv = val.pv
61 else:
62 pv = "1.0"
63 63
64 print("%s %s %s %s" % (key, pn, pv, ' '.join(val.packages))) 64 if self.args.skip and val.skipped:
65 continue
65 66
66if __name__ == "__main__": 67 if self.args.members:
67 sys.exit(main(sys.argv[1:])) 68 out = key
69 for member in self.args.members.split(','):
70 out += ": %s" % val.__dict__.get(member)
71 print("%s" % out)
72 else:
73 print("%s: %s" % (key, val.__dict__))
74 elif not self.args.recipe:
75 print("%s %s" % (key, val))
68 76
77if __name__ == "__main__":
78 try:
79 dump = DumpCache()
80 ret = dump.main()
81 except Exception as esc:
82 ret = 1
83 import traceback
84 traceback.print_exc()
85 sys.exit(ret)