diff --git a/collects/profile/analyzer.ss b/collects/profile/analyzer.ss index 8cbf57e..f3c765b 100644 --- a/collects/profile/analyzer.ss +++ b/collects/profile/analyzer.ss @@ -4,56 +4,7 @@ (provide analyze-samples) -(require scheme/list) - -;; An encapsulation of an analyzed profile call graph: -;; - total-time: the total time observed in msec (this is generally different -;; than the time it took to run the profile). -;; - sample-number: the number of samples taken. -;; - thread-times: a list of ( . msec) for the time spent in -;; observed threads. -;; - nodes: the list of call-graph nodes sorted by their total time. -;; - *-node: a special node that is connected as a "caller" for all toplevel -;; functions and a "callee" for all leaf functions. It will also be -;; identifiable by having both id and src fields being #f. Can be used to -;; start a graph traversal from the top or the bottom. -(provide (struct-out profile)) -(define-struct profile - (total-time cpu-time sample-number thread-times nodes *-node)) - -;; An entry for a single profiled function: -;; - id, src: the corresponding values from `continuation-mark-set->context'. -;; - thread-ids: the list of thread identifiers this function has been seen in. -;; - total: total msecs it participated in (= time in it, including callees). -;; - self: msecs where it was at the top of the stack (= time in its own code). -;; - callers, callees: a list of `edge' values for the time spent while it was -;; called by the repective , or it called it, sorted in decreasing msec -;; time. -;; Note that the sum of caller/callee edges including the special `*-node' -;; should be equal to the `total' time. So the edge from/to the `*-node' can -;; be used to get the time spent as a leaf or as a root divided by the number -;; of time the function appeared on the stack: so this value can be displayed -;; in the call-graph and the numbers will sum up nicely to a 100%. -(provide (struct-out node)) -(define-struct node (id src thread-ids total self callers callees) - #:mutable - #:property prop:custom-write - (lambda (node o w?) (fprintf o "#" (or (node-id node) '???)))) - -;; An edge representing function calls between two nodes: -;; - total: the total time spent while the call was anywhere on the stack. -;; - caller, callee: the two relevant `node' values. -;; - caller-time, callee-time: the time that the caller/callee spent in this -;; call (different from the above time because each stack sample's time is -;; divided by the number of times the caller/callee appears in that slice). -(provide (struct-out edge)) -(define-struct edge (total caller caller-time callee callee-time) - #:mutable - #:property prop:custom-write - (lambda (edge o w?) - (fprintf o "#" - (or (node-id (edge-caller edge)) '???) - (or (node-id (edge-callee edge)) '???)))) +(require scheme/list "structs.ss" "utils.ss") (define-syntax-rule (with-hash ) (hash-ref! (lambda () ))) diff --git a/collects/profile/main.ss b/collects/profile/main.ss index 2d990be..3c29bf0 100644 --- a/collects/profile/main.ss +++ b/collects/profile/main.ss @@ -2,7 +2,7 @@ (provide profile-thunk profile) -(require "sampler.ss" (except-in "analyzer.ss" profile) +(require "sampler.ss" "analyzer.ss" (prefix-in text: "render-text.ss") (for-syntax scheme/base)) diff --git a/collects/profile/render-graphviz.ss b/collects/profile/render-graphviz.ss index 2c6e5c8..946a15f 100644 --- a/collects/profile/render-graphviz.ss +++ b/collects/profile/render-graphviz.ss @@ -2,7 +2,7 @@ (provide render) -(require "analyzer.ss" "utils.ss") +(require "structs.ss" "analyzer.ss" "utils.ss") (define (render profile #:hide-self [hide-self% 1/100] diff --git a/collects/profile/render-text.ss b/collects/profile/render-text.ss index 60dcec0..8cda73a 100644 --- a/collects/profile/render-text.ss +++ b/collects/profile/render-text.ss @@ -2,7 +2,7 @@ (provide render) -(require "analyzer.ss" "utils.ss" scheme/list) +(require "structs.ss" "analyzer.ss" "utils.ss" scheme/list) (define (f:msec msec) (number->string (round (inexact->exact msec)))) diff --git a/collects/profile/structs.ss b/collects/profile/structs.ss new file mode 100644 index 0000000..6512b1f --- /dev/null +++ b/collects/profile/structs.ss @@ -0,0 +1,52 @@ +#lang scheme/base + +;; Struct definitions for the profiler + +;; An encapsulation of an analyzed profile call graph: +;; - total-time: the total time observed in msec (this is generally different +;; than the time it took to run the profile). +;; - sample-number: the number of samples taken. +;; - thread-times: a list of ( . msec) for the time spent in +;; observed threads. +;; - nodes: the list of call-graph nodes sorted by their total time. +;; - *-node: a special node that is connected as a "caller" for all toplevel +;; functions and a "callee" for all leaf functions. It will also be +;; identifiable by having both id and src fields being #f. Can be used to +;; start a graph traversal from the top or the bottom. +(provide (struct-out profile)) +(define-struct profile + (total-time cpu-time sample-number thread-times nodes *-node)) + +;; An entry for a single profiled function: +;; - id, src: the corresponding values from `continuation-mark-set->context'. +;; - thread-ids: the list of thread identifiers this function has been seen in. +;; - total: total msecs it participated in (= time in it, including callees). +;; - self: msecs where it was at the top of the stack (= time in its own code). +;; - callers, callees: a list of `edge' values for the time spent while it was +;; called by the repective , or it called it, sorted in decreasing msec +;; time. +;; Note that the sum of caller/callee edges including the special `*-node' +;; should be equal to the `total' time. So the edge from/to the `*-node' can +;; be used to get the time spent as a leaf or as a root divided by the number +;; of time the function appeared on the stack: so this value can be displayed +;; in the call-graph and the numbers will sum up nicely to a 100%. +(provide (struct-out node)) +(define-struct node (id src thread-ids total self callers callees) + #:mutable + #:property prop:custom-write + (lambda (node o w?) (fprintf o "#" (or (node-id node) '???)))) + +;; An edge representing function calls between two nodes: +;; - total: the total time spent while the call was anywhere on the stack. +;; - caller, callee: the two relevant `node' values. +;; - caller-time, callee-time: the time that the caller/callee spent in this +;; call (different from the above time because each stack sample's time is +;; divided by the number of times the caller/callee appears in that slice). +(provide (struct-out edge)) +(define-struct edge (total caller caller-time callee callee-time) + #:mutable + #:property prop:custom-write + (lambda (edge o w?) + (fprintf o "#" + (or (node-id (edge-caller edge)) '???) + (or (node-id (edge-callee edge)) '???)))) diff --git a/collects/profile/utils.ss b/collects/profile/utils.ss index edc76f9..8e6de02 100644 --- a/collects/profile/utils.ss +++ b/collects/profile/utils.ss @@ -1,7 +1,7 @@ #lang scheme/base (provide format-percent format-source get-hidden) -(require "analyzer.ss") +(require "structs.ss") ;; Format a percent number, possibly doing the division too. If we do the ;; division, then be careful: if we're dividing by zero, then make the result