home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / apps / gmemusage / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.4 KB  |  163 lines

  1. /*
  2.  * print.c  printing memory usage
  3.  *
  4.  * Copyright 1994, Silicon Graphics, Inc.
  5.  * All Rights Reserved.
  6.  *
  7.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8.  * the contents of this file may not be disclosed to third parties, copied or
  9.  * duplicated in any form, in whole or in part, without the prior written
  10.  * permission of Silicon Graphics, Inc.
  11.  *
  12.  * RESTRICTED RIGHTS LEGEND:
  13.  * Use, duplication or disclosure by the Government is subject to restrictions
  14.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17.  * rights reserved under the Copyright Laws of the United States.
  18.  */
  19.  
  20. #include <stdio.h>
  21.  
  22. #include "process.h"
  23. #include "print.h"
  24.  
  25. /*
  26.  *  static void PrintAllUsage(FILE *fp, PROGRAM *usage)
  27.  *
  28.  *  Description:
  29.  *      Print out info about all programs that are running
  30.  *
  31.  *  Parameters:
  32.  *      fp     stream to print to
  33.  *      usage  the usage to print
  34.  */
  35.  
  36. static void PrintAllUsage(FILE *fp, PROGRAM *usage)
  37. {
  38.     long totSize = 0, totRes = 0, totPhys = 0, totPriv = 0;
  39.  
  40.     fprintf(fp, "        All Programs:\n");
  41.     fprintf(fp, "                "
  42.         "Name\t  Size\t   Res\t  Phys\t  Priv\tCopies\n");
  43.     
  44.     while (usage) {
  45.     if (usage->print) {
  46.         fprintf(fp, "%20s\t%6d\t%6d\t%6d\t%6d\t%6d\n",
  47.             usage->progName, usage->size, usage->resSize,
  48.             usage->weightSize, usage->privSize, usage->nProc);
  49.         totSize += usage->size;
  50.         totRes += usage->resSize;
  51.         totPhys += usage->weightSize;
  52.         totPriv += usage->privSize;
  53.     }
  54.     usage = usage->next;
  55.     }
  56.     fprintf(fp, "              Totals:\t%6d\t%6d\t%6d\t%6d\n",
  57.         totSize, totRes, totPhys, totPriv);
  58. }
  59.  
  60. /*
  61.  *  static void PrintMapUsage(FILE *fp, PROGRAM *usage)
  62.  *
  63.  *  Description:
  64.  *      Print out info about all resident mappings
  65.  *
  66.  *  Parameters:
  67.  *      fp     stream to print to
  68.  *      usage  the usage to print
  69.  */
  70.  
  71. static void PrintMapUsage(FILE *fp, PROGRAM *usage)
  72. {
  73.     long totPhys = 0, totPriv = 0;
  74.     fprintf(fp, "   Resident Mappings:\n");
  75.  
  76.     fprintf(fp, "                "
  77.         "Name\t           Type\t  Phys\t  Priv\n");
  78.  
  79.     while (usage) {
  80.     if (usage->print && usage->mapType) {
  81.         fprintf(fp, "%20s\t%15s\t%6d\t%6d\n",
  82.             usage->mapName ? usage->mapName : "none",
  83.             usage->mapType, usage->weightSize,
  84.             usage->privSize);
  85.         totPhys += usage->weightSize;
  86.         totPriv += usage->privSize;
  87.     }
  88.     usage = usage->next;
  89.     }
  90.     fprintf(fp, "              Totals:\t               \t%6d\t%6d\n",
  91.         totPhys, totPriv);
  92. }
  93.  
  94. /*
  95.  *  static void PrintProcUsage(FILE *fp, PROGRAM *usage, char *procName)
  96.  *
  97.  *  Description:
  98.  *      Print info about all the mappings for a particular program
  99.  *
  100.  *  Parameters:
  101.  *      fp        stream to print to
  102.  *      usage     usage to print
  103.  *      procName  name of the program whose mappings are bing printed
  104.  */
  105.  
  106. static void PrintProcUsage(FILE *fp, PROGRAM *usage, char *procName)
  107. {
  108.     long totSize = 0, totRes = 0, totPhys = 0, totPriv = 0;
  109.  
  110.     fprintf(fp, "%20s:\n", procName);
  111.     fprintf(fp, "                "
  112.         "Name\t           Type\t  Size\t   Res\t  Phys\t  Priv\n");
  113.     
  114.     while (usage) {
  115.     if (usage->print) {
  116.         fprintf(fp, "%20s\t%15s\t%6d\t%6d\t%6d\t%6d\n",
  117.             usage->mapName ? usage->mapName : "none",
  118.             usage->mapType, usage->size,
  119.             usage->resSize, usage->weightSize,
  120.             usage->privSize);
  121.         totSize += usage->size;
  122.         totRes += usage->resSize;
  123.         totPhys += usage->weightSize;
  124.         totPriv += usage->privSize;
  125.     }
  126.     usage = usage->next;
  127.     }
  128.     fprintf(fp, "              Totals:\t              \t%6d\t%6d\t%6d\t%6d\n",
  129.         totSize, totRes, totPhys, totPriv);
  130. }
  131.  
  132. /*
  133.  *  void PrintUsage(FILE *fp, PRTYPE type, PROGRAM *usage, char *procName)
  134.  *
  135.  *  Description:
  136.  *      Print info to fp for permanent storage
  137.  *
  138.  *  Parameters:
  139.  *      fp         stream to print to
  140.  *      type       the type of print out
  141.  *      usage      the usage to print
  142.  *      procName   the name of the program to print mappings for, if
  143.  *                 type is PRProc
  144.  */
  145.  
  146. void PrintUsage(FILE *fp, PRTYPE type, PROGRAM *usage, char *procName)
  147. {
  148.     fprintf(fp, "-----------------------------------"
  149.         "-----------------------------------\n");
  150.  
  151.     switch (type) {
  152.     case PRAll:
  153.     PrintAllUsage(fp, usage);
  154.     break;
  155.     case PRMaps:
  156.     PrintMapUsage(fp, usage);
  157.     break;
  158.     case PRProc:
  159.     PrintProcUsage(fp, usage, procName);
  160.     break;
  161.     }
  162. }
  163.