functiontrace 0.4.0__tar.gz → 0.4.3__tar.gz

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.
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "_functiontrace_rs"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ color-eyre = { version = "0.6", default-features = false }
8
+ functiontrace-server = { version = "0.8.4", default-features = false, features = ["serialize"] }
9
+ libc = "0.2"
10
+ pyo3 = { version = "0.25", features = ["eyre"] }
11
+ rmp-serde = "1.3"
12
+ serde = "1"
13
+
14
+ [build-dependencies]
15
+ toml = { version = "0.8", default-features = false, features = ["parse"] }
16
+ pyo3-build-config = { version = "0.25", features = ["resolve-config"] }
17
+
18
+ [lib]
19
+ # See https://github.com/PyO3/pyo3 for details
20
+ name = "_functiontrace_rs" # private module to be nested into Python package
21
+ crate-type = ["cdylib"]
22
+ path = "rust/lib.rs"
@@ -0,0 +1,57 @@
1
+ # The Prosperity Public License 3.0.0
2
+
3
+ Contributor: Matt Bryant, Alistair Dobke
4
+
5
+ Source Code: https://gitlab.com/mbryant/functiontrace (https://functiontrace.com)
6
+
7
+ ## Purpose
8
+
9
+ This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
10
+
11
+ ## Agreement
12
+
13
+ In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
14
+
15
+ ## Notices
16
+
17
+ Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
18
+
19
+ ## Commercial Trial
20
+
21
+ Limit your use of this software for commercial purposes to a thirty-day trial period. If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
22
+
23
+ ## Contributions Back
24
+
25
+ Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
26
+
27
+ ## Personal Uses
28
+
29
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
30
+
31
+ ## Noncommercial Organizations
32
+
33
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
34
+
35
+ ## Defense
36
+
37
+ Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
38
+
39
+ ## Copyright
40
+
41
+ The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
42
+
43
+ ## Patent
44
+
45
+ The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
46
+
47
+ ## Reliability
48
+
49
+ The contributor can't revoke this license.
50
+
51
+ ## Excuse
52
+
53
+ You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
54
+
55
+ ## No Liability
56
+
57
+ ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
@@ -1,3 +1,4 @@
1
1
  graft mpack
2
2
  graft rust
3
3
  include Cargo.toml
4
+ include build.rs
@@ -1,23 +1,24 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: functiontrace
3
- Version: 0.4.0
3
+ Version: 0.4.3
4
4
  Summary: A profiling tool that traces your application's execution
5
5
  Author: Alistair Dobke
6
6
  Author-email: Matt Bryant <functiontrace@programsareproofs.com>
7
- License: The Prosperity Public License 3.0.0
7
+ License-Expression: LicenseRef-Prosperity-Public-License-3.0.0
8
8
  Project-URL: homepage, https://functiontrace.com
9
9
  Project-URL: repository, https://gitlab.com/mbryant/functiontrace
10
10
  Keywords: profiler,debugger
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Topic :: Software Development :: Debuggers
13
- Classifier: License :: Free for non-commercial use
14
13
  Classifier: Operating System :: Unix
15
14
  Classifier: Environment :: Console
16
15
  Classifier: Programming Language :: Python :: 3
17
16
  Classifier: Programming Language :: Python :: 3 :: Only
18
17
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
- Requires-Python: >=3.7
18
+ Requires-Python: >=3.9
20
19
  Description-Content-Type: text/x-rst
20
+ License-File: LICENSE.md
21
+ Dynamic: license-file
21
22
 
22
23
  Py-Functiontrace
23
24
  ================
@@ -0,0 +1,160 @@
1
+ #include <Python.h>
2
+ #include <frameobject.h>
3
+ #include <sys/types.h>
4
+ #include <pthread.h>
5
+ #include <stdio.h>
6
+ #include <stdbool.h>
7
+ #include <unistd.h>
8
+
9
+ #include "mpack/mpack.h"
10
+
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // Prototypes
13
+ ////////////////////////////////////////////////////////////////////////////////
14
+ static int Fprofile_FunctionTrace(PyObject* obj, PyFrameObject* frame, int what, PyObject* arg);
15
+
16
+ ////////////////////////////////////////////////////////////////////////////////
17
+ // Globals
18
+ ////////////////////////////////////////////////////////////////////////////////
19
+ // This key is used to fetch the thread local instance of the `Writer`
20
+ // structure.
21
+ static pthread_key_t Tss_Key = 0;
22
+
23
+ // The exposed apis of the Rust extension.
24
+ static struct {
25
+ pthread_key_t (*set_config)(int (*functiontrace)(PyObject*, PyFrameObject*, int, PyObject*));
26
+ }* rust;
27
+
28
+ ////////////////////////////////////////////////////////////////////////////////
29
+ // Misc
30
+ ////////////////////////////////////////////////////////////////////////////////
31
+
32
+ // Given a PyObject (likely `co_name` or similar), return a UTF-8
33
+ // representation.
34
+ static inline const char* Fprofile_UnicodeToUtf8(PyObject* obj) {
35
+ if (obj == NULL) {
36
+ return "<NULL>";
37
+ }
38
+
39
+ if (PyUnicode_Check(obj)) {
40
+ const char* utf8 = PyUnicode_AsUTF8(obj);
41
+
42
+ return utf8 != NULL ? utf8 : "<DECODE ERROR>";
43
+ } else if (obj == Py_None) {
44
+ return "<NONE>";
45
+ } else {
46
+ return "<UNKNOWN>";
47
+ }
48
+ }
49
+
50
+ ////////////////////////////////////////////////////////////////////////////////
51
+ // Callbacks
52
+ ////////////////////////////////////////////////////////////////////////////////
53
+ static int Fprofile_FunctionTrace(PyObject* obj, PyFrameObject* frame, int what, PyObject* arg) {
54
+ struct timespec tsc = { 0 };
55
+
56
+ // This is called from the Rust code, which has already checked that
57
+ // everything is configured to send messages.
58
+ mpack_writer_t* writer = pthread_getspecific(Tss_Key);
59
+
60
+ clock_gettime(CLOCK_MONOTONIC, &tsc);
61
+
62
+ switch (what) {
63
+ case PyTrace_CALL:
64
+ mpack_start_array(writer, 5);
65
+ mpack_write_cstr(writer, "Call");
66
+
67
+ mpack_start_array(writer, 2);
68
+ mpack_write_u32(writer, tsc.tv_sec);
69
+ mpack_write_u32(writer, tsc.tv_nsec);
70
+ mpack_finish_array(writer);
71
+
72
+ {
73
+ PyCodeObject* code = PyFrame_GetCode(frame);
74
+ int lineno = PyFrame_GetLineNumber(frame);
75
+
76
+ #if PY_VERSION_HEX >= 0x030b00a0
77
+ mpack_write_cstr(writer, Fprofile_UnicodeToUtf8(code->co_qualname));
78
+ #else
79
+ mpack_write_cstr(writer, Fprofile_UnicodeToUtf8(code->co_name));
80
+ #endif
81
+ mpack_write_cstr(writer, Fprofile_UnicodeToUtf8(code->co_filename));
82
+ mpack_write_u32(writer, lineno);
83
+
84
+ Py_DECREF(code);
85
+ }
86
+ mpack_finish_array(writer);
87
+ break;
88
+ case PyTrace_RETURN:
89
+ mpack_start_array(writer, 3);
90
+ mpack_write_cstr(writer, "Return");
91
+
92
+ mpack_start_array(writer, 2);
93
+ mpack_write_u32(writer, tsc.tv_sec);
94
+ mpack_write_u32(writer, tsc.tv_nsec);
95
+ mpack_finish_array(writer);
96
+
97
+ {
98
+ PyCodeObject* code = PyFrame_GetCode(frame);
99
+
100
+ #if PY_VERSION_HEX >= 0x030b00a0
101
+ mpack_write_cstr(writer, Fprofile_UnicodeToUtf8(code->co_qualname));
102
+ #else
103
+ mpack_write_cstr(writer, Fprofile_UnicodeToUtf8(code->co_name));
104
+ #endif
105
+
106
+ Py_DECREF(code);
107
+ }
108
+ mpack_finish_array(writer);
109
+ break;
110
+ default:
111
+ perror("Impossible C case");
112
+ break;
113
+ }
114
+
115
+ return 0;
116
+ }
117
+
118
+ ////////////////////////////////////////////////////////////////////////////////
119
+ // Module Initialization
120
+ ////////////////////////////////////////////////////////////////////////////////
121
+
122
+ // The set of methods exposed by this module to Python.
123
+ static PyMethodDef methods[] = {
124
+ [0] = {NULL, NULL, 0, NULL}
125
+ };
126
+
127
+ static PyModuleDef module = {
128
+ PyModuleDef_HEAD_INIT,
129
+ "_functiontrace",
130
+ "",
131
+ -1,
132
+ methods
133
+ };
134
+
135
+ PyMODINIT_FUNC PyInit__functiontrace(void) {
136
+ // Setup our janky Rust dlopen alternative so we can use Rust code.
137
+ PyObject* rust_mod = PyImport_ImportModule("_functiontrace_rs");
138
+
139
+ // Verify that the rust extension loads if we're using it.
140
+ if (rust_mod == NULL) {
141
+ perror("Failed to load internal Rust extension");
142
+ exit(-1);
143
+ }
144
+
145
+ // This returns a pointer to the C API exposed by the Rust module.
146
+ PyObject* py_c_api = PyObject_GetAttrString(rust_mod, "c_api");
147
+ if (py_c_api == NULL) {
148
+ perror("Failed to initialize FunctionTrace Rust<->C interface");
149
+ exit(-1);
150
+ }
151
+ PyObject* c_api = PyObject_CallFunctionObjArgs(py_c_api, NULL);
152
+
153
+ // Save the Rust vtable so everyone can access it
154
+ rust = PyLong_AsVoidPtr(c_api);
155
+
156
+ // Share our globals with Rust
157
+ Tss_Key = rust->set_config(Fprofile_FunctionTrace);
158
+
159
+ return PyModule_Create(&module);
160
+ }
@@ -0,0 +1,20 @@
1
+ fn main() -> std::io::Result<()> {
2
+ println!("cargo::rerun-if-changed=pyproject.toml");
3
+
4
+ // Read pyproject.toml to expose our version to the Rust extension
5
+ let pyproject = std::fs::read_to_string("pyproject.toml")?
6
+ .parse::<toml::Table>()
7
+ .expect("pyproject.toml is valid toml");
8
+ let version = pyproject
9
+ .get("project")
10
+ .and_then(|p| p.as_table())
11
+ .and_then(|p| p.get("version"))
12
+ .and_then(|v| v.as_str())
13
+ .expect("version field is present in pyproject.toml");
14
+ println!("cargo::rustc-env=PACKAGE_VERSION={}", version);
15
+
16
+ // Figure out which Python version we're building for
17
+ pyo3_build_config::use_pyo3_cfgs();
18
+
19
+ Ok(())
20
+ }
@@ -1,23 +1,24 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: functiontrace
3
- Version: 0.4.0
3
+ Version: 0.4.3
4
4
  Summary: A profiling tool that traces your application's execution
5
5
  Author: Alistair Dobke
6
6
  Author-email: Matt Bryant <functiontrace@programsareproofs.com>
7
- License: The Prosperity Public License 3.0.0
7
+ License-Expression: LicenseRef-Prosperity-Public-License-3.0.0
8
8
  Project-URL: homepage, https://functiontrace.com
9
9
  Project-URL: repository, https://gitlab.com/mbryant/functiontrace
10
10
  Keywords: profiler,debugger
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Topic :: Software Development :: Debuggers
13
- Classifier: License :: Free for non-commercial use
14
13
  Classifier: Operating System :: Unix
15
14
  Classifier: Environment :: Console
16
15
  Classifier: Programming Language :: Python :: 3
17
16
  Classifier: Programming Language :: Python :: 3 :: Only
18
17
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
- Requires-Python: >=3.7
18
+ Requires-Python: >=3.9
20
19
  Description-Content-Type: text/x-rst
20
+ License-File: LICENSE.md
21
+ Dynamic: license-file
21
22
 
22
23
  Py-Functiontrace
23
24
  ================
@@ -1,7 +1,9 @@
1
1
  Cargo.toml
2
+ LICENSE.md
2
3
  MANIFEST.in
3
4
  README.rst
4
5
  _functiontrace.c
6
+ build.rs
5
7
  functiontrace.py
6
8
  pyproject.toml
7
9
  setup.py
@@ -5,7 +5,8 @@ import sys
5
5
  import tempfile
6
6
  from importlib import machinery, util
7
7
 
8
- import _functiontrace
8
+ import _functiontrace # noqa: F401 - this import is load bearing since we need to run code on import
9
+ import _functiontrace_rs as rust
9
10
 
10
11
  PYTHON_TEMPLATE = """#!/bin/sh
11
12
 
@@ -70,9 +71,7 @@ def main():
70
71
  action="store_true",
71
72
  help="Disable compression of traces, which can be unnecessarily slow if filesize is not a concern.",
72
73
  )
73
- parser.add_argument(
74
- "-v", "--version", action="version", version=_functiontrace.__version__
75
- )
74
+ parser.add_argument("-v", "--version", action="version", version=rust.__version__)
76
75
  parser.add_argument("script", nargs=argparse.REMAINDER)
77
76
  args = parser.parse_args()
78
77
 
@@ -114,8 +113,8 @@ def main():
114
113
  if args.no_compression:
115
114
  os.environ["FUNCTIONTRACE_COMPRESSION"] = "false"
116
115
  if args.trace_memory:
117
- _functiontrace.config_tracememory()
118
- _functiontrace.begin_tracing(args.output_dir)
116
+ rust.enable_tracememory()
117
+ rust.begin_tracing(args.output_dir)
119
118
 
120
119
  # Run their code now that we're tracing. This must be done in the context
121
120
  # of the __main__ module we've created.
@@ -125,7 +124,7 @@ def main():
125
124
  def trace():
126
125
  # Make sure we're set up to work properly, then begin tracing.
127
126
  setup_dependencies()
128
- _functiontrace.begin_tracing(os.getcwd())
127
+ rust.begin_tracing(os.getcwd())
129
128
 
130
129
 
131
130
  if __name__ == "__main__":
@@ -1,20 +1,21 @@
1
1
  [project]
2
2
  name = "functiontrace"
3
- version = "0.4.0"
3
+ version = "0.4.3"
4
4
  description = "A profiling tool that traces your application's execution"
5
5
  authors = [
6
6
  { name = "Matt Bryant", email = "functiontrace@programsareproofs.com"},
7
7
  { name = "Alistair Dobke" }
8
8
  ]
9
- license = { text = "The Prosperity Public License 3.0.0" }
9
+ license = "LicenseRef-Prosperity-Public-License-3.0.0"
10
+ license-files = ["LICENSE.md"]
10
11
  readme = "README.rst"
11
- # NOTE: Actively tested on Python 3.7 - 3.12 and may plausibly break on greater
12
+ # NOTE: Actively tested on Python 3.9 - 3.13 and may plausibly break on greater
12
13
  # versions due to C extension hacks. However, setting a maximum version causes
13
14
  # new Python versions to simply install very old versions of Functiontrace that
14
15
  # didn't have the `requires-python` annotation on them and are also unlikely to
15
16
  # work. Best to only set the minimum and let bug reports notify us of issues
16
17
  # with new Python releases.
17
- requires-python = ">=3.7"
18
+ requires-python = ">=3.9"
18
19
  keywords = [
19
20
  "profiler",
20
21
  "debugger"
@@ -22,7 +23,6 @@ keywords = [
22
23
  classifiers = [
23
24
  "Intended Audience :: Developers",
24
25
  "Topic :: Software Development :: Debuggers",
25
- "License :: Free for non-commercial use",
26
26
  "Operating System :: Unix",
27
27
  "Environment :: Console",
28
28
  "Programming Language :: Python :: 3",
@@ -41,9 +41,9 @@ functiontrace = "functiontrace:main"
41
41
  functiontrace = "functiontrace"
42
42
 
43
43
  [build-system]
44
- requires = ["setuptools", "toml", "setuptools-rust"]
44
+ requires = ["setuptools", "setuptools-rust"]
45
45
  build-backend = "setuptools.build_meta"
46
46
 
47
47
  [[tool.setuptools-rust.ext-modules]]
48
- target = "_functiontrace_rs._lib" # Must match `lib.name` in Cargo.toml
48
+ target = "_functiontrace_rs" # Must match `lib.name` in Cargo.toml
49
49
  binding = "PyO3"