Debian Codegraph @

tools/debug/core/chttp2_ref_leak.py

raw
1 #!/usr/bin/env python3
2 # Copyright 2017 gRPC authors.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Reads stdin to find chttp2_refcount log lines, and prints reference leaks
17 # to stdout
18
19 import collections
20 import re
21 import sys
22
23
24 def new_obj():
25 return ['destroy']
26
27
28 outstanding = collections.defaultdict(new_obj)
29
30 # Sample log line:
31 # chttp2:unref:0x629000005200 2->1 destroy [src/core/ext/transport/chttp2/transport/chttp2_transport.c:599]
32
33 for line in sys.stdin:
34 m = re.search(
35 r'chttp2:( ref|unref):0x([a-fA-F0-9]+) [^ ]+ ([^[]+) \[(.*)\]', line)
36 if m:
37 if m.group(1) == ' ref':
38 outstanding[m.group(2)].append(m.group(3))
39 else:
40 outstanding[m.group(2)].remove(m.group(3))
41
42 for obj, remaining in list(outstanding.items()):
43 if remaining:
44 print(('LEAKED: %s %r' % (obj, remaining)))