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)