LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
citizenContinued.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 #
4 # Copyright 2008-2017 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 
25 __all__ = ["setCallbacks", "mortal"]
26 
27 import re
28 
29 from .citizen import Citizen
30 
31 
32 def setCallbacks(new=None, delete=None, both=False):
33  """Set the callback IDs for the Citizen; if both is true, set both new and delete to the same value
34 
35  You probably want to chant the following to gdb:
36  break defaultNewCallback
37  break defaultDeleteCallback
38 
39  You might want to put this in your .gdbinit file.
40 
41  You can retrieve a citizen's signature from python with obj.repr()
42  """
43 
44  if both:
45  if new:
46  if delete and new != delete:
47  raise RuntimeError("You may not specify new, delete, and both")
48  delete = new
49  else:
50  new = delete
51 
52  if new:
53  Citizen.setNewCallbackId(new)
54  if delete:
55  Citizen.setDeleteCallbackId(delete)
56 
57 
58 def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None):
59  """!Print leaked memory blocks
60 
61  @param memId0 Only consider blocks allocated after this memId
62  @param nleakPrintMax Maximum number of leaks to print; <= 0 means unlimited
63  @param first Print the first nleakPrintMax blocks; if False print the last blocks.
64  @param showTypes Only print objects matching this regex (if starts with !, print objects that don't match)
65 
66  If you want finer control than nleakPrintMax/first provide, use
67  Citizen.census() to get the entire list
68 
69  You can get the next memId to be allocated with mortal("set"), e.g.
70  memId0 = mortal("set")
71  # work work work
72  mortal(memId0)
73  """
74  if memId0 == 'set':
75  return Citizen.getNextMemId()
76 
77  nleak = Citizen.census(0, memId0)
78  if nleak != 0:
79  print("%d Objects leaked" % Citizen.census(0, memId0))
80 
81  census = Citizen.census()
82  census = [census[i].repr() for i in range(len(census))] # using [i] for some swiggy reason
83  if showTypes:
84  if showTypes[0] == '!':
85  invert = True # invert the matching logic
86  showTypes = showTypes[1:]
87  else:
88  invert = False
89 
90  _census, census = census, []
91  for c in _census:
92  memId, addr, dtype = c.split()
93  memId = int(memId[:-1])
94 
95  if (not invert and re.search(showTypes, dtype)) or \
96  (invert and not re.search(showTypes, dtype)):
97  census.append(c)
98 
99  nleak = len(census)
100  print("%d leaked objects match" % nleak)
101 
102  if nleakPrintMax <= 0 or nleak <= nleakPrintMax:
103  for c in census:
104  memId, addr, type = c.split()
105  memId = int(memId[:-1])
106  if memId >= memId0:
107  print(c)
108  else:
109  print("...")
110  for i in range(nleakPrintMax - 1, -1, -1):
111  print(census[i])
def setCallbacks(new=None, delete=None, both=False)
def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None)
Print leaked memory blocks.