10
10
GZIP_BALANCED_COMPRESSION_LEVEL = 6
11
11
DEFAULT_FRAME_COMPONENT_DELIMITER = ":"
12
12
13
-
14
13
def _get_module_path (file_path , sys_paths ):
15
14
"""
16
15
We tried to remove the python library root path in order to give a reasonable expression of the module path.
17
16
For example, /tmp/bin/python/site-packages/great_app/simple_expansions/simple_interface.py
18
17
will get turned into great_app.simple_expansions.simple_interface given that the syspath contains
19
18
/tmp/bin/python/site-packages
19
+
20
+ We are making sure we're removing the current path.
21
+ For example, '/Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app/./polls/views.py'
22
+ will get turned into `polls.views' given that the file path contains the current path.
23
+ This should not happen usually, but we've found a case where the "/." is added when calling traceback.walk_stack(..)
24
+ in a uwsgi application. Check sampling_utils.py file for details.
25
+
26
+ sampling_utils.py returns different values when calling traceback.walk_stack(..) for uwsgi vs non-uwsgi
27
+ for Python 3.8.10-Python 3.9.2.
28
+ Examples of results:
29
+ - file '/Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app/./polls/views.py', line 104, code get_queryset>, 104
30
+ - file '/Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app/polls/views.py', line 104, code get_queryset>, 104
20
31
"""
21
32
module_path = file_path
22
33
23
34
if platform .system () == "Windows" :
24
35
# In Windows, separator can either be / or \ from experimental result
25
- file_path = file_path .replace ("/" , os .sep )
36
+ module_path = module_path .replace ("/" , os .sep )
26
37
27
- for root in sys_paths :
28
- if root in file_path :
29
- module_path = file_path .replace (root , "" )
30
- break
38
+ # remove prefix path
39
+ module_path = _remove_prefix_path (module_path , sys_paths )
31
40
32
41
# remove suffix
33
42
module_path = str (Path (module_path ).with_suffix ("" ))
@@ -42,6 +51,15 @@ def _get_module_path(file_path, sys_paths):
42
51
return module_path
43
52
44
53
54
+ def _remove_prefix_path (module_path , sys_paths ):
55
+ current_path = str (Path ().absolute ())
56
+ if current_path in module_path :
57
+ return module_path .replace (current_path , "" ).replace ("/./" , "/" )
58
+ for root in sys_paths :
59
+ if root in module_path :
60
+ return module_path .replace (root , "" )
61
+ return module_path
62
+
45
63
class ProfileEncoder :
46
64
"""
47
65
Encodes a given Profile into the JSON version of the ion-based profile format
0 commit comments