You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/tools/recorded-call-graph-metrics/README.md
+106-7Lines changed: 106 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,113 @@ also known as _call graph tracing_.
4
4
5
5
Execute a python program and for each call being made, record the call and callee. This allows us to compare call graph resolution from static analysis with actual data -- that is, can we statically determine the target of each actual call correctly.
6
6
7
-
This is still in the early stages, and currently only supports a very minimal working example (to show that this approach might work).
7
+
Using the call graph tracer does incur a heavy toll on the performance. Expect 10x longer to execute the program.
8
8
9
-
The next hurdle is being able to handle multiple calls on the same line, such as
9
+
Number of calls recorded vary a little from run to run. I have not been able to pinpoint why.
10
10
11
-
-`foo(); bar()`
12
-
-`foo(bar())`
13
-
-`foo().bar()`
11
+
## Running against real projects
14
12
15
-
## How do I give it a spin?
13
+
Currently it's possible to gather metrics from traced runs of the standard test suite of a few projects (defined in [projects.json](./projects.json)): `youtube-dl`, `wcwidth`, and `flask`.
16
14
17
-
Run the `recreate-db.sh` script to create the database `cg-trace-example-db`, which will include the `example/simple.xml` trace from executing the `example/simple.py` code. Then run the queries inside the `ql/` directory.
15
+
To run against all projects, use
16
+
17
+
```bash
18
+
$ ./helper.sh all $(./helper.sh projects)
19
+
```
20
+
21
+
To view the results, use
22
+
```
23
+
$ head -n 100 projects/*/Metrics.txt
24
+
```
25
+
26
+
### Expanding set of projects
27
+
28
+
It should be fairly straightforward to expand the set of projects. Most projects use `tox` for running their tests against multiple python versions. I didn't look into any kind of integration, but have manually picked out the instructions required to get going.
29
+
30
+
As an example, compare the [`tox.ini`](https://github.com/pallets/flask/blob/21c3df31de4bc2f838c945bd37d185210d9bab1a/tox.ini) file from flask with the configuration
You can also run traces for all tests and build a database by running `tests/create-test-db.sh`. Then run the queries inside the `ql/` directory.
88
+
89
+
## Tracing Limitations
90
+
91
+
### Multi-threading
92
+
93
+
Should be possible by using [`threading.setprofile`](https://docs.python.org/3.8/library/threading.html#threading.setprofile), but that hasn't been done yet.
94
+
95
+
### Code that uses `sys.setprofile`
96
+
97
+
Since that is our mechanism for recording calls, any code that uses `sys.setprofile` will not work together with the call-graph tracer.
98
+
99
+
### Class instantiation
100
+
101
+
Does not always fire off an event in the `sys.setprofile` function (neither in `sys.settrace`), so is not recorded. Example:
0 commit comments