home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / callmon / src / example_motif_vm.c < prev    next >
C/C++ Source or Header  |  1996-08-06  |  5KB  |  177 lines

  1. /*  CALLMON Examples
  2.  *
  3.  *  File:     EXAMPLE_MOTIF_VM.C
  4.  *  Author:   Thierry Lelegard
  5.  *  Version:  1.0
  6.  *  Date:     24-JUL-1996
  7.  *
  8.  *  Abstract: This module uses CALLMON to trace all routines allocating
  9.  *            virtual memory. Can be used with EXAMPLE_MOTIF.C.
  10.  *
  11.  *            Use option "-nocallmon" in command line to run the program
  12.  *            without the interception of memory allocation routines.
  13.  *
  14.  *            Use option "-list" to display a list of intercepted routines.
  15.  */
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <stsdef.h>
  22. #include <starlet.h>
  23. #include "callmon.h"
  24.  
  25. static int active_phase = 0;
  26.  
  27.  
  28. /*******************************************************************************
  29.  *
  30.  *  General pre- and post-processing routine for CALLMON.
  31.  *  We simply display a message. The boolean "active_phase" is used
  32.  *  to avoid tracing the usage of memory during initialization.
  33.  */
  34.  
  35. static void interceptor (
  36.     callmon$arguments_t* arguments,
  37.     uint32               caller_invo_handle,
  38.     char*                routine_name,
  39.     uint64               (*intercepted_routine)(),
  40.     uint64               (*jacket_routine)())
  41. {
  42.     if (active_phase) {
  43.         if (arguments->post_processing)
  44.             printf ("<== %s\n", routine_name);
  45.         else
  46.             printf ("==> %s (%d arg%s)\n", routine_name,
  47.                 arguments->arg_count, arguments->arg_count > 1 ? "s" : "");
  48.     }
  49. }
  50.  
  51.  
  52. /*******************************************************************************
  53.  *
  54.  *  Initialization routine called by the application.
  55.  */
  56.  
  57. void init_call_monitor (int argc, char** argv)
  58. {
  59.     uint32 status;
  60.     char** name;
  61.     int arg;
  62.     int show_list = 0;
  63.  
  64.     /* List of routines involved in virtual memory allocation */
  65.  
  66.     static char* routine_list [] = {
  67.         "DECC$CALLOC",
  68.         "DECC$CALLOC_OPT",
  69.         "DECC$CFREE",
  70.         "DECC$CFREE_OPT",
  71.         "DECC$FREE",
  72.         "DECC$FREE_OPT",
  73.         "DECC$MALLOC",
  74.         "DECC$MALLOC_OPT",
  75.         "DECC$REALLOC",
  76.         "DECC$VAXC$CALLOC_OPT",
  77.         "DECC$VAXC$CFREE_OPT",
  78.         "DECC$VAXC$FREE_OPT",
  79.         "DECC$VAXC$MALLOC_OPT",
  80.         "DECC$VAXC$REALLOC_OPT",
  81.         "DECC$_CALLOC64",
  82.         "DECC$_MALLOC64",
  83.         "DECC$_REALLOC64",
  84.         "LIB$$GET_VM_POINTERS",
  85.         "LIB$$GET_VM_POINTERS_64",
  86.         "LIB$CREATE_USER_VM_ZONE",
  87.         "LIB$CREATE_USER_VM_ZONE_64",
  88.         "LIB$CREATE_VM_ZONE",
  89.         "LIB$CREATE_VM_ZONE_64",
  90.         "LIB$DELETE_VM_ZONE",
  91.         "LIB$DELETE_VM_ZONE_64",
  92.         "LIB$FIND_VM_ZONE",
  93.         "LIB$FIND_VM_ZONE_64",
  94.         "LIB$FREE_VM",
  95.         "LIB$FREE_VM_64",
  96.         "LIB$FREE_VM_PAGE",
  97.         "LIB$FREE_VM_PAGE_64",
  98.         "LIB$GET_VM",
  99.         "LIB$GET_VM_64",
  100.         "LIB$GET_VM_PAGE",
  101.         "LIB$GET_VM_PAGE_64",
  102.         "LIB$RESET_VM_ZONE",
  103.         "LIB$RESET_VM_ZONE_64",
  104.         "LIB$SHOW_VM",
  105.         "LIB$SHOW_VM_64",
  106.         "LIB$SHOW_VM_ZONE",
  107.         "LIB$SHOW_VM_ZONE_64",
  108.         "LIB$STAT_VM",
  109.         "LIB$STAT_VM_64",
  110.         "LIB$VERIFY_VM_ZONE",
  111.         "LIB$VERIFY_VM_ZONE_64",
  112.         "LIB$VM_CALLOC",
  113.         "LIB$VM_CALLOC_64",
  114.         "LIB$VM_FREE",
  115.         "LIB$VM_FREE_64",
  116.         "LIB$VM_MALLOC",
  117.         "LIB$VM_MALLOC_64",
  118.         "LIB$VM_REALLOC",
  119.         "LIB$VM_REALLOC_64",
  120.         "XMEMORY_CALLOC",
  121.         "XMEMORY_FREE",
  122.         "XMEMORY_MALLOC",
  123.         "XMEMORY_REALLOC",
  124.         "XTCALLOC",
  125.         "XTFREE",
  126.         "XTMALLOC",
  127.         "XTREALLOC",
  128.         "_XTHEAPALLOC",
  129.         "_XTHEAPFREE",
  130.         "_XTHEAPINIT",
  131.         "_XMHEAPALLOC",
  132.         "_XMHEAPCREATE",
  133.         "_XMHEAPFREE",
  134.         NULL};
  135.  
  136.     /* If "-nocallmon" is specified, keep silent */
  137.  
  138.     for (arg = 1; arg < argc; arg++) {
  139.         if (strcmp (argv [arg], "-nocallmon") == 0)
  140.             return;
  141.         else if (strcmp (argv [arg], "-list") == 0)
  142.             show_list = 1;
  143.     }
  144.  
  145.     /* Intercept all memory allocation routines */
  146.  
  147.     active_phase = 0;
  148.  
  149.     for (name = routine_list; *name != NULL; name++) {
  150.  
  151.         printf ("Intercepting %s\n", *name);
  152.  
  153.         status = callmon$intercept (*name, interceptor, interceptor);
  154.  
  155.         if (!$VMS_STATUS_SUCCESS (status)) {
  156.             uint32 msgvec [2];
  157.             msgvec [0] = 1;
  158.             msgvec [1] = status;
  159.             sys$putmsg (msgvec, 0, 0, 0);
  160.         }
  161.     }
  162.  
  163.     /* Display a list of intercepted routines */
  164.  
  165.     if (show_list) {
  166.         printf ("\n*** Intercepted routines:\n");
  167.         callmon$dump_routine_tree (CALLMON$C_INTERCEPTED_ONLY);
  168.         printf ("\n*** Non-interceptable routines:\n");
  169.         callmon$dump_routine_tree (CALLMON$C_UNINTERCEPTABLE_ONLY);
  170.         printf ("\n*** Non-relocatable routines:\n");
  171.         callmon$dump_routine_tree (CALLMON$C_UNRELOCATABLE_ONLY);
  172.         printf ("\n");
  173.     }
  174.  
  175.     active_phase = 1;
  176. }
  177.