Asterisk - The Open Source Telephony Project  18.5.0
Functions
reflocks Namespace Reference

Functions

def main (argv=None)
 
def process_file (options)
 

Detailed Description

Process a ref debug log for lock usage

 This file will process a log file created by Asterisk
 that was compiled with REF_DEBUG and DEBUG_THREADS.

 See http://www.asterisk.org for more information about
 the Asterisk project. Please do not directly contact
 any of the maintainers of this project for assistance;
 the project provides a web site, mailing lists and IRC
 channels for your use.

 This program is free software, distributed under the terms of
 the GNU General Public License Version 2. See the LICENSE file
 at the top of the source tree.

 Copyright (C) 2018, CFWare, LLC
 Corey Farrell <[email protected]>

Function Documentation

◆ main()

def reflocks.main (   argv = None)
Main entry point for the script

Definition at line 82 of file reflocks.py.

References process_file().

82 def main(argv=None):
83  """Main entry point for the script"""
84 
85  ret_code = 0
86 
87  if argv is None:
88  argv = sys.argv
89 
90  parser = OptionParser()
91 
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.")
101 
102  (options, args) = parser.parse_args(argv)
103 
104  if not os.path.isfile(options.filepath):
105  print("File not found: %s" % options.filepath, file=sys.stderr)
106  return -1
107 
108  try:
109  process_file(options)
110  except (KeyboardInterrupt, SystemExit, IOError):
111  print("File processing cancelled", file=sys.stderr)
112  return -1
113 
114  return ret_code
115 
116 
def process_file(options)
Definition: reflocks.py:28
def main(argv=None)
Definition: reflocks.py:82

◆ process_file()

def reflocks.process_file (   options)
The routine that kicks off processing a ref file

Definition at line 28 of file reflocks.py.

References len().

Referenced by main().

28 def process_file(options):
29  """The routine that kicks off processing a ref file"""
30 
31  object_types = {}
32  objects = {}
33  filename = options.filepath
34 
35  with open(filename, 'r') as ref_file:
36  for line in ref_file:
37  if 'constructor' not in line and 'destructor' not in line:
38  continue
39  # The line format is:
40  # addr,delta,thread_id,file,line,function,state,tag
41  # Only addr, file, line, function, state are used by reflocks.py
42  tokens = line.strip().split(',', 7)
43  addr = tokens[0]
44  state = tokens[6]
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] = {
49  'used': 0,
50  'unused': 0,
51  'none': 0
52  }
53  objects[addr] = obj_type
54  elif 'destructor' in state:
55  if addr not in objects:
56  # This error would be reported by refcounter.py.
57  continue
58  obj_type = objects[addr]
59  del 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
66 
67  for (allocator, info) in object_types.items():
68  stats = [];
69  if info['used'] > 0:
70  if not options.used:
71  continue
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'])
77  if len(stats) == 0:
78  continue
79  print("%s: %s" % (allocator, ', '.join(stats)))
80 
81 
def process_file(options)
Definition: reflocks.py:28
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)