home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / cutils / Profile / C / ProfileC next >
Encoding:
Text File  |  1991-06-02  |  1.2 KB  |  63 lines

  1. /* C.ProfileC: Execution profiler (by count)
  2.  *
  3.  * Version 1.00, 04-06-1990
  4.  *
  5.  * Copyright (C) Ferdinand Oeinck 1990
  6.  *
  7.  * Modified, Paul Moore 02/06/91.
  8.  *   To conform to the conventions of my "Utils" library.
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14.  
  15. #include "Profile.h"
  16.  
  17. extern void _mapstore (void);
  18. extern void _fmapstore (const char *);
  19.  
  20. static char *_profile_filename;
  21. static void _profile_exithandler(void);
  22.  
  23. void profile_init_count (const char *filename)
  24. {
  25.     if (filename == NULL || *filename == '\0')
  26.         _profile_filename = NULL;
  27.     else
  28.     {
  29.         if ((_profile_filename = malloc(strlen(filename) + 1)) == NULL)
  30.         {
  31.             printf("Warning: Execution count profiling not possible.\n");
  32.             printf("         Malloc failed.\n");
  33.             return;
  34.         }
  35.  
  36.         strcpy(_profile_filename, filename);
  37.     }
  38.  
  39.     atexit(_profile_exithandler);
  40. }
  41.  
  42. static void _profile_exithandler (void)
  43. {
  44.     FILE *fp;
  45.  
  46.     if (_profile_filename == NULL)
  47.     {
  48.         _mapstore();
  49.     }
  50.     else if ((fp = fopen(_profile_filename, "w")) == NULL)
  51.     {
  52.         fprintf(stderr,"Can't write profile data to %s - using stderr\n",_profile_filename);
  53.         _mapstore();
  54.     }
  55.     else
  56.     {
  57.         fclose(fp);
  58.         _fmapstore(_profile_filename);
  59.     }
  60.  
  61.     free(_profile_filename);
  62. }
  63.