Skip to content

Commit 672804b

Browse files
committed
Update v3/docs/opt-trace-format.md
1 parent 29e2246 commit 672804b

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

‎v3/docs/opt-trace-format.md‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,89 @@ which corresponds to the Python object `(1, c)`.
483483
The ability to put "REF" objects inside of heap objects enables an arbitrary object graph to be
484484
represented in the execution trace.
485485

486+
## stdout output
487+
488+
The `stdout` field in an execution point object represents the sum total of all output sent to stdout
489+
so far during execution. For example, given this program:
490+
491+
```python
492+
print 1
493+
print "two"
494+
print (3, 4, 5)
495+
```
496+
497+
The complete trace object is:
498+
499+
```javascript
500+
{
501+
"code": "print 1\nprint \"two\"\nprint (3, 4, 5)\n\n",
502+
"trace": [
503+
{
504+
"ordered_globals": [],
505+
"stdout": "",
506+
"func_name": "<module>",
507+
"stack_to_render": [],
508+
"globals": {},
509+
"heap": {},
510+
"line": 1,
511+
"event": "step_line"
512+
},
513+
{
514+
"ordered_globals": [],
515+
"stdout": "1\n",
516+
"func_name": "<module>",
517+
"stack_to_render": [],
518+
"globals": {},
519+
"heap": {},
520+
"line": 2,
521+
"event": "step_line"
522+
},
523+
{
524+
"ordered_globals": [],
525+
"stdout": "1\ntwo\n",
526+
"func_name": "<module>",
527+
"stack_to_render": [],
528+
"globals": {},
529+
"heap": {},
530+
"line": 3,
531+
"event": "step_line"
532+
},
533+
{
534+
"ordered_globals": [],
535+
"stdout": "1\ntwo\n(3, 4, 5)\n",
536+
"func_name": "<module>",
537+
"stack_to_render": [],
538+
"globals": {},
539+
"heap": {},
540+
"line": 3,
541+
"event": "return"
542+
}
543+
]
544+
}
545+
```
546+
547+
By now you should be getting pretty good at reading these objects :)
548+
549+
Let's just focus on the `stdout` field at each execution point. Note that its contents start as an empty string
550+
at the beginning of execution and then grow incrementally as more stuff is printed to stdout at each
551+
subsequent execution point. If we grep for `stdout` in the trace, we see the following progression:
552+
553+
```javascript
554+
"stdout": "",
555+
"stdout": "1\n",
556+
"stdout": "1\ntwo\n",
557+
"stdout": "1\ntwo\n(3, 4, 5)\n",
558+
```
559+
560+
This isn't rocket science; but just be aware that `stdout` contains the cumulative contents of the stdout
561+
buffer up to that execution point, not only what's just been printed by the last executed line.
562+
486563

487564
## Function Stack Frames
488565

489566
(TODO: WRITE ME!)
567+
568+
569+
## Closures and Zombie Frames (advanced)
570+
571+
(TODO: WRITE ME!)

0 commit comments

Comments
 (0)