home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 156_01 / profile.doc < prev    next >
Text File  |  1985-08-21  |  3KB  |  73 lines

  1. PROFILE
  2.  
  3. If the "profile and trace" option of the compiler is used, each
  4. call to err() results in a walkback trace of function calls.
  5. (Err() is in the IOLIB library. For details, see IOLIB.DOC.) In
  6. addition, an execution profile is displayed on the console at
  7. program termination (call to exit()). The profile consists of a
  8. list of the functions and the number of times (up to 999999)
  9. each was called. This is sometimes useful for debugging (to
  10. spot functions that are never called), but is most valuable for
  11. program execution time optimization. If you're trying to speed
  12. up a program, pay close attention to the functions that are
  13. called a lot of times!
  14.  
  15. The "profile and trace" option of the compiler causes it to add
  16. a call to the profile printout function just before exiting to
  17. the operating system. The code at the beginning of the program
  18. then looks like this:
  19.  
  20. ;        ORG 100H    ;implied - ZLINK default
  21.         LD HL,(6) 
  22.         LD SP,HL    ;initialize stack 
  23.         CALL CCGO    ;initialize other things 
  24.         CALL QMAIN    ;execute the user's program 
  25.         LD HL,CC2    ;pointer to 1st function 
  26.         CALL CCCALLS    ;print the profile 
  27.         CALL QEXIT    ;exit to operating system 
  28.  
  29. A header and two calls are also added to the code generated
  30. for each function. The function header contains a pointer, a
  31. counter, and a string with the function name.
  32.  
  33.     ;trials() 
  34.     CC2:    DW CC3    ;function pointer. Points to the 
  35.             ;function pointer in the textually 
  36.             ;following function, or contains a 
  37.             ;zero if this is the last one. 
  38.         DB  0,0,0  ;a three byte BCD counter for the 
  39.             ;number of times this function has been
  40.  
  41.  
  42.             ;called. (permits 999999 calls before 
  43.             ;overflow.) 
  44.     CC4:    DB 'trials',0    ;the function name 
  45.     QTRIALS: 
  46.         LD HL,CC4    ;save pointer to function 
  47.         PUSH HL        ; header block. 
  48.         CALL CCREGIS    ;register function entry. 
  49.             ;ccregis() pushes onto the stack a 
  50.             ;pointer to the function that called 
  51.             ;this one, and saves in CURRENT a 
  52.             ;pointer to this one. 
  53.     ;{    z=a(x); 
  54.         LD HL,QX 
  55.  
  56.         ...        ;regular code. 
  57.  
  58.     ;} 
  59.         CALL CCLEAVI    ;register function return 
  60.                 ;(resets CURRENT to point to 
  61.                 ;the function that called this 
  62.                 ;one) 
  63.         POP BC        ;discard the pointer added by 
  64.                 ;ccregis(). 
  65.         POP BC        ;discard the pointer to the 
  66.                 ;header block of this function.
  67.  
  68.  
  69.         RET 
  70.  
  71. Note that this method permits a walkback trace even in the 
  72. presence of recursive function calls. 
  73.