source: trunk/contrib/huebner/advice-profiler/overhead.lisp @ 16687

Last change on this file since 16687 was 16687, checked in by rme, 5 years ago

Update copyright/licesne header as authorized by author.

File size: 2.5 KB
Line 
1;;; -*- Lisp -*-
2;;;
3;;; Copyright 2008 Hans Huebner
4;;;
5;;; Licensed under the Apache License, Version 2.0 (the "License");
6;;; you may not use this file except in compliance with the License.
7;;; You may obtain a copy of the License at
8;;;
9;;;     http://www.apache.org/licenses/LICENSE-2.0
10;;;
11;;; Unless required by applicable law or agreed to in writing, software
12;;; distributed under the License is distributed on an "AS IS" BASIS,
13;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14;;; See the License for the specific language governing permissions and
15;;; limitations under the License.
16
17;;; Profiling overhead calculation
18
19;;; This is in a separate file so that the profiler.lisp file can be
20;;; compiled and loaded beforehand, making the macrology available.
21
22(in-package "PROFILER")
23
24(eval-when (:compile-toplevel :load-toplevel :execute)
25  (defun stub-function (x)
26    (declare (ignore x))
27    nil)
28  (proclaim '(notinline stub-function)))
29
30(defconstant +overhead-iterations+ 10000
31  "Number of iterations to make through the empty stub function to
32   determine profiling overhead.")
33
34(defvar *determining-overhead* nil
35  "Set while determining overhead in order to prevent recursion")
36
37(defun determine-overhead ()
38  (format *trace-output* "; Calculating profiling overhead...")
39  (force-output *trace-output*)
40  (reset)
41  (process-enable-profiling *current-process*)
42  (unprofile stub-function)
43  ;; Determine loop and function call overhead
44  (with-real/cpu/cons (bare-real bare-cpu bare-cons)
45      (dotimes (i +overhead-iterations+)
46        (stub-function nil))
47    (profile stub-function)
48    (with-real/cpu/cons (alloc-real alloc-cpu alloc-cons)
49        (stub-function nil)             ; call once in order to allocate call record structure
50      ;; Determine profiling overhead
51      (with-real/cpu/cons (profiled-real profiled-cpu profiled-cons)
52          (dotimes (i +overhead-iterations+)
53            (stub-function nil))
54        (unprofile stub-function)
55        (setf *real-overhead* (round (/ (- profiled-real bare-real) +overhead-iterations+))
56              *cpu-overhead* (round (/ (- profiled-cpu bare-cpu) +overhead-iterations+))
57              *cons-overhead* (round (/ (- profiled-cons bare-cons alloc-cons) +overhead-iterations+)))))
58    (reset)
59    (format *trace-output* "~&; per call overheads: cpu time ~A, real time ~A, cons ~A bytes~%"
60            (format-time *cpu-overhead*) (format-time *real-overhead*) *cons-overhead*)))
61
62(determine-overhead)
Note: See TracBrowser for help on using the repository browser.