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
|
|
|
|
trace-action-produced
|
|
|
|
trace-event-consumed
|
|
|
|
trace-causal-influence
|
|
|
|
|
|
|
|
(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
|
|
|
|
;; -- 'action
|
|
|
|
;; -- 'event
|
|
|
|
;; -- 'influence
|
|
|
|
;;
|
|
|
|
;; The trace-notification-detail field is used differently for each
|
|
|
|
;; NotificationType:
|
|
|
|
;; -- 'turn-begin and 'turn-end --> Process
|
2016-08-31 18:12:05 +00:00
|
|
|
;; -- 'spawn --> (list PID Process), the parent's PID and the process' initial state
|
2016-08-25 17:07:27 +00:00
|
|
|
;; -- 'exit --> Option Exception
|
|
|
|
;; -- 'action --> (U Event 'quit) (notably, spawns are handled otherwise)
|
|
|
|
;; -- 'event --> Event
|
|
|
|
;; -- 'influence --> Event
|
|
|
|
;;
|
|
|
|
;; The source and sink fields both hold values of type ActorPath. They
|
|
|
|
;; 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
|
|
|
|
;; -- 'spawn --> source is dataspace; sink the new process
|
|
|
|
;; -- 'exit --> source is dataspace; sink the exiting process
|
|
|
|
;; -- 'action --> source is acting process; sink is dataspace (NB: Flipped!)
|
|
|
|
;; -- 'event --> source is dataspace; sink is receiving process
|
|
|
|
;; -- 'influence --> source is acting process; sink is receiving process
|
|
|
|
;;
|
|
|
|
;; For 'influence, when the detail event is a patch, the source field
|
|
|
|
;; is not always the true influencing party. In the case where a
|
|
|
|
;; process adds new observe assertions to a dataspace where matching
|
|
|
|
;; assertions already exist, it will appear to "influence itself".
|
|
|
|
;; Really, with patches, it's the PIDs at the leaves of each patch's
|
|
|
|
;; tries that are the influencers.
|
|
|
|
|
|
|
|
(struct trace-notification (source sink type detail) #:prefab)
|
|
|
|
|
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
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
(define-syntax-rule (notify! src snk typ det)
|
2016-08-31 14:12:52 +00:00
|
|
|
(let ((trace-procedures (current-trace-procedures)))
|
|
|
|
(when (pair? trace-procedures)
|
|
|
|
(define n (trace-notification src snk typ det))
|
|
|
|
(for-each (lambda (procedure) (procedure n)) trace-procedures))))
|
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
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
;; PID Process
|
|
|
|
(define (trace-turn-begin pid p)
|
|
|
|
(notify! (current-actor-path-rev) (cons-pid pid) 'turn-begin p))
|
|
|
|
|
|
|
|
;; PID Process
|
|
|
|
(define (trace-turn-end pid p)
|
|
|
|
(notify! (current-actor-path-rev) (cons-pid pid) 'turn-end p))
|
|
|
|
|
|
|
|
;; PID PID Process
|
|
|
|
(define (trace-actor-spawn parent-pid pid p)
|
2016-08-31 18:12:05 +00:00
|
|
|
(notify! (current-actor-path-rev) (cons-pid pid) 'spawn (list (cons-pid parent-pid) p)))
|
2016-08-25 17:07:27 +00:00
|
|
|
|
|
|
|
;; PID (Option Exception)
|
|
|
|
(define (trace-actor-exit pid maybe-exn)
|
|
|
|
(notify! (current-actor-path-rev) (cons-pid pid) 'exit maybe-exn))
|
2015-03-21 16:30:10 +00:00
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
;; PID Event
|
|
|
|
(define (trace-action-produced pid e)
|
|
|
|
(notify! (cons-pid pid) (current-actor-path-rev) 'action e))
|
2015-03-21 16:30:10 +00:00
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
;; PID Event
|
|
|
|
(define (trace-event-consumed pid e)
|
|
|
|
(notify! (current-actor-path-rev) (cons-pid pid) 'event e))
|
2015-03-04 16:16:18 +00:00
|
|
|
|
2016-08-25 17:07:27 +00:00
|
|
|
;; PID PID Event
|
|
|
|
(define (trace-causal-influence src-pid snk-pid e)
|
|
|
|
(notify! (cons-pid src-pid) (cons-pid snk-pid) 'influence e))
|