cavisson-pythonagent 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
  2. cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
  3. cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
  4. cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
  5. cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
  6. pythonagent/__init__.py +22 -0
  7. pythonagent/agent/__init__.py +219 -0
  8. pythonagent/agent/internal/__init__.py +1 -0
  9. pythonagent/agent/internal/agent.py +1651 -0
  10. pythonagent/agent/internal/framesinfo.py +152 -0
  11. pythonagent/agent/internal/heap_dump.py +39 -0
  12. pythonagent/agent/internal/intercept_module.py +70 -0
  13. pythonagent/agent/internal/logs.py +122 -0
  14. pythonagent/agent/internal/metadata/__init__.py +0 -0
  15. pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
  16. pythonagent/agent/internal/proc_compat.py +75 -0
  17. pythonagent/agent/internal/profile.py +47 -0
  18. pythonagent/agent/internal/provider.py +83 -0
  19. pythonagent/agent/internal/thread_dump.py +85 -0
  20. pythonagent/agent/internal/udp.py +245 -0
  21. pythonagent/agent/internal/udp_message.py +800 -0
  22. pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
  23. pythonagent/agent/probes/Instrumentation/find.py +243 -0
  24. pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
  25. pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
  26. pythonagent/agent/probes/Instrumentation/parser.py +129 -0
  27. pythonagent/agent/probes/__init__.py +219 -0
  28. pythonagent/agent/probes/base.py +303 -0
  29. pythonagent/agent/probes/cache/__init__.py +51 -0
  30. pythonagent/agent/probes/cache/redis.py +119 -0
  31. pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
  32. pythonagent/agent/probes/coroutines/__init__.py +1 -0
  33. pythonagent/agent/probes/coroutines/asyncio.py +63 -0
  34. pythonagent/agent/probes/elasticdb/__init__.py +7 -0
  35. pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
  36. pythonagent/agent/probes/frameworks/__init__.py +27 -0
  37. pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
  38. pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
  39. pythonagent/agent/probes/frameworks/aisess.py +151 -0
  40. pythonagent/agent/probes/frameworks/asgi.py +340 -0
  41. pythonagent/agent/probes/frameworks/bottle.py +27 -0
  42. pythonagent/agent/probes/frameworks/cherry.py +25 -0
  43. pythonagent/agent/probes/frameworks/django.py +128 -0
  44. pythonagent/agent/probes/frameworks/falcon.py +21 -0
  45. pythonagent/agent/probes/frameworks/fastapi.py +35 -0
  46. pythonagent/agent/probes/frameworks/flask.py +30 -0
  47. pythonagent/agent/probes/frameworks/pyramid.py +56 -0
  48. pythonagent/agent/probes/frameworks/test.py +108 -0
  49. pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
  50. pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
  51. pythonagent/agent/probes/frameworks/wsgi.py +353 -0
  52. pythonagent/agent/probes/grpc/__init__.py +76 -0
  53. pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
  54. pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
  55. pythonagent/agent/probes/havoc/__init__.py +0 -0
  56. pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
  57. pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
  58. pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
  59. pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
  60. pythonagent/agent/probes/http/__init__.py +49 -0
  61. pythonagent/agent/probes/http/aiohttp_client.py +59 -0
  62. pythonagent/agent/probes/http/boto.py +12 -0
  63. pythonagent/agent/probes/http/httplib.py +110 -0
  64. pythonagent/agent/probes/http/httpx_client.py +116 -0
  65. pythonagent/agent/probes/http/requests.py +15 -0
  66. pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
  67. pythonagent/agent/probes/http/urllib3.py +16 -0
  68. pythonagent/agent/probes/langchain/__init__.py +21 -0
  69. pythonagent/agent/probes/langchain/base_tool.py +95 -0
  70. pythonagent/agent/probes/langchain/langchain_community.py +136 -0
  71. pythonagent/agent/probes/langchain/langchain_core.py +32 -0
  72. pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
  73. pythonagent/agent/probes/logging/__init__.py +106 -0
  74. pythonagent/agent/probes/message_brokers/__init__.py +4 -0
  75. pythonagent/agent/probes/message_brokers/pika.py +126 -0
  76. pythonagent/agent/probes/mongodb/__init__.py +6 -0
  77. pythonagent/agent/probes/mongodb/pymongo.py +286 -0
  78. pythonagent/agent/probes/openai/__init__.py +3 -0
  79. pythonagent/agent/probes/openai/openai.py +797 -0
  80. pythonagent/agent/probes/span.py +101 -0
  81. pythonagent/agent/probes/sql/__init__.py +13 -0
  82. pythonagent/agent/probes/sql/botocores3.py +51 -0
  83. pythonagent/agent/probes/sql/dbapi.py +285 -0
  84. pythonagent/agent/probes/sql/dynamodb.py +90 -0
  85. pythonagent/agent/probes/sql/mysql_connector.py +24 -0
  86. pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
  87. pythonagent/agent/probes/sql/mysqldb.py +43 -0
  88. pythonagent/agent/probes/sql/psycopg2.py +174 -0
  89. pythonagent/agent/probes/sql/pymysql.py +25 -0
  90. pythonagent/bootstrap/__init__.py +0 -0
  91. pythonagent/bootstrap/cav_gunicorn.py +26 -0
  92. pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
  93. pythonagent/bootstrap/run.py +47 -0
  94. pythonagent/bootstrap/sitecustomize.py +287 -0
  95. pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
  96. pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
  97. pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
  98. pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
  99. pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
  100. pythonagent/config.py +279 -0
  101. pythonagent/find.py +72 -0
  102. pythonagent/find_mod_cls_name.py +54 -0
  103. pythonagent/lang.py +131 -0
  104. pythonagent/lib.py +91 -0
  105. pythonagent/main/__init__.py +0 -0
  106. pythonagent/main/pytrace/__init__.py +79 -0
  107. pythonagent/main/pytrace/commands/__init__.py +0 -0
  108. pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
  109. pythonagent/main/pytrace/commands/run.py +401 -0
  110. pythonagent/main/pytrace/pytrace.py +133 -0
  111. pythonagent/main/wsgi.py +6 -0
  112. pythonagent/main.py +27 -0
  113. pythonagent/run.py +46 -0
  114. pythonagent/sqins.py +8 -0
  115. pythonagent/test.py +73 -0
  116. pythonagent/utils.py +168 -0
  117. pythonagent/vendor/__init__.py +0 -0
  118. pythonagent/vendor/pympler/__init__.py +1 -0
  119. pythonagent/vendor/pympler/asizeof.py +2810 -0
  120. pythonagent/vendor/pympler/charts.py +62 -0
  121. pythonagent/vendor/pympler/classtracker.py +590 -0
  122. pythonagent/vendor/pympler/classtracker_stats.py +780 -0
  123. pythonagent/vendor/pympler/garbagegraph.py +80 -0
  124. pythonagent/vendor/pympler/mprofile.py +97 -0
  125. pythonagent/vendor/pympler/muppy.py +275 -0
  126. pythonagent/vendor/pympler/panels.py +115 -0
  127. pythonagent/vendor/pympler/process.py +238 -0
  128. pythonagent/vendor/pympler/py.typed +0 -0
  129. pythonagent/vendor/pympler/refbrowser.py +451 -0
  130. pythonagent/vendor/pympler/refgraph.py +350 -0
  131. pythonagent/vendor/pympler/summary.py +321 -0
  132. pythonagent/vendor/pympler/tracker.py +267 -0
  133. pythonagent/vendor/pympler/util/__init__.py +0 -0
  134. pythonagent/vendor/pympler/util/bottle.py +3809 -0
  135. pythonagent/vendor/pympler/util/compat.py +23 -0
  136. pythonagent/vendor/pympler/util/stringutils.py +77 -0
  137. pythonagent/vendor/pympler/web.py +346 -0
  138. pythonagent/vendor/werkzeug/__init__.py +20 -0
  139. pythonagent/vendor/werkzeug/_compat.py +228 -0
  140. pythonagent/vendor/werkzeug/_internal.py +473 -0
  141. pythonagent/vendor/werkzeug/_reloader.py +341 -0
  142. pythonagent/vendor/werkzeug/datastructures.py +3120 -0
  143. pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
  144. pythonagent/vendor/werkzeug/debug/console.py +218 -0
  145. pythonagent/vendor/werkzeug/debug/repr.py +297 -0
  146. pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
  147. pythonagent/vendor/werkzeug/exceptions.py +829 -0
  148. pythonagent/vendor/werkzeug/filesystem.py +64 -0
  149. pythonagent/vendor/werkzeug/formparser.py +584 -0
  150. pythonagent/vendor/werkzeug/http.py +1307 -0
  151. pythonagent/vendor/werkzeug/local.py +420 -0
  152. pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
  153. pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
  154. pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
  155. pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
  156. pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
  157. pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
  158. pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
  159. pythonagent/vendor/werkzeug/posixemulation.py +117 -0
  160. pythonagent/vendor/werkzeug/routing.py +2210 -0
  161. pythonagent/vendor/werkzeug/security.py +249 -0
  162. pythonagent/vendor/werkzeug/serving.py +1117 -0
  163. pythonagent/vendor/werkzeug/test.py +1123 -0
  164. pythonagent/vendor/werkzeug/testapp.py +241 -0
  165. pythonagent/vendor/werkzeug/urls.py +1138 -0
  166. pythonagent/vendor/werkzeug/useragents.py +202 -0
  167. pythonagent/vendor/werkzeug/utils.py +778 -0
  168. pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
  169. pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
  170. pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
  171. pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
  172. pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
  173. pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
  174. pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
  175. pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
  176. pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
  177. pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
  178. pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
  179. pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
  180. pythonagent/vendor/werkzeug/wsgi.py +1000 -0
@@ -0,0 +1,267 @@
1
+ """The tracker module allows you to track changes in the memory usage over
2
+ time.
3
+
4
+ Using the SummaryTracker, you can create summaries and compare them
5
+ with each other. Stored summaries can be ignored during comparison,
6
+ avoiding the observer effect.
7
+
8
+ The ObjectTracker allows to monitor object creation. You create objects from
9
+ one time and compare with objects from an earlier time.
10
+
11
+ """
12
+ import gc
13
+ import inspect
14
+
15
+ from . import muppy, summary
16
+ from .util import compat
17
+
18
+
19
+ class SummaryTracker(object):
20
+ """ Helper class to track changes between two summaries taken.
21
+
22
+ Detailed information on single objects will be lost, e.g. object size or
23
+ object id. But often summaries are sufficient to monitor the memory usage
24
+ over the lifetime of an application.
25
+
26
+ On initialisation, a first summary is taken. Every time `diff` is called,
27
+ a new summary will be created. Thus, a diff between the new and the last
28
+ summary can be extracted.
29
+
30
+ Be aware that filtering out previous summaries is time-intensive. You
31
+ should therefore restrict yourself to the number of summaries you really
32
+ need.
33
+
34
+ """
35
+ def __init__(self, ignore_self=True):
36
+ """Constructor.
37
+
38
+ The number of summaries managed by the tracker has a performance
39
+ impact on new summaries, iff you decide to exclude them from further
40
+ summaries. Therefore it is suggested to use them economically.
41
+
42
+ Keyword arguments:
43
+ ignore_self -- summaries managed by this object will be ignored.
44
+ """
45
+ self.s0 = summary.summarize(muppy.get_objects())
46
+ self.summaries = {}
47
+ self.ignore_self = ignore_self
48
+
49
+ def create_summary(self):
50
+ """Return a summary.
51
+
52
+ See also the notes on ignore_self in the class as well as the
53
+ initializer documentation.
54
+
55
+ """
56
+ if not self.ignore_self:
57
+ res = summary.summarize(muppy.get_objects())
58
+ else:
59
+ # If the user requested the data required to store summaries to be
60
+ # ignored in the summaries, we need to identify all objects which
61
+ # are related to each summary stored.
62
+ # Thus we build a list of all objects used for summary storage as
63
+ # well as a dictionary which tells us how often an object is
64
+ # referenced by the summaries.
65
+ # During this identification process, more objects are referenced,
66
+ # namely int objects identifying referenced objects as well as the
67
+ # corresponding count.
68
+ # For all these objects it will be checked whether they are
69
+ # referenced from outside the monitor's scope. If not, they will be
70
+ # subtracted from the snapshot summary, otherwise they are
71
+ # included (as this indicates that they are relevant to the
72
+ # application).
73
+
74
+ all_of_them = [] # every single object
75
+ ref_counter = {} # how often it is referenced; (id(o), o) pairs
76
+
77
+ def store_info(o):
78
+ all_of_them.append(o)
79
+ if id(o) in ref_counter:
80
+ ref_counter[id(o)] += 1
81
+ else:
82
+ ref_counter[id(o)] = 1
83
+
84
+ # store infos on every single object related to the summaries
85
+ store_info(self.summaries)
86
+ for k, v in self.summaries.items():
87
+ store_info(k)
88
+ summary._traverse(v, store_info)
89
+
90
+ # do the summary
91
+ res = summary.summarize(muppy.get_objects())
92
+
93
+ # remove ids stored in the ref_counter
94
+ for _id in ref_counter:
95
+ # referenced in frame, ref_counter, ref_counter.keys()
96
+ if len(gc.get_referrers(_id)) == (3):
97
+ summary._subtract(res, _id)
98
+ for o in all_of_them:
99
+ # referenced in frame, summary, all_of_them
100
+ if len(gc.get_referrers(o)) == (ref_counter[id(o)] + 2):
101
+ summary._subtract(res, o)
102
+
103
+ return res
104
+
105
+ def diff(self, summary1=None, summary2=None):
106
+ """Compute diff between to summaries.
107
+
108
+ If no summary is provided, the diff from the last to the current
109
+ summary is used. If summary1 is provided the diff from summary1
110
+ to the current summary is used. If summary1 and summary2 are
111
+ provided, the diff between these two is used.
112
+
113
+ """
114
+ res = None
115
+ if summary2 is None:
116
+ self.s1 = self.create_summary()
117
+ if summary1 is None:
118
+ res = summary.get_diff(self.s0, self.s1)
119
+ else:
120
+ res = summary.get_diff(summary1, self.s1)
121
+ self.s0 = self.s1
122
+ else:
123
+ if summary1 is not None:
124
+ res = summary.get_diff(summary1, summary2)
125
+ else:
126
+ raise ValueError(
127
+ "You cannot provide summary2 without summary1.")
128
+ return summary._sweep(res)
129
+
130
+ def print_diff(self, summary1=None, summary2=None):
131
+ """Compute diff between to summaries and print it.
132
+
133
+ If no summary is provided, the diff from the last to the current
134
+ summary is used. If summary1 is provided the diff from summary1
135
+ to the current summary is used. If summary1 and summary2 are
136
+ provided, the diff between these two is used.
137
+ """
138
+ summary.print_(self.diff(summary1=summary1, summary2=summary2))
139
+
140
+ def format_diff(self, summary1=None, summary2=None):
141
+ """Compute diff between to summaries and return a list of formatted
142
+ lines.
143
+
144
+ If no summary is provided, the diff from the last to the current
145
+ summary is used. If summary1 is provided the diff from summary1
146
+ to the current summary is used. If summary1 and summary2 are
147
+ provided, the diff between these two is used.
148
+ """
149
+ return summary.format_(self.diff(summary1=summary1, summary2=summary2))
150
+
151
+ def store_summary(self, key):
152
+ """Store a current summary in self.summaries."""
153
+ self.summaries[key] = self.create_summary()
154
+
155
+
156
+ class ObjectTracker(object):
157
+ """
158
+ Helper class to track changes in the set of existing objects.
159
+
160
+ Each time you invoke a diff with this tracker, the objects which existed
161
+ during the last invocation are compared with the objects which exist during
162
+ the current invocation.
163
+
164
+ Please note that in order to do so, strong references to all objects will
165
+ be stored. This means that none of these objects can be garbage collected.
166
+ A use case for the ObjectTracker is the monitoring of a state which should
167
+ be stable, but you see new objects being created nevertheless. With the
168
+ ObjectTracker you can identify these new objects.
169
+
170
+ """
171
+
172
+ # Some precaution needs to be taken when handling frame objects (see
173
+ # warning at http://docs.python.org/lib/inspect-stack.html). All ignore
174
+ # lists used need to be emptied so no frame objects remain referenced.
175
+
176
+ def __init__(self):
177
+ """On initialisation, the current state of objects is stored.
178
+
179
+ Note that all objects which exist at this point in time will not be
180
+ released until you destroy this ObjectTracker instance.
181
+ """
182
+ self.o0 = self._get_objects(ignore=(inspect.currentframe(),))
183
+
184
+ def _get_objects(self, ignore=()):
185
+ """Get all currently existing objects.
186
+
187
+ XXX - ToDo: This method is a copy&paste from muppy.get_objects, but
188
+ some modifications are applied. Specifically, it allows to ignore
189
+ objects (which includes the current frame).
190
+
191
+ keyword arguments
192
+ ignore -- list of objects to ignore
193
+ """
194
+ def remove_ignore(objects, ignore=()):
195
+ # remove all objects listed in the ignore list
196
+ res = []
197
+ for o in objects:
198
+ if not compat.object_in_list(o, ignore):
199
+ res.append(o)
200
+ return res
201
+
202
+ tmp = gc.get_objects()
203
+ ignore += (inspect.currentframe(), self, ignore, remove_ignore)
204
+ if hasattr(self, 'o0'):
205
+ ignore += (self.o0,)
206
+ if hasattr(self, 'o1'):
207
+ ignore += (self.o1,)
208
+ # this implies that referenced objects are also ignored
209
+ tmp = remove_ignore(tmp, ignore)
210
+ res = []
211
+ for o in tmp:
212
+ # gc.get_objects returns only container objects, but we also want
213
+ # the objects referenced by them
214
+ refs = muppy.get_referents(o)
215
+ for ref in refs:
216
+ if not gc.is_tracked(ref):
217
+ # we already got the container objects, now we only add
218
+ # non-container objects
219
+ res.append(ref)
220
+ res.extend(tmp)
221
+ res = muppy._remove_duplicates(res)
222
+ if ignore is not None:
223
+ # repeat to filter out objects which may have been referenced
224
+ res = remove_ignore(res, ignore)
225
+ # manual cleanup, see comment above
226
+ del ignore
227
+ return res
228
+
229
+ def get_diff(self, ignore=()):
230
+ """Get the diff to the last time the state of objects was measured.
231
+
232
+ keyword arguments
233
+ ignore -- list of objects to ignore
234
+ """
235
+ # ignore this and the caller frame
236
+ self.o1 = self._get_objects(ignore+(inspect.currentframe(),))
237
+ diff = muppy.get_diff(self.o0, self.o1)
238
+ self.o0 = self.o1
239
+ # manual cleanup, see comment above
240
+ return diff
241
+
242
+ def print_diff(self, ignore=()):
243
+ """Print the diff to the last time the state of objects was measured.
244
+
245
+ keyword arguments
246
+ ignore -- list of objects to ignore
247
+ """
248
+ # ignore this and the caller frame
249
+ for line in self.format_diff(ignore+(inspect.currentframe(),)):
250
+ print(line)
251
+
252
+ def format_diff(self, ignore=()):
253
+ """Format the diff to the last time the state of objects was measured.
254
+
255
+ keyword arguments
256
+ ignore -- list of objects to ignore
257
+ """
258
+ # ignore this and the caller frame
259
+ lines = []
260
+ diff = self.get_diff(ignore+(inspect.currentframe(),))
261
+ lines.append("Added objects:")
262
+ for line in summary.format_(summary.summarize(diff['+'])):
263
+ lines.append(line)
264
+ lines.append("Removed objects:")
265
+ for line in summary.format_(summary.summarize(diff['-'])):
266
+ lines.append(line)
267
+ return lines
File without changes