2015-03-04 16:16:18 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
2016-08-31 14:12:52 +00:00
|
|
|
(provide current-trace-procedures
|
2016-08-25 17:07:27 +00:00
|
|
|
trace-turn-begin
|
|
|
|
trace-turn-end
|
|
|
|
trace-actor-spawn
|
|
|
|
trace-actor-exit
|
2017-08-12 04:08:09 +00:00
|
|
|
trace-action-interpreted
|
|
|
|
trace-actions-produced
|
2016-08-25 17:07:27 +00:00
|
|
|
trace-event-consumed
|
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
trace-timestamp!
|
|
|
|
(struct-out spacetime)
|
2016-08-25 17:07:27 +00:00
|
|
|
(struct-out trace-notification))
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2016-07-20 22:54:31 +00:00
|
|
|
(require "hierarchy.rkt")
|
2015-05-11 22:25:21 +00:00
|
|
|
(require "pretty.rkt")
|
2016-09-02 16:55:46 +00:00
|
|
|
(require "store.rkt")
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
;; A NotificationType is one of
|
|
|
|
;; -- 'turn-begin
|
|
|
|
;; -- 'turn-end
|
|
|
|
;; -- 'spawn
|
|
|
|
;; -- 'exit
|
2017-08-12 04:08:09 +00:00
|
|
|
;; -- 'action-interpreted
|
|
|
|
;; -- 'actions-produced
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'event
|
2017-08-13 23:58:48 +00:00
|
|
|
|
|
|
|
;; A Moment is a Natural representing an abstract increasing counter,
|
|
|
|
;; unique for a Racket VM instance. It names a specific moment in the
|
|
|
|
;; interpretation of a Syndicate configuration.
|
|
|
|
|
|
|
|
;; A SpaceTime is either a (spacetime ActorPath Moment) or #f. When
|
|
|
|
;; non-#f, it names a specific point in the actor hierarchy ("space")
|
|
|
|
;; along with a point in time ("time"). When #f, it signifies
|
|
|
|
;; "unknown".
|
|
|
|
(struct spacetime (space time) #:prefab)
|
|
|
|
|
|
|
|
;; A TraceNotification is a (trace-notification SpaceTime SpaceTime NotificationType TraceDetail).
|
|
|
|
;; It represents an event in a Syndicate hierarchy.
|
|
|
|
(struct trace-notification (source sink type detail) #:prefab)
|
2016-08-25 17:07:27 +00:00
|
|
|
;;
|
2017-08-13 23:58:48 +00:00
|
|
|
;; A TraceDetail represents information about a specific
|
|
|
|
;; NotificationType, and so depends on the particular NotificationType
|
|
|
|
;; being used:
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'turn-begin and 'turn-end --> Process
|
2017-08-13 23:58:48 +00:00
|
|
|
;; -- 'spawn --> Process, the new process' initial state
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'exit --> Option Exception
|
2017-08-12 04:08:09 +00:00
|
|
|
;; -- 'action-interpreted --> (U Event 'quit) (notably, spawns are handled otherwise)
|
|
|
|
;; -- 'actions-produced --> (Listof (U Action 'quit)) (spawns included!)
|
2017-08-13 23:58:48 +00:00
|
|
|
;; -- 'event --> (list SpaceTime Event) ;; point describes action that led to this event,
|
|
|
|
;; ;; thus capturing the information of the former
|
|
|
|
;; ;; "causal influence" NotificationType.
|
2016-08-25 17:07:27 +00:00
|
|
|
;;
|
2017-08-13 23:58:48 +00:00
|
|
|
;; The source and sink fields both hold values of type SpaceTime. They
|
2016-08-25 17:07:27 +00:00
|
|
|
;; are, again, used differently for each NotificationType:
|
|
|
|
;; -- 'turn-begin --> source is dataspace; sink the process whose turn it is
|
|
|
|
;; -- 'turn-end --> source is dataspace; sink the process whose turn it was
|
2017-08-13 23:58:48 +00:00
|
|
|
;; -- 'spawn --> source is parent process; sink the new process
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'exit --> source is dataspace; sink the exiting process
|
2017-08-12 04:08:09 +00:00
|
|
|
;; -- 'action-interpreted --> source is acting process; sink is dataspace (NB: Flipped!)
|
2017-08-13 23:58:48 +00:00
|
|
|
;; -- 'actions-produced --> source and sink are both acting process; source = turn-end or spawn
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'event --> source is dataspace; sink is receiving process
|
|
|
|
|
2016-09-02 16:55:46 +00:00
|
|
|
(define current-trace-procedures (make-store #:default-box (box '())))
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define *current-moment* 0)
|
|
|
|
(define (moment!)
|
|
|
|
(local-require ffi/unsafe/atomic)
|
|
|
|
(call-as-atomic (lambda ()
|
|
|
|
(begin0 *current-moment*
|
|
|
|
(set! *current-moment* (+ *current-moment* 1))))))
|
|
|
|
|
|
|
|
(define (trace-timestamp! actor-path)
|
|
|
|
(spacetime actor-path (moment!)))
|
|
|
|
|
|
|
|
(define-syntax-rule (notify! SRC SNK TYP DET)
|
2016-08-31 14:12:52 +00:00
|
|
|
(let ((trace-procedures (current-trace-procedures)))
|
2017-08-13 23:58:48 +00:00
|
|
|
(cond [(pair? trace-procedures)
|
|
|
|
(define snk SNK)
|
|
|
|
(define n (trace-notification SRC snk TYP DET))
|
|
|
|
(for-each (lambda (procedure) (procedure n)) trace-procedures)
|
|
|
|
snk]
|
|
|
|
[else 'trace-collection-disabled])))
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2015-03-21 21:30:48 +00:00
|
|
|
(define (cons-pid pid)
|
|
|
|
(if pid
|
2016-07-20 22:54:31 +00:00
|
|
|
(cons pid (current-actor-path-rev))
|
|
|
|
(current-actor-path-rev)))
|
2015-03-21 21:30:48 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-turn-begin source pid p)
|
|
|
|
(notify! source (trace-timestamp! (cons-pid pid)) 'turn-begin p))
|
2016-08-25 17:07:27 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-turn-end source pid p)
|
|
|
|
(notify! source (trace-timestamp! (cons-pid pid)) 'turn-end p))
|
2016-08-25 17:07:27 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-actor-spawn source pid p)
|
|
|
|
(notify! source (trace-timestamp! (cons-pid pid)) 'spawn p))
|
2015-03-21 16:30:10 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-actor-exit source pid maybe-exn)
|
|
|
|
(notify! source (trace-timestamp! (cons-pid pid)) 'exit maybe-exn))
|
2017-08-12 04:08:09 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-action-interpreted source _pid e)
|
|
|
|
(notify! source (trace-timestamp! (current-actor-path-rev)) 'action-interpreted e))
|
2015-03-21 16:30:10 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-actions-produced source pid es)
|
|
|
|
(notify! source (trace-timestamp! (cons-pid pid)) 'actions-produced es))
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2017-08-13 23:58:48 +00:00
|
|
|
(define (trace-event-consumed interpreted-point ;; direct cause
|
|
|
|
produced-point ;; one-step indirect cause
|
|
|
|
pid ;; recipient
|
|
|
|
e)
|
|
|
|
(notify! interpreted-point (trace-timestamp! (cons-pid pid)) 'event (list produced-point e)))
|