]>
git.saurik.com Git - apple/mdnsresponder.git/blob - Platforms/ADK/Thread/adk-mem-parse.py
2 # Copyright (c) 2020 Apple Inc. All rights reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # This code parses an ADK log with MALLOC_DEBUG_LOGGING and eliminates matching alloc/free pairs.
18 # It then prints a list of all allocations that have not yet been freed, and the file and line
19 # number where they were allocated. This can be useful for detecting leaks, although not everything
20 # printed will be a leak: it could just be live data.
27 alloc_re
= re
.compile(r
"^([0-9][0-9]*\.[0-9][0-9]*)\s+[A-Za-z][A-Za-z]*\s+(0x[0-9a-f][0-9a-f]*): (malloc|strdup|calloc)\((.*)\) at (.*)$")
28 free_re
= re
.compile(r
"^([0-9][0-9]*\.[0-9][0-9]*)\s+[A-Za-z][A-Za-z]*\s+(0x[0-9a-f][0-9a-f]*): (free)\((.*)\) at (.*)$")
30 for line
in sys
.stdin
:
32 matches
= alloc_re
.match(line
)
34 allocations
[matches
.group(2)] = matches
36 matches
= free_re
.match(line
)
38 if matches
.group(2) in allocations
:
39 del allocations
[matches
.group(2)]
41 print("mismatched free: ", line
);
44 for key
, value
in allocations
.items():
45 if value
.group(5) in leaks
:
46 leaks
[value
.group(5)].append(value
)
48 leaks
[value
.group(5)] = [value
]
50 for key
in sorted(leaks
.keys()):
51 print("\nPossible leaks at: ", key
)
52 for match
in leaks
[key
]:
53 print(" ", match
.group(2), " ", match
.group(3), " ", match
.group(4))