2"""Process a ref debug log for lock usage
4 This file will process a log file created by Asterisk
5 that was compiled with REF_DEBUG and DEBUG_THREADS.
7 See http://www.asterisk.org for more information about
8 the Asterisk project. Please do not directly contact
9 any of the maintainers of this project for assistance;
10 the project provides a web site, mailing lists and IRC
11 channels for your use.
13 This program is free software, distributed under the terms of
14 the GNU General Public License Version 2. See the LICENSE file
15 at the top of the source tree.
17 Copyright (C) 2018, CFWare, LLC
18 Corey Farrell <git@cfware.com>
21from __future__
import print_function
25from optparse
import OptionParser
29 """The routine that kicks off processing a ref file"""
33 filename = options.filepath
35 with open(filename,
'r')
as ref_file:
37 if 'constructor' not in line
and 'destructor' not in line:
42 tokens = line.strip().split(
',', 7)
45 if 'constructor' in state:
46 obj_type =
'%s:%s:%s' % (tokens[3], tokens[4], tokens[5])
47 if obj_type
not in object_types:
48 object_types[obj_type] = {
53 objects[addr] = obj_type
54 elif 'destructor' in state:
55 if addr
not in objects:
58 obj_type = objects[addr]
60 if '**lock-state:unused**' in state:
61 object_types[obj_type][
'unused'] += 1
62 elif '**lock-state:used**' in state:
63 object_types[obj_type][
'used'] += 1
64 elif '**lock-state:none**' in state:
65 object_types[obj_type][
'none'] += 1
67 for (allocator, info)
in object_types.items():
72 stats.append(
"%d used" % info[
'used'])
73 if info[
'unused'] > 0:
74 stats.append(
"%d unused" % info[
'unused'])
75 if info[
'none'] > 0
and options.none:
76 stats.append(
"%d none" % info[
'none'])
79 print(
"%s: %s" % (allocator,
', '.join(stats)))
83 """Main entry point for the script"""
90 parser = OptionParser()
92 parser.add_option(
"-f",
"--file", action=
"store", type=
"string",
93 dest=
"filepath", default=
"/var/log/asterisk/refs",
94 help=
"The full path to the refs file to process")
95 parser.add_option(
"-u",
"--suppress-used", action=
"store_false",
96 dest=
"used", default=
True,
97 help=
"Don't output types that have used locks.")
98 parser.add_option(
"-n",
"--show-none", action=
"store_true",
99 dest=
"none", default=
False,
100 help=
"Show counts of objects with no locking.")
102 (options, args) = parser.parse_args(argv)
104 if not os.path.isfile(options.filepath):
105 print(
"File not found: %s" % options.filepath, file=sys.stderr)
110 except (KeyboardInterrupt, SystemExit, IOError):
111 print(
"File processing cancelled", file=sys.stderr)
117if __name__ ==
"__main__":
118 sys.exit(
main(sys.argv))
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
def process_file(options)