LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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
34  delete to the same value.
35 
36  You probably want to chant the following to gdb:
37  * break defaultNewCallback
38  * break defaultDeleteCallback
39 
40  You might want to put this in your ``.gdbinit`` file.
41 
42  You can retrieve a citizen's signature from python with ``obj.repr()``.
43  """
44 
45  if both:
46  if new:
47  if delete and new != delete:
48  raise RuntimeError("You may not specify new, delete, and both")
49  delete = new
50  else:
51  new = delete
52 
53  if new:
54  Citizen.setNewCallbackId(new)
55  if delete:
56  Citizen.setDeleteCallbackId(delete)
57 
58 
59 def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None):
60  """!Print leaked memory blocks
61 
62  @param memId0 Only consider blocks allocated after this memId
63  @param nleakPrintMax Maximum number of leaks to print; <= 0 means unlimited
64  @param first Print the first nleakPrintMax blocks; if False print the last
65  blocks.
66  @param showTypes Only print objects matching this regex (if starts with !,
67  print objects that don't match)
68 
69  If you want finer control than nleakPrintMax/first provide, use
70  Citizen.census() to get the entire list
71 
72  You can get the next memId to be allocated with mortal("set"), e.g.
73  memId0 = mortal("set")
74  # work work work
75  mortal(memId0)
76  """
77  if memId0 == 'set':
78  return Citizen.getNextMemId()
79 
80  nleak = Citizen.census(0, memId0)
81  if nleak != 0:
82  print("%d Objects leaked" % Citizen.census(0, memId0))
83 
84  census = Citizen.census()
85  census = [census[i].repr() for i in range(len(census))] # using [i] for some swiggy reason
86  if showTypes:
87  if showTypes[0] == '!':
88  invert = True # invert the matching logic
89  showTypes = showTypes[1:]
90  else:
91  invert = False
92 
93  _census, census = census, []
94  for c in _census:
95  memId, addr, dtype = c.split()
96  memId = int(memId[:-1])
97 
98  if (not invert and re.search(showTypes, dtype)) or \
99  (invert and not re.search(showTypes, dtype)):
100  census.append(c)
101 
102  nleak = len(census)
103  print("%d leaked objects match" % nleak)
104 
105  if nleakPrintMax <= 0 or nleak <= nleakPrintMax:
106  for c in census:
107  memId, addr, type = c.split()
108  memId = int(memId[:-1])
109  if memId >= memId0:
110  print(c)
111  else:
112  print("...")
113  for i in range(nleakPrintMax - 1, -1, -1):
114  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.