/*****************************************************************************/ /* hyperSPIxx.c Basic hyperSPI, plus more items, plus better graphics (hyperSPI++)! This application generates VMS System Performance Information HTML documents. Coupled with 'HyperSpi$agent.c', the data-collection application, it can profile, complete with graphics, fundamental system performance indicators as CPU usage, memory usage, IO values. It operates in two distinct modes, text and graphic. In text mode it returns an HTML stream to the browser comprising a hypertext page, with selection menu, node performance presentation page, data listing or dump page. In graphic mode it returns a GIF image to the browser, first processing the specified data into an in-memory bitmap graph, then sending this image to the client via an internal GIF processor. A node preformance presentation page may have one or more HTML tags within it. Each of these tags will separately cause the browser to invoke the application to generate a graphic from the data specified in the SRC= URL. If the /NODES= qualifier specifies a comma-separated list of node names these are used in the menus for listing the available nodes. If this is not supplied the data directory is searched for current-day data files, those found have the respective node name extacted and these are used to list the nodes. The /STYLE= qualifier provide for a URL to a site-local style file. This allows the internal styles to be over-loaded. Button labels are customizable (potentially to non-English language). They comprise a label, equate symbol and URL-style path suitable for creating a link. Multiple buttons are separated using the semicolon. Note that any such button customization must provide escaped HTML-forbidden characters in the button label and URI-forbidden characters in the path! See DEFAULT_BUTTONS. Here is an example of changing the button labels: /BUTTON="Selector$Help=/hyperspi/-/hyperspi.html" Always have the equivalent of "Close" for the first button! Additional buttons may be created by adding "label=path;" elements to the button string. In this way an additional information page could be referenced as follows: /BUTTON="↶Back=javascript:parent.history.go(-1)$" + "Selector$^Help=/hyperspi/-/hyperspi.html$^Other VMS=/vms/" DIFFICULTY FITTING ALL THESE QUALIFIERS INTO A COMMAND LINE OR LOGICAL? Use an existing, or create a new, DCL wrapper procedure for the script (same name and directory) and build up a DCL symbol to provide the information. Up to 1024 characters can be included in this way. For example: $ HYPERSPI$PARAM = "/BUTTON=""Select$Help=/hyperspi/-/hyperspihelp.html""" $ HYPERSPI$PARAM = HYPERSPI$PARAM + "/STYLE=""/hyperspi/-/local.css""" $ RUN HT_EXE:HYPERSPI OSU ENVIRONMENT --------------- Script responses are returned in OSU "raw" mode; the script taking care of the full response header and correctly carriage-controlled data stream, text or binary!! Uses the CGILIB.C to engage in the dialog phase generating, storing and then making available the equivalent of CGI variables. "VANILLA" CGI ENVIRONMENT ------------------------- Primarily for the likes of Netscape FastTrack. This environment can accomodate CGI variables that are not prefixed with "WWW_" and do not supply "KEY_xxxxx" or "FORM_xxxxx" (which must be derived from "QUERY_STRING"). Full HTTP stream (non-parsed header) is assumed as not supported so all output occurs with a CGI-compliant header line (e.g. "Status: 200 Success") and record-oriented output. CGI VARIABLES ------------- FORM_BUFFERED_IO if non-null then buffered IO requested FORM_CPU if non-null then cpu usage requested FORM_DO what to do(!): "DUMP", "GRAPH", "LIST", "PAGE", "MENU" FORM_DAY the (first) day of the data file(s) FORM_DIRECT_IO if non-null then direct IO requested FORM_EXTRACT if non-null provide a link to allow graph extraction FORM_HOUR the (first) hour of the data FORM_INCLUDE additional category: PEAK, TOTAL (only with "user-mode-cpu"), HARD-FAULTS (only with "faults") FORM_LIST_NODE name of node to process data (see also FORM_NODE) FORM_MINUTE the (first) minute of the data FORM_MONTH the (first) month of the data file(s) FORM_MSCP_IO if non-null then MSCP IO requested FORM_NET_INT network interface traffic FORM_NODE name of node to process data (used before FORM_LIST_NODE) FORM_PERIOD standard period (e.g. "until" now, "business", "today", "yesterday", or since a number of days) FORM_REFRESH integer number of minutes between summary refreshes FORM_TODAY the last day of the data file(s) FORM_TOMINUTE the last minute of the data FORM_TOHOUR the last hour of the data FORM_TOMONTH the last month of the data file(s) FORM_TOYEAR the last year of the data file(s) FORM_USER_MODE_CPU if non-null then user-mode-cpu usage requested FORM_WHAT any data category can be placed in this comma-separated list FORM_XMAG number of times X axis should be enlarged FORM_YEAR the (first) year of the data file(s) FORM_YMAG number of times Y axis should be enlarged QUALIFIERS ---------- /BUTTONS= string containing button labels/paths /CHARSET= "Content-Type: text/html; charset=...", empty suppresses charset /DBUG turns on all "if (Debug)" statements /DIRECTORY= directory containing any node description HTML files /HELP= help HTML file URL /NODES= comma-separated list of node names collecting SPI data /SHUTDOWN causes the HYPERSPI$AGENT image/process to exit LOGICAL NAMES ------------- HYPERSPI$DATA locates the data files HYPERSPI$PARAM equivalent to (overrides) the command line parameters/qualifiers (define as a system-wide logical) BUILD DETAILS ------------- See BUILD_HYPERSPI.COM procedure. COPYRIGHT --------- Copyright (C) 1996-2018 Mark G.Daniel This program, comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the conditions of the GNU GENERAL PUBLIC LICENSE, version 3, or any later version. http://www.gnu.org/licenses/gpl.txt VERSION HISTORY (update SOFTWAREVN as well!) --------------- 04-FEB-2018 MGD v3.1.0, a fresh coat of paint bugfix; build suitable for both MMK and MMS 29-MAY-2011 MGD v3.0.0, add network interface data data format version 3 (shared with vanilla hyperSPI) (There is a lot of work that *could* be done to this older piece of code but I've spent the minimal time necessary just to make it work on modern platforms.) 30-MAR-2001 JFP v2.1.0, updated for later version of GD graphics library 08-JAN-2001 MGD v2.0.1, interim release 03-NOV-2000 JFP v2.0.0, hyperSPI++ evolution from WASD hyperSPI, it is dependent on the GD graphics library 12-APR-2000 MGD v1.6.1, minor changes for CGILIB 1.4 07-AUG-1999 MGD v1.6.0, use more of the CGILIB functionality 24-APR-1999 MGD v1.5.0, use CGILIB.C, standard CGI environment (Netscape FastTrack), modify to use CgiVar() 02-OCT-1998 MGD v1.4.0, provide content-type "; charset=..." 13-AUG-1998 MGD v1.3.0, accomodations for OSU bugfix; IncludeFile() file name length 13-AUG-1998 MGD NOTE: this application is not Y2K compliant (in the sense data is stored in files named with a 2 digit year!) 06-MAY-1998 MGD v1.2.0, general maintenance, cosmetic changes 11-SEP-1997 MGD v1.1.1, upped MAX_NODE_COUNT_BEFORE_SELECT to 20 01-AUG-1997 MGD v1.1.0, added /BODY= qualifier, remove extraneous '/' from , general maintenance 19-SEP-1995 MGD v1.0.1, replace carriage-control single newline, still acceptable for HTTP, slightly more efficient 20-JUN-1995 MGD v1.0.0, initial development */ /*****************************************************************************/ #define SOFTWAREVN "3.1.0" #define SOFTWARENM "HYPERSPIXX" #define SOFTWARECR "Copyright (C) 1996-2018 Mark G.Daniel" #ifdef __ALPHA # define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN #endif #ifdef __ia64 # define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN #endif #ifdef __VAX # define SOFTWAREID SOFTWARENM " VAX-" SOFTWAREVN #endif /* standard C header files */ #include #include #include #include #include #include #include #include #include #include /* VMS related header files */ #include #include #include #include #include #include #include #include #include #include #include #define NEWLIB_GDCHART #include #define MAXINT INT_MAX #define MAXSHORT SHRT_MAX #include "gdc.h" #include "gdchart.h" #include "gdcpie.h" /* application header file */ #include "HyperSpi.h" #include #ifndef __VAX # pragma nomember_alignment #endif #define boolean int #define true 1 #define false 0 #define VMSok(x) ((x) & STS$M_SUCCESS) #define VMSnok(x) !(((x) & STS$M_SUCCESS)) #define FI_LI __FILE__, __LINE__ /* for use by functions in PlotSpi.c */ #define PLOT_ON 0 #define PLOT_OFF 1 #define PLOT_XOR 2 #define MAX_SAMPLE_PERIOD_DAYS 31 #define MAX_NODE_COUNT_BEFORE_SELECT 20 #define DEFAULT_BUTTONS "\ ↶Back=javascript:parent.history.go(-1)$Selector$\ ^Help=/hyperspixx/-/hyperspixx.html\ " #define DEFAULT_STYLE "\ body { margin:0.5em; background-color:white; color:black; \ font-family:sans-serif; }\n\ a { text-decoration:none; color:black; \ border:1px solid slategray; border-radius:3px; padding:1px 5px 2px 5px; }\n\ .header { padding:0.5em 0.5em 0.5em 1em; background-color: gainsboro; \ border:1px solid lightslategray; border-radius:1px; \ font-size: 140%; font-weight: bold; word-spacing:0.2em; }\n\ .buttonbar { padding:0.7em 1em 0.7em 1em; \ border:1px solid lightslategray; border-radius:1px; \ background-color: gainsboro; min-height:1.3em; }\n\ .buttonbar a { text-decoration:none; color:inherit; \ border:1px solid slategray; border-radius:3px; padding:1px 5px 2px 5px; }\n\ .hyperSPI { display:table-cell; \ font-family: futura, \"Tw Cen MT\", helvetica, arial, sans; \ font-weight:normal; font-size:125%; letter-spacing:-2px; }\n\ .heading { display:table-cell; width:95%; text-align:center; \ font-size:110%; }\n\ .datetime { display:table-cell; white-space:nowrap; font-size:80%; \ word-spacing:0px; }\n\ .content { margin:1.5em; }\n\ .precis { margin:0.5em 1em 0.5em 2em; }\n\ .precis th { text-align:right; }\n\ .precis td { text-align:left; }\n\ .graph { margin:0.5em; }\n\ .graphtitle { margin:1em 0.5em 0.5em 0.5em; font-size:120%; font-weight:bold; \ text-decoration:underline; }\n\ .graphdata { margin:1em 1em 1em 2em; }\n\ .fileday { margin-bottom:1em; font-size:120%; font-weight:bold; }\n\ .filename { font-family:monospace; font-size:120%; }\n\ .extrbtn { margin-left:2em; background-color:whitesmoke; font-size:80%; }\n\ " char Utility [] = "HYPERSPI"; char *DayName [] = { "", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", }; char *MonthName [] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; boolean Debug, DoDump, DoGraph, DoList, DoComprehensiveMenu, DoShutdownAgent, DoSummaryMenu, DoPresentSummaryPage, ErrorReported, ExtractGraph, GifTransparentBackground = true, HttpHasBeenOutput, IncludePeak, IncludeTotal, OsuEnvironment, ProvidePercentCPU, ProvidePercentModeCPU, ProvidePercentModeCPUPie, ProvidePercentUserModeCPU, ProvideBufferedIO, ProvidePeakBufferedIO, ProvideDirectIO, ProvidePeakDirectIO, ProvideMemory, ProvideMscpIO, ProvideNetInt, ProvidePeakMscpIO, ProvidePeakNetInt, ProvidePageFaults, ProvidePeakPageFaults, ProvideHardPageFaults, ProvidePeakHardPageFaults, ProvideSoftPageFaults, ProvidePeakSoftPageFaults, ProvideProcesses, ProvideCom, ProvideLocks, ProvideLocksPie, RefreshTodayData, StdCgiEnvironment; int AvePercentCPU, AvePercentUserModeCPU, AveBufferedIO, AveDirectIO, AveLck, AveLckIn, AveLckOut, AveLckLoc, AveMscpIO, AveNetIntRxTx, AveNumberOfCom, AvePageFaults, AveHardPageFaults, AveNetInt, AveNetIntRx, AveNetIntTx, AveNumberOfProcesses, AveSystemMemoryPercentInUse, AvePageSpacePercentInUse, CurrentJulianDate, CurrentMinuteFromStartOfPeriod, DataFileNameLength, DataFileSpecLength, DataFilesFoundCount, DataFilesProcessedCount, DataRecordsReadCount, DataRecordsProcessedCount, DataMinute, DataHour, DataDay, DataMonth, DataYear, FromJulianDate, FromDay, FromHour, FromMinute, FromMonth, FromYear, HaveDataY, MaxAveBufferedIO, MaxAveDirectIO, MaxAveMscpIO, MaxAveNetInt, MaxAveNetIntRxTx, MaxAvePageFaults, MaxAveHardPageFaults, MaxNumberOfCom, MaxNumberOfProcesses, MaxPageSpacePercentInUse, MaxSystemMemoryPercentInUse, NodeCount, NumberOfCPUs, NumberOfDays, NumberOfDaysIntoData, NumberOfHours, NumberOfMinutesIntoData, NumberOfProcesses, PageSpaceMBytes, PageSpacePercentInUse, PeakPercentUserModeCPU, PeakBufferedIO, PeakDirectIO, PeakMscpIO, PeakPageFaults, PeakNetInt, PeakNetIntRxTx, PeakPercentCPU, PeakHardPageFaults, PercentCPU, PercentUserModeCPU, RecordSampleRate, RefreshSeconds = 0, SizeOfMarginX = 10, SizeOfMarginY = 20, SizeOfPlotX, SizeOfPlotY, StartMinuteOnFirstDay, StartMinuteOfData, SystemMemoryMBytes, SystemMemoryPercentInUse, ToJulianDate, ToMinute, ToHour, ToDay, ToMonth, ToYear, XMag, YMag; #ifndef __VAX unsigned __int64 NetIntRxTx; #else unsigned int NetIntRxTx; #endif unsigned int AvePercentModeCPU[HYPERSPI_CPU_MODE_COUNT]; float ScalingFactorY; char DataFileName [256], DataFileSpec [256], DataNode [32], DateString [32], DefaultButtons [] = DEFAULT_BUTTONS, FileSpecification [256], HyperSpiUrl [256], SoftwareID [48], ToDateString [32], UnixDateTime [64]; char *ButtonsPtr = DefaultButtons, *CgiEnvironmentPtr, *CgiFormDoPtr, *CgiFormIncludePtr, *CgiFormNodePtr, *CgiFormPeriodPtr, *CgiFormRefreshPtr, *CgiFormWhatPtr, *CgiRequestMethodPtr, *CgiPathInfoPtr, *CgiPathTranslatedPtr, *CgiScriptNamePtr, *CgiServerNamePtr, *CgiServerSoftwarePtr, *CliCharsetPtr, *DefaultStyle = DEFAULT_STYLE, *HyperSpiDirectoryPtr = "HYPERSPI$DATA:", *SelectorPtr, *SoftwareCopy = SOFTWARECR, *StyleSheetPtr = ""; char SpiNodeNames [16][16] = { "" }; unsigned long CurrentBinTime [2]; unsigned short CurrentNumTime [7]; /* this structure is declared in HyperSpi.h */ struct HyperSpiData SpiRecord; static float* Values[6]; static char** Labels; static GDC_CHART_T ChartType; static int GraphLinesCnt; /* required function prototypes */ char *ButtonBarButton(); void GetParameters(); void SetPageScheme(); void GetRequest(); void ValidateRequest(); void SummaryMenu(); void PresentSummaryPage(); void DumpRecord(); void DumpData(); void GraphData(); void ListProcessedData(); void ListProcessedRecord(); void GraphRecordCPU(); void GraphRecordCPUModes(); void GraphRecordLocks(); void GraphRecordMemory(); void GraphRecordProcesses(); void GraphRecordCom(); void GraphRecordRange(); void SelectNodeNameByDataFileName(); void SummarizeRecord(); void SummarizeData(); char* UniqueNumber(); int IncludeFile(char*); int ProcessDataFiles(); void PresentCPU(); void PresentCPUModes(); void PresentLocks(); void PresentMemory(); void PresentProcesses(); void PresentCom(); void PresentPageFaults(); void PresentPeakPageFaults(); void PresentHardPageFaults(); void PresentPeakHardPageFaults(); void PresentBufferedIO(); void PresentPeakBufferedIO(); void PresentDirectIO(); void PresentPeakDirectIO(); void PresentMscpIO(); void PresentPeakMscpIO(); void PresentNetInt(); void PresentPeakNetInt(); void ProcessDataFileRecords(); void SectionHeading (char*); void SelectNodeNames (); int ShutdownAgent(); char* SystemNodeName(); boolean strsame(char*, char*, int); /*****************************************************************************/ /* 'argc/argv' are only required to support OSU, in particular CgiLibOsuInit(). */ main ( int argc, char *argv[] ) { int status; unsigned long UnixTime; struct tm *UnixTmPtr; /*********/ /* begin */ /*********/ sprintf (SoftwareID, "%s (%s)", SOFTWAREID, CgiLibEnvironmentVersion()); if (getenv ("HYPERSPI$DBUG") != NULL) { Debug = true; fputs ("Content-Type: text/plain\n\n", stdout); CgiLibEnvironmentSetDebug (Debug); } CgiLibEnvironmentInit (argc, argv, false); CgiEnvironmentPtr = CgiLibEnvironmentName (); GetParameters (); if (DoShutdownAgent) exit (ShutdownAgent()); CgiLibResponseSetCharset (CliCharsetPtr); CgiLibResponseSetSoftwareID (SoftwareID); CgiLibResponseSetErrorMessage ("Reported by hyperSPI++"); if (StyleSheetPtr[0]) { char *cptr = calloc (1, 64+strlen(StyleSheetPtr)); sprintf (cptr, "\n", StyleSheetPtr); StyleSheetPtr = cptr; } CgiServerSoftwarePtr = CgiVar ("WWW_SERVER_SOFTWARE"); CgiRequestMethodPtr = CgiVar ("WWW_REQUEST_METHOD"); if (strcmp (CgiRequestMethodPtr, "GET")) { CgiLibResponseHeader (501, "text/html"); fprintf (stdout, "Not implemented!\n"); return; } CgiScriptNamePtr = CgiVar ("WWW_SCRIPT_NAME"); CgiServerNamePtr = CgiVar ("WWW_SERVER_NAME"); sys$gettim (&CurrentBinTime); sys$numtim (&CurrentNumTime, &CurrentBinTime); time (&UnixTime); UnixTmPtr = localtime (&UnixTime); if (!strftime (UnixDateTime, sizeof(UnixDateTime), "%a, %d %b %Y %T", UnixTmPtr)) strcpy (UnixDateTime, "[error]"); if (Debug) fprintf (stdout, "UnixDateTime |%s|\n", UnixDateTime); GetRequest (); ValidateRequest (); if (DoSummaryMenu || DoComprehensiveMenu) { SummaryMenu (); exit (SS$_NORMAL); } /* create file specification for processing data */ DataFileSpecLength = sprintf (DataFileSpec, "%sHYPERSPI_%s_%s_%%%%%%%%%%%%.DAT", HYPERSPI_DATA_DIRECTORY, HYPERSPI_DATA_VERSION, CgiFormNodePtr); if (Debug) fprintf (stdout, "DataFileSpec |%s|\n", DataFileSpec); if (DoPresentSummaryPage) PresentSummaryPage (); else if (DoDump) DumpData (); else if (DoGraph) GraphData (); else if (DoList) ListProcessedData (); exit (SS$_NORMAL); } /*****************************************************************************/ /* Get "command-line" parameters, whether from the command-line or from a configuration symbol or logical containing the equivalent. OSU scripts have the 'method', 'url' and 'protocol' supplied as P1, P2, P3 (these being detected and used by CGILIB), and are of no interest to this function. */ void GetParameters () { static char CommandLine [256]; static unsigned long Flags = 0; int idx, status, SkipParameters; unsigned short Length; char ch; char *aptr, *cptr, *clptr, *sptr; $DESCRIPTOR (CommandLineDsc, CommandLine); /*********/ /* begin */ /*********/ if ((clptr = getenv ("HYPERSPI$PARAM")) == NULL) { /* get the entire command line following the verb */ if (VMSnok (status = lib$get_foreign (&CommandLineDsc, 0, &Length, &Flags))) exit (status); (clptr = CommandLine)[Length] = '\0'; } /* if [C]SWS (VMS Apache) */ if (CgiLibEnvironmentIsApache()) { /* CSWS 1.2/3 look for something non-space outside of quotes */ for (cptr = clptr; *cptr; cptr++) { if (isspace(*cptr)) continue; if (*cptr != '\"') break; cptr++; while (*cptr && *cptr != '\"') cptr++; if (*cptr) cptr++; } /* CSWS 1.2/3 if nothing outside of quotes then ignore command line */ if (!*cptr) return; /* SWS 2.0 doesn't begin with /APACHE from DCL procedure wrapper */ if (!strsame (cptr, "/APACHE", 7)) return; } /* if OSU environment then skip P1, P2, P3 */ if (CgiLibEnvironmentIsOsu()) SkipParameters = 3; else SkipParameters = 0; aptr = NULL; ch = *clptr; for (;;) { if (aptr != NULL) *aptr = '\0'; if (!ch) break; *clptr = ch; if (Debug) fprintf (stdout, "clptr |%s|\n", clptr); while (*clptr && isspace(*clptr)) *clptr++ = '\0'; aptr = clptr; if (*clptr == '/') clptr++; while (*clptr && !isspace (*clptr) && *clptr != '/') { if (*clptr != '\"') { clptr++; continue; } cptr = clptr; clptr++; while (*clptr) { if (*clptr == '\"') if (*(clptr+1) == '\"') clptr++; else break; *cptr++ = *clptr++; } *cptr = '\0'; if (*clptr) clptr++; } ch = *clptr; if (*clptr) *clptr = '\0'; if (Debug) fprintf (stdout, "aptr |%s|\n", aptr); if (!*aptr) continue; if (SkipParameters) { SkipParameters--; continue; } if (strsame (aptr, "/APACHE", 4)) { /* just skip this marker for command-line parameters under SWS 2.0 */ continue; } if (strsame (aptr, "/BUTTONS=", 4)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; ButtonsPtr = cptr; continue; } if (strsame (aptr, "/CHARSET=", 4)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; CliCharsetPtr = cptr; continue; } if (strsame (aptr, "/DBUG", -1)) { Debug = true; continue; } if (strsame (aptr, "/DIRECTORY=", 3)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; HyperSpiDirectoryPtr = cptr; continue; } if (strsame (aptr, "/NODES=", 3)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; /* quick and nasty, no checks on array bounds (caveat emptor) */ idx = 0; while (*cptr) { sptr = SpiNodeNames[idx++]; while (*cptr && *cptr != ',') *sptr++ = toupper(*cptr++); *sptr = '\0'; if (*cptr) cptr++; } SpiNodeNames[idx][0] = '\0'; continue; } if (strsame (aptr, "/SHUTDOWN", 3)) { DoShutdownAgent = true; continue; } if (*aptr != '/') { fprintf (stdout, "%%%s-E-MAXPARM, too many parameters\n \\%s\\\n", Utility, aptr); exit (STS$K_ERROR | STS$M_INHIB_MSG); } else { fprintf (stdout, "%%%s-E-IVQUAL, unrecognized qualifier\n \\%s\\\n", Utility, aptr+1); exit (STS$K_ERROR | STS$M_INHIB_MSG); } } } /*****************************************************************************/ /* Create the navigation buttons. */ ButtonBar (int Top1Bottom2) { int idx; char *cptr, *sptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ButtonBar()\n"); fprintf (stdout, "
\n", Top1Bottom2 == 1 ? " butbartop" : ""); cptr = ButtonsPtr; /* back */ cptr = ButtonBarButton (cptr, NULL); /* calendar request form */ cptr = ButtonBarButton (cptr, CgiScriptNamePtr); /* any further buttons */ while (*cptr) cptr = ButtonBarButton (cptr, NULL); fprintf (stdout, "
\n"); } /*****************************************************************************/ /* Generate a single "button" inside the context created by ButtonBar(). */ char* ButtonBarButton ( char *ButtonLabel, char *ButtonPath ) { char *cptr, *sptr, *tptr, *uptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ButtonBarButton() |%s|\n", ButtonLabel); if (!*ButtonLabel) for (cptr = ButtonLabel = "*ERROR*"; *cptr; cptr++); else for (cptr = ButtonLabel; *cptr && *cptr != '=' && *cptr != '$'; cptr++); if (*ButtonLabel == '^') { ButtonLabel++; tptr = " target=\"_blank\""; } else tptr = ""; if (*cptr == '=') for (sptr = uptr = cptr+1; *sptr && *sptr != '$'; sptr++); else if (ButtonPath) sptr = (uptr = ButtonPath) + strlen(ButtonPath); else sptr = (uptr = "*ERROR*") + 8; if (!memcmp(uptr,"javascript:", 11)) fprintf (stdout, "\n", tptr, sptr-uptr, sptr-uptr, uptr, cptr-ButtonLabel, cptr-ButtonLabel, ButtonLabel); else fprintf (stdout, "%*.*s\n", tptr, sptr-uptr, sptr-uptr, uptr, cptr-ButtonLabel, cptr-ButtonLabel, ButtonLabel); while (*cptr && *cptr != '$') cptr++; while (*cptr && *cptr == '$') cptr++; return (cptr); } /*****************************************************************************/ /* Get the request CGI variables. */ void GetRequest () { char *cptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GetRequest()\n"); /* determine what has been requested */ CgiFormWhatPtr = CgiVar ("WWW_FORM_WHAT"); for (cptr = CgiFormWhatPtr; *cptr; cptr++) *cptr = toupper(*cptr); if (strsame (CgiFormWhatPtr, "CPU", -1)) ProvidePercentCPU = true; if (strstr (CgiFormWhatPtr, ",CPU") != NULL) ProvidePercentCPU = true; cptr = CgiVar ("WWW_FORM_CPU"); if (cptr[0]) ProvidePercentCPU = true; if (strstr (CgiFormWhatPtr, "MODES") != NULL) ProvidePercentModeCPU = true; cptr = CgiVar ("WWW_FORM_MODES"); if (cptr[0]) ProvidePercentModeCPU = true; if (strstr (CgiFormWhatPtr, "MODES_PIE") != NULL) ProvidePercentModeCPUPie = true; cptr = CgiVar ("WWW_FORM_MODES_PIE"); if (cptr[0]) ProvidePercentModeCPUPie = true; if (strstr (CgiFormWhatPtr, "LOCKS") != NULL) ProvideLocks = true; cptr = CgiVar ("WWW_FORM_LOCKS"); if (cptr[0]) ProvideLocks = true; if (strstr (CgiFormWhatPtr, "LOCKS_PIE") != NULL) ProvideLocksPie = true; cptr = CgiVar ("WWW_FORM_LOCKS_PIE"); if (cptr[0]) ProvideLocksPie = true; if (strstr (CgiFormWhatPtr, "BUFFERED") != NULL) ProvideBufferedIO = true; cptr = CgiVar ("WWW_FORM_BUFFERED_IO"); if (cptr[0]) ProvideBufferedIO = true; if (strstr (CgiFormWhatPtr, "PEAK_BUFFERED") != NULL) ProvidePeakBufferedIO = true; cptr = CgiVar ("WWW_FORM_PEAK_BUFFERED_IO"); if (cptr[0]) ProvidePeakBufferedIO = true; if (strstr (CgiFormWhatPtr, "DIRECT") != NULL) ProvideDirectIO = true; cptr = CgiVar ("WWW_FORM_DIRECT_IO"); if (cptr[0]) ProvideDirectIO = true; if (strstr (CgiFormWhatPtr, "PEAK_DIRECT") != NULL) ProvidePeakDirectIO = true; cptr = CgiVar ("WWW_FORM_PEAK_DIRECT_IO"); if (cptr[0]) ProvidePeakDirectIO = true; if (strstr (CgiFormWhatPtr, "MSCP") != NULL) ProvideMscpIO = true; cptr = CgiVar ("WWW_FORM_MSCP_IO"); if (cptr[0]) ProvideMscpIO = true; if (strstr (CgiFormWhatPtr, "PEAK_MSCP") != NULL) ProvidePeakMscpIO = true; cptr = CgiVar ("WWW_FORM_PEAK_MSCP_IO"); if (cptr[0]) ProvidePeakMscpIO = true; if (strstr (CgiFormWhatPtr, "FAULTS") != NULL) ProvidePageFaults = true; cptr = CgiVar ("WWW_FORM_FAULTS"); if (cptr[0]) ProvidePageFaults = true; if (strstr (CgiFormWhatPtr, "PEAK_FAULTS") != NULL) ProvidePeakPageFaults = true; cptr = CgiVar ("WWW_FORM_PEAK_FAULTS"); if (cptr[0]) ProvidePeakPageFaults = true; if (strstr (CgiFormWhatPtr, "HARD_FAULTS") != NULL) ProvideHardPageFaults = true; cptr = CgiVar ("WWW_FORM_HARD_FAULTS"); if (cptr[0]) ProvideHardPageFaults = true; if (strstr (CgiFormWhatPtr, "PEAK_HARD_FAULTS") != NULL) ProvidePeakHardPageFaults = true; cptr = CgiVar ("WWW_FORM_PEAK_HARD_FAULTS"); if (cptr[0]) ProvidePeakHardPageFaults = true; if (strstr (CgiFormWhatPtr, "SOFT_FAULTS") != NULL) ProvideSoftPageFaults = true; cptr = CgiVar ("WWW_FORM_SOFT_FAULTS"); if (cptr[0]) ProvideSoftPageFaults = true; if (strstr (CgiFormWhatPtr, "PEAK_SOFT_FAULTS") != NULL) ProvidePeakSoftPageFaults = true; cptr = CgiVar ("WWW_FORM_PEAK_SOFT_FAULTS"); if (cptr[0]) ProvidePeakSoftPageFaults = true; if (strstr (CgiFormWhatPtr, "MEMORY") != NULL) ProvideMemory = true; cptr = CgiVar ("WWW_FORM_MEMORY"); if (cptr[0]) ProvideMemory = true; if (strstr (CgiFormWhatPtr, "NET_INT") != NULL) ProvideNetInt = true; cptr = CgiVar ("WWW_FORM_NET_INT"); if (cptr[0]) ProvideNetInt = true; if (strstr (CgiFormWhatPtr, "PEAK_NET_INT") != NULL) ProvidePeakNetInt = true; cptr = CgiVar ("WWW_FORM_PEAK_NET_INT"); if (cptr[0]) ProvidePeakNetInt = true; if (strstr (CgiFormWhatPtr, "PROCESSES") != NULL) ProvideProcesses = true; cptr = CgiVar ("WWW_FORM_PROCESSES"); if (cptr[0]) ProvideProcesses = true; if (strstr (CgiFormWhatPtr, "COMPUTABLE") != NULL) ProvideCom = true; cptr = CgiVar ("WWW_FORM_COMPUTABLE"); if (cptr[0]) ProvideCom = true; CgiFormIncludePtr = CgiVar ("WWW_FORM_INCLUDE"); for (cptr = CgiFormIncludePtr; *cptr; cptr++) *cptr = toupper(*cptr); if (strstr (CgiFormIncludePtr, "PEAK") != NULL) IncludePeak = true; if (strstr (CgiFormIncludePtr, "TOTAL") != NULL) IncludeTotal = true; cptr = CgiVar ("WWW_FORM_FROM"); sscanf (cptr, "%4d-%2d-%2d %2d:%2d", &FromYear, &FromMonth, &FromDay, &FromHour, &FromMinute); cptr = CgiVar ("WWW_FORM_TO"); sscanf (cptr, "%4d-%2d-%2d %2d:%2d", &ToYear, &ToMonth, &ToDay, &ToHour, &ToMinute); CgiFormDoPtr = CgiVar ("WWW_FORM_DO"); CgiFormNodePtr = CgiVar ("WWW_FORM_NODE"); if (!CgiFormNodePtr[0]) CgiFormNodePtr = CgiVar ("WWW_FORM_LIST_NODE"); if (CgiFormNodePtr[0]) { /* ensure the node name is in upper case */ for (cptr = CgiFormNodePtr; *cptr; cptr++) *cptr = toupper(*cptr); } cptr = CgiVar ("WWW_FORM_EXTRACT"); if (cptr[0]) ExtractGraph = true; CgiFormPeriodPtr = CgiVar ("WWW_FORM_PERIOD"); cptr = CgiVar ("WWW_FORM_XMAG"); if (isdigit(cptr[0])) XMag = atoi (cptr); else XMag = 1; if (XMag > 4) XMag = 4; if (XMag < 1) XMag = 1; cptr = CgiVar ("WWW_FORM_YMAG"); if (isdigit(cptr[0])) YMag = atoi (cptr); else YMag = 1; if (YMag > 4) YMag = 4; if (YMag < 1) YMag = 1; if (strstr (CgiFormWhatPtr, "REFRESH") != NULL) RefreshTodayData = true; cptr = CgiVar ("WWW_FORM_REFRESH"); if (cptr[0]) RefreshTodayData = true; } /*****************************************************************************/ /* Process the request parameters (e.g. time, node name). Verify the parameters are within constraints, particular time. Process the time components into values the application can use. */ void ValidateRequest () { static long LibJulianDate = LIB$K_JULIAN_DATE; static char *MonthName [] = { "???", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; int status; unsigned long BinTime [2], DeltaTime [2]; unsigned short NumTime [7]; char Scratch [256]; $DESCRIPTOR (TempDsc, ""); /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ValidateRequest()\n"); if (!CgiFormDoPtr[0]) DoSummaryMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'G') DoGraph = true; else if (toupper(CgiFormDoPtr[0]) == 'P') DoPresentSummaryPage = true; else if (toupper(CgiFormDoPtr[0]) == 'C') DoComprehensiveMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'M') DoSummaryMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'D') DoDump = true; else if (toupper(CgiFormDoPtr[0]) == 'L') DoList = true; else { sprintf (Scratch, "Cannot do \"%s\"", CgiFormDoPtr); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } if ((DoPresentSummaryPage || DoGraph || DoList || DoDump) && !CgiFormNodePtr[0]) { CgiLibResponseError (FI_LI, 0, "Node name not specified."); exit (SS$_NORMAL); } /********************/ /* standard periods */ /********************/ if (CgiFormPeriodPtr[0] && toupper(CgiFormPeriodPtr[0]) != 'O') { /* a standard time period has been specified, other than "other" */ FromHour = 0; FromMinute = 0; ToHour = 23; ToMinute = 59; FromDay = ToDay = CurrentNumTime[2]; FromMonth = ToMonth = CurrentNumTime[1]; FromYear = ToYear = CurrentNumTime[0]; if (toupper(CgiFormPeriodPtr[0]) == 'U') { /* "until_now" (7am to this hour) */ FromHour = 7; ToHour = CurrentNumTime[3]; } else if (toupper(CgiFormPeriodPtr[0]) == 'B') { /* "business" hours (7am to 7pm) */ FromHour = 7; ToHour = 18; } else if (toupper(CgiFormPeriodPtr[0]) == 'T') { /* "today" */ ToHour = 23; } else if (toupper(CgiFormPeriodPtr[0]) == 'S' || toupper(CgiFormPeriodPtr[0]) == 'Y') { /* "since_yesterday" until now, or all of "yesterday" */ TempDsc.dsc$a_pointer = "1 00:00:00.00"; TempDsc.dsc$w_length = 13; if (VMSnok (status = sys$bintim (&TempDsc, &DeltaTime))) { CgiLibResponseError (FI_LI, status, CgiFormPeriodPtr); exit (SS$_NORMAL); } lib$sub_times (&CurrentBinTime, &DeltaTime, &BinTime); sys$numtim (&NumTime, &BinTime); FromDay = NumTime[2]; FromMonth = NumTime[1]; FromYear = NumTime[0]; if (toupper(CgiFormPeriodPtr[0]) == 'S') ToHour = CurrentNumTime[3]; else { ToDay = NumTime[2]; ToMonth = NumTime[1]; ToYear = NumTime[0]; } } else if (isdigit(CgiFormPeriodPtr[0])) { TempDsc.dsc$a_pointer = Scratch; TempDsc.dsc$w_length = sprintf (Scratch, "%s 00:00:00.00", CgiFormPeriodPtr); if (VMSnok (status = sys$bintim (&TempDsc, &DeltaTime))) { CgiLibResponseError (FI_LI, status, CgiFormPeriodPtr); exit (SS$_NORMAL); } lib$sub_times (&CurrentBinTime, &DeltaTime, &BinTime); sys$numtim (&NumTime, &BinTime); FromDay = NumTime[2]; FromMonth = NumTime[1]; FromYear = NumTime[0]; } else { CgiLibResponseError (FI_LI, 0, "Periods are \"until_now\""); exit (SS$_NORMAL); } } /*******************/ /* time components */ /*******************/ /* non-specified date components default to those of the current day */ if (!FromDay) FromDay = CurrentNumTime[2]; if (!FromMonth) FromMonth = CurrentNumTime[1]; if (!FromYear) FromYear = CurrentNumTime[0]; if (!ToDay) ToDay = CurrentNumTime[2]; if (!ToMonth) ToMonth = CurrentNumTime[1]; if (!ToYear) ToYear = CurrentNumTime[0]; /* bit of a sanity check (prevents 'MonthName[x]' access violating, etc.) */ if (FromMonth < 1 || FromMonth > 12) FromMonth = 0; if (ToMonth < 1 || ToMonth > 12) ToMonth = 0; /* ensure the commencement date/time is acceptable */ TempDsc.dsc$a_pointer = DateString; TempDsc.dsc$w_length = sprintf (DateString, "%d-%s-%d %02.02d:%02.02d", FromDay, MonthName[FromMonth], FromYear, FromHour, FromMinute); if (Debug) fprintf (stdout, "DateString |%s|\n", DateString); if (VMSnok (status = sys$bintim (&TempDsc, &BinTime))) { sprintf (Scratch, "%02.02d:%02.02d %02.02d/%02.02d/%02.02d", FromHour, FromMinute, FromDay, FromMonth, FromYear); CgiLibResponseError (FI_LI, status, Scratch); exit (SS$_NORMAL); } /* get the commencement julian date (number of days in epoch) */ lib$cvt_from_internal_time (&LibJulianDate, &FromJulianDate, &BinTime); /* ensure the conclusion date/time is acceptable */ TempDsc.dsc$a_pointer = ToDateString; TempDsc.dsc$w_length = sprintf (ToDateString, "%d-%s-%d %02.02d:%02.02d", ToDay, MonthName[ToMonth], ToYear, ToHour, ToMinute); if (Debug) fprintf (stdout, "ToDateString |%s|\n", ToDateString); if (VMSnok (status = sys$bintim (&TempDsc, &BinTime))) { sprintf (Scratch, "%02.02d:%02.02d %02.02d/%02.02d/%02.02d", ToHour, ToMinute, ToDay, ToMonth, ToYear); CgiLibResponseError (FI_LI, status, Scratch); exit (SS$_NORMAL); } /* get the conclusion julian date (number of days in epoch) */ lib$cvt_from_internal_time (&LibJulianDate, &ToJulianDate, &BinTime); /***************************/ /* calculate period values */ /***************************/ /* using julian dates, get number of days and hours sample period covers */ NumberOfHours = ((ToJulianDate - FromJulianDate) * 24) + ToHour - FromHour; NumberOfDays = (NumberOfHours / 24); if (DoPresentSummaryPage || DoGraph || DoList || DoDump) { if (NumberOfHours < 0 || (NumberOfHours == 0 && ToMinute <= FromMinute)) { sprintf (Scratch, "Beginning of period (%04.04d-%02.02d-%02.02d %02.02d:%02.02d) \ does not precede end (%04.04d-%02.02d-%02.02d %02.02d:%02.02d)!", FromYear, FromMonth, FromDay, FromHour, FromMinute, ToYear, ToMonth, ToDay, ToHour, ToMinute); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } if (NumberOfHours < 1) { CgiLibResponseError (FI_LI, 0, "Little point to such a short period!"); exit (SS$_NORMAL); } if (NumberOfDays > MAX_SAMPLE_PERIOD_DAYS) { sprintf (Scratch, "Maximum sample period is %d days.", MAX_SAMPLE_PERIOD_DAYS); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } } /* rate at which the data (and any graphic) must be X-axis compressed */ if (NumberOfHours <= 12) RecordSampleRate = 1; else if (NumberOfHours <= 24) RecordSampleRate = 2; else RecordSampleRate = (NumberOfDays + 1) * 2; /* add one to number of hours, for graphing purposes, re-calculate days */ NumberOfHours++; NumberOfDays = (NumberOfHours / 24); /* the number of minutes from midnight data begins being processed */ StartMinuteOnFirstDay = (FromHour * 60) + FromMinute; /* the current minute from the start of the specified period */ lib$cvt_from_internal_time (&LibJulianDate, &CurrentJulianDate, &CurrentBinTime); CurrentMinuteFromStartOfPeriod = ((((CurrentJulianDate - FromJulianDate) * 24) + (CurrentNumTime[3] - FromHour)) * 60) + CurrentNumTime[4]; if (Debug) fprintf (stdout, "FromJulianDate: %d ToJulianDate: %d\n\ NumberOfDays: %d NumberOfHours: %d RecordSampleRate: %d\n", FromJulianDate, ToJulianDate, NumberOfDays, NumberOfHours, RecordSampleRate); } /*****************************************************************************/ /* Provide either a standard or comprehensive menu allowing System Performance Information system, category and period to be specified. */ void SummaryMenu () { char *CheckedPtr, *TodayCheckedPtr, *UntilNowCheckedPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SummaryMenu()\n"); if (DoComprehensiveMenu) CheckedPtr = ""; else CheckedPtr = " checked"; CgiLibResponseHeader (200, "text/html"); fprintf (stdout, "\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ hyperSPI++, Summary Selector\n\ \n\ %s\ \n\ \n", SoftwareID, SoftwareCopy, CgiEnvironmentPtr, UnixDateTime, DefaultStyle, StyleSheetPtr); fprintf (stdout, "
\
hyperSPI++
\
Summary Selector
\
%d %s %d %0.2d:%0.2d
\
\n", CurrentNumTime[2], MonthName[CurrentNumTime[1]], CurrentNumTime[0], CurrentNumTime[3], CurrentNumTime[4]); HttpHasBeenOutput = true; fprintf (stdout, "
\n\
\n", CgiScriptNamePtr); SelectNodeNames (); if (DoComprehensiveMenu) { fputs ( "  or ... node
", stdout); } if (CurrentNumTime[3] >= 7) { UntilNowCheckedPtr = " checked"; TodayCheckedPtr = ""; } else { UntilNowCheckedPtr = ""; TodayCheckedPtr = " checked"; } fprintf (stdout, "

\n\ \ since 7am (until now)
\ today
\n\ \ since yesterday (until now)
\n\ yesterday
\n\ previous week  \n\ two weeks  \n\ four weeks
\n\ \n\ \ from\n\ \ to\n\ \  (yyyy-mm-dd hh:mm)\n\ \n\

\n\

\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n", UntilNowCheckedPtr, TodayCheckedPtr, CurrentNumTime[0], CurrentNumTime[1], CurrentNumTime[2], CurrentNumTime[3], CurrentNumTime[0], CurrentNumTime[1], CurrentNumTime[2], CheckedPtr); fprintf (stdout, "", CheckedPtr); if (DoComprehensiveMenu) { fputs ( " ", stdout); } if (DoComprehensiveMenu) { fputs ( " \ \n", stdout); fputs ( " \ \n", stdout); } fputs ("", stdout); if (DoComprehensiveMenu) { fputs (" ", stdout); } fputs ( "", stdout); if (DoComprehensiveMenu) { fputs ( " ", stdout); } fputs ( "", stdout); if (DoComprehensiveMenu) { fputs ( " ", stdout); } fputs ( "\n", stdout); fputs ( "", stdout); if (DoComprehensiveMenu) { fputs ( " ", stdout); } fputs ("
CPU CPU modes memory
processes \ computable processes paging peak
\ paging (soft) \ peak \ paging (hard) \ peak
disk IO peak other IO peak MSCP IO\" \ peak
\ locking activity network peak

\n", stdout); if (DoComprehensiveMenu) { fputs ( "\ include peak plot (where applicable)\n\

\n\ graph\n\ (X,Y magnification:\ ,\ )
\n\ list
\n\ dump
\n\ \n\

\n", stdout); } else { fputs ( "\n", stdout); } fputs ( "

\n\ \n", stdout); fputs ( " \ Refresh today data   \n", stdout); if (!DoComprehensiveMenu) { fputs ( " \ double-height graph   \n", stdout); } fprintf (stdout, "\n\

\n\ \n\

\n"); SelectorPtr = NULL; ButtonBar (2); fprintf (stdout, "\n\n"); } /*****************************************************************************/ /* Output a list of node names that data can be selected from. Get these either from a command-line-supplied list or from data files present for the current day. */ void SelectNodeNames () { int idx; char *CheckedPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SelectNodeNames()\n"); if (SpiNodeNames[0][0]) { NodeCount = 0; for (idx = 0; SpiNodeNames[idx][0]; idx++) NodeCount++; if (NodeCount <= MAX_NODE_COUNT_BEFORE_SELECT) { CheckedPtr = " checked"; for (idx = 0; SpiNodeNames[idx][0]; idx++) { fprintf (stdout, " %s
\n", SpiNodeNames[idx], CheckedPtr, SpiNodeNames[idx]); CheckedPtr = ""; } } else { CheckedPtr = " selected"; fprintf (stdout, "\n", stdout); } } else { /* create file specification for getting node names (today's files) */ DataFileSpecLength = sprintf (DataFileSpec, "%sHYPERSPI_%s_*_%02.02d%02.02d%02.02d.DAT", HYPERSPI_DATA_DIRECTORY, HYPERSPI_DATA_VERSION, FromDay, FromMonth, FromYear%100); if (Debug) fprintf (stdout, "DataFileSpec |%s|\n", DataFileSpec); /* count the number of node data files */ ProcessDataFiles (NULL, false); NodeCount = DataFilesFoundCount; if (NodeCount <= MAX_NODE_COUNT_BEFORE_SELECT) ProcessDataFiles (&SelectNodeNameByDataFileName, false); else { fprintf (stdout, "\n", stdout); } } } /*****************************************************************************/ /* Called by pointer to function each time a matching data file is returned by sys$search(0 in function FindDataFiles(). Output the node name associated with the data file. */ void SelectNodeNameByDataFileName () { static char *CheckedPtr = " checked"; static char *SelectedPtr = " selected"; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SelectNodeNameByFileName() |%s|\n", DataFileName); if (NodeCount < MAX_NODE_COUNT_BEFORE_SELECT) { fprintf (stdout, " %s
\n", DataNode, CheckedPtr, DataNode); CheckedPtr = ""; } else { fprintf (stdout, "

\
hyperSPI++
\
Summary for %s
\
%d %s %d %0.2d:%0.2d
\
\n", CgiFormNodePtr, CurrentNumTime[2], MonthName[CurrentNumTime[1]], CurrentNumTime[0], CurrentNumTime[3], CurrentNumTime[4]); fprintf (stdout, "
\n"); fflush (stdout); HttpHasBeenOutput = true; fprintf (stdout, "\n\n", FromDay, MonthName[FromMonth], FromYear, FromHour, FromMinute, ToDay, MonthName[ToMonth], ToYear, ToHour, ToMinute); /* summarize the data and calculate required averages */ SummarizeData (); if (DataRecordsProcessedCount) { IncludeFile (CgiFormNodePtr); fprintf (stdout, "\n\ \n\ \n\ \n\
Period:"); if ((!NumberOfDays && NumberOfHours == 24) || NumberOfDays == 1) fputs ("1 day", stdout); else if (NumberOfDays > 1) fprintf (stdout, "%d days", NumberOfDays); if ((PeriodHours = (NumberOfHours % 24)) == 1) fputs ("1 hour", stdout); else if (PeriodHours > 1) fprintf (stdout, " %d hours", PeriodHours); fprintf (stdout, ", from %02.02d %s %d %02.02d:%02.02d to %02.02d %s %d %02.02d:%02.02d\
CPUs:%d
Memory:%dMB physical, %dMB page space \ (%dmb total)
Processes:%d average, %d peak
\ (x axes are marked at hour intervals)
\n\

\n", NumberOfCPUs, SystemMemoryMBytes, PageSpaceMBytes, SystemMemoryMBytes+PageSpaceMBytes, AveNumberOfProcesses, MaxNumberOfProcesses); if (ProvidePercentCPU) PresentCPU (); if (ProvidePercentModeCPU || ProvidePercentModeCPUPie) PresentCPUModes (); if (ProvideLocks || ProvideLocksPie) PresentLocks (); if (ProvideMemory) PresentMemory (); if (ProvideProcesses) PresentProcesses (); if (ProvideCom) PresentCom (); if (ProvidePageFaults || ProvideSoftPageFaults) PresentPageFaults (); if (ProvidePeakPageFaults || ProvidePeakSoftPageFaults) PresentPeakPageFaults (); if (ProvideHardPageFaults) PresentHardPageFaults (); if (ProvidePeakHardPageFaults) PresentPeakHardPageFaults (); if (ProvideBufferedIO) PresentBufferedIO (); if (ProvidePeakBufferedIO) PresentPeakBufferedIO (); if (ProvideDirectIO) PresentDirectIO (); if (ProvidePeakDirectIO) PresentPeakDirectIO (); if (ProvideMscpIO) PresentMscpIO (); if (ProvidePeakMscpIO) PresentPeakMscpIO (); if (ProvideNetInt) PresentNetInt (); if (ProvidePeakNetInt) PresentPeakNetInt (); } else fputs ("No data available.\n", stdout); fprintf (stdout, "

\n"); ButtonBar (2); fprintf (stdout, "\n\n"); } /*****************************************************************************/ /* Place an HTML link into the HTTP output stream to get a plot-data, GIF image, generated dynamically by this application, embedded in the current HTML document. The 'UniqueNumber()' is used to place a unique component into the URL of the graph GIF URL, ensuring a cached version is not retrieved. The 'WhatPtr' is the name of the performance count to graph. The optional 'IncludePtr' allows selected graphs to contain additional information. */ GraphImageLink ( boolean InlineImage, char *WhatPtr, char *IncludePtr, ... ) { #define LABEL_UNITS 0 #define LABEL_Y1 1 #define LABEL_Y2 2 #define LABEL_X1 3 #define LABEL_X2 4 int argcnt, idx; char *Labels[5] = { NULL,NULL,NULL,NULL,NULL }; va_list argptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphImageLink()\n"); va_count (argcnt); if (argcnt < 3 || argcnt > 8) exit (SS$_BUGCHECK); /* labels: Y units, Y axis 1, Y axis 2, X axis 1, X axis 2 */ idx = 0; va_start (argptr, IncludePtr); for (argcnt -= 3; argcnt; argcnt--) Labels[idx++] = (char*)va_arg (argptr, char*); va_end (argptr); for (idx = 0; idx < 5; idx++) if (!Labels[idx]) Labels[idx] = ""; if (InlineImage) { fprintf (stdout, "\n\ \n\ \n\ \ \n\
%s\n\ \"[graph]\"\n\ %s
%s
%s%s
\n", Labels[LABEL_Y2], Labels[LABEL_UNITS], Labels[LABEL_X1], Labels[LABEL_X2]); } else fputs ("\">Extract Graph\n", stdout); } /*****************************************************************************/ /* CPU usage. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void SectionHeading (char *String) { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SectionHeading() |%s|\n", String); fprintf (stdout, "\n\

\n\

%s
\n\

\n\

\n", String); } /*****************************************************************************/ /* CPU usage. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentCPU () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentCPU()\n"); SectionHeading ("CPU Usage"); GraphImageLink (true, "cpu", "peak"); fprintf (stdout, "Y axis is percentage. \ Histogram is average, plot is peak \ (total of available %d CPU(s)).\n\
Overall %d%% average, %d%% peak \ (\ interrupt %d%%, \ MP-sync %d%%, \ kernel %d%%, \ exec %d%%, \ super %d%%, \ user %d%%\ ).\n", NumberOfCPUs, AvePercentCPU, PeakPercentCPU, AvePercentModeCPU[HYPERSPI_MODE_INTERRUPT], AvePercentModeCPU[HYPERSPI_MODE_MULTIPROC], AvePercentModeCPU[HYPERSPI_MODE_KERNEL], AvePercentModeCPU[HYPERSPI_MODE_EXECUTIVE], AvePercentModeCPU[HYPERSPI_MODE_SUPERVISOR], AvePercentModeCPU[HYPERSPI_MODE_USER]); if (ExtractGraph) GraphImageLink (false, "cpu", "peak"); } /*****************************************************************************/ /* CPU usage. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentCPUModes () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentCPUModes()\n"); SectionHeading ("CPU Modes Usage"); GraphImageLink (true, "modes", "peak"); fprintf (stdout, "Y axis is percentage. \ Histogram is average, plot is peak \ (total of available %d CPU(s)).\n\
Overall %d%% average, %d%% peak \ (\ interrupt %d%%, \ MP-sync %d%%, \ kernel %d%%, \ exec %d%%, \ super %d%%, \ user %d%%\ ).\n", NumberOfCPUs, AvePercentCPU, PeakPercentCPU, AvePercentModeCPU[HYPERSPI_MODE_INTERRUPT], AvePercentModeCPU[HYPERSPI_MODE_MULTIPROC], AvePercentModeCPU[HYPERSPI_MODE_KERNEL], AvePercentModeCPU[HYPERSPI_MODE_EXECUTIVE], AvePercentModeCPU[HYPERSPI_MODE_SUPERVISOR], AvePercentModeCPU[HYPERSPI_MODE_USER]); if (ExtractGraph) GraphImageLink (false, "modes", "peak"); GraphImageLink (true, "modes_pie", ""); } /*****************************************************************************/ /* Locking activity. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentLocks () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentLocks()\n"); SectionHeading ("Locking activity (Enq + EnqCvt)"); GraphImageLink (true, "locks", "peak"); fprintf (stdout, "Y axis is percentage. \ Histogram is average, \
Overall %d average \ (\ incoming %d/s, \ outgoing %d/s, \ local %d/s\ ).\n", AveLck, AveLckIn, AveLckOut, AveLckLoc); if (ExtractGraph) GraphImageLink (false, "locks", ""); if (AveLckIn || AveLckOut || AveLckLoc) GraphImageLink (true, "locks_pie", ""); } /*****************************************************************************/ /* Page space and physical memory usage. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentMemory () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentMemory()\n"); SectionHeading ("Memory Usage"); GraphImageLink (true, "memory", ""); fprintf (stdout, "Y axis is percentage. \ Histogram is page space (%dMb) usage, plot is physical memory (%dMb).\n\
Overall page space %d%% average, %d%% peak; \ physical memory %d%% average, %d%% peak.\n", PageSpaceMBytes, SystemMemoryMBytes, AvePageSpacePercentInUse, MaxPageSpacePercentInUse, AveSystemMemoryPercentInUse, MaxSystemMemoryPercentInUse); if (ExtractGraph) GraphImageLink (false, "memory", ""); } /*****************************************************************************/ /* Number of processes. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentProcesses () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentProcesses()\n"); SectionHeading ("Number of Processes"); GraphImageLink (true, "processes", ""); fprintf (stdout, "Y axis is number of processes.\n\
Overall %d average, maximum %d.\n", AveNumberOfProcesses, MaxNumberOfProcesses); if (ExtractGraph) GraphImageLink (false, "processes", ""); } /*****************************************************************************/ void PresentCom () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentCom()\n"); SectionHeading ("Number of Computable Processes"); GraphImageLink (true, "computable", ""); fprintf (stdout, "Y axis is number of computable processes.\n\
Overall %d average, maximum %d.\n", AveNumberOfCom, MaxNumberOfCom); if (ExtractGraph) GraphImageLink (false, "computable", ""); } /*****************************************************************************/ /* Buffered IO (non-disk, non-tape, i.e. network, terminal). Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentBufferedIO () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentBufferedIO()\n"); SectionHeading ("Buffered IO (network, terminal, etc.)"); if (IncludePeak) { GraphImageLink (true, "buffered_IO", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "buffered_IO", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is IOs per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AveBufferedIO, MaxAveBufferedIO, PeakBufferedIO); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "buffered_IO", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "buffered_IO", ""); } /*****************************************************************************/ /* Peak buffered IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakBufferedIO () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakBufferedIO()\n"); SectionHeading ("Peak Buffered IO (network, terminal, etc.)"); GraphImageLink (true, "peak_buffered_IO", ""); fprintf (stdout, "Y axis is IOs per-second. \n\
Peak %d per-second.\n", PeakBufferedIO); if (ExtractGraph) GraphImageLink (false, "peak_buffered_IO", ""); } /*****************************************************************************/ /* Direct IO (disk, tape, etc). Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentDirectIO () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentDirectIO()\n"); SectionHeading ("Direct IO (disk, tape, etc.)"); if (IncludePeak) { GraphImageLink (true, "direct_IO", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "direct_IO", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is IOs per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AveDirectIO, MaxAveDirectIO, PeakDirectIO); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "direct_IO", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "direct_IO", ""); } /*****************************************************************************/ /* Peak direct IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakDirectIO () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakDirectIO()\n"); SectionHeading ("Peak Direct IO (disk, tape, etc.)"); GraphImageLink (true, "peak_direct_IO", ""); fprintf (stdout, "Y axis is IOs per-second. \n\
Peak %d per-second.\n", PeakDirectIO); if (ExtractGraph) GraphImageLink (false, "peak_direct_IO", ""); } /*****************************************************************************/ /* MSCP IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentMscpIO () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentMscpIO()\n"); SectionHeading ("MSCP IO (served disk and tape)"); if (IncludePeak) { GraphImageLink (true, "mscp_IO", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "mscp_IO", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is IOs per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AveMscpIO, MaxAveMscpIO, PeakMscpIO); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "mscp_IO", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "mscp_IO", ""); } /*****************************************************************************/ /* Peak mscp IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakMscpIO () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakMscpIO()\n"); SectionHeading ("Peak MSCP IO (served disk and tape)"); GraphImageLink (true, "peak_mscp_IO", ""); fprintf (stdout, "Y axis is IOs per-second.\n\
Peak %d per-second.\n", PeakMscpIO); if (ExtractGraph) GraphImageLink (false, "peak_mscp_IO", ""); } /*****************************************************************************/ /* */ void PresentNetInt () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentNetInt()\n"); SectionHeading ("Network Interface"); if (IncludePeak) { GraphImageLink (true, "net_int", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "net_int", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is network interface traffic bytes per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AveNetInt, MaxAveNetInt, PeakNetInt); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "net_int", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "net_int", ""); } /*****************************************************************************/ /* Peak network interface. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakNetInt () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakNetInt()\n"); SectionHeading ("Peak Network Interface"); GraphImageLink (true, "peak_net_int", ""); fprintf (stdout, "Y axis is network interface traffic bytes per-second.\n\
Peak %d per-second.\n", PeakNetInt); if (ExtractGraph) GraphImageLink (false, "peak_net_int", ""); } /*****************************************************************************/ /* Page faulting IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPageFaults () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPageFaults()\n"); if (ProvidePageFaults) SectionHeading ("Paging"); else SectionHeading ("Paging (Soft)"); if (IncludePeak) { GraphImageLink (true, "faults", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "faults", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is page faults per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AvePageFaults, MaxAvePageFaults, PeakPageFaults); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "faults", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "faults", ""); } /*****************************************************************************/ /* Peak paging to disk. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakPageFaults () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakPageFaults()\n"); SectionHeading ("Peak Paging (Soft)"); GraphImageLink (true, "peak_faults", ""); fprintf (stdout, "Y axis is page faults per-second. \n\
Peak %d per-second.\n", PeakPageFaults); if (ExtractGraph) GraphImageLink (false, "peak_faults", ""); } /*****************************************************************************/ /* Page faulting IO. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentHardPageFaults () { char *ExplainPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentHardPageFaults()\n"); SectionHeading ("Paging To Disk"); if (IncludePeak) { GraphImageLink (true, "hard_faults", "peak"); ExplainPtr = " Histogram is average, plot is peak."; } else { GraphImageLink (true, "hard_faults", ""); ExplainPtr = ""; } fprintf (stdout, "Y axis is IOs per-second.%s\n\
Overall %d average, maximum %d, peak %d.\n", ExplainPtr, AveHardPageFaults, MaxAveHardPageFaults, PeakHardPageFaults); if (IncludePeak) if (ExtractGraph) GraphImageLink (false, "hard_faults", "peak"); else; else if (ExtractGraph) GraphImageLink (false, "hard_faults", ""); } /*****************************************************************************/ /* Peak paging to disk. Place textual information and a graphic GIF image link into the current HTML document being generated. */ void PresentPeakHardPageFaults () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "PresentPeakHardPageFaults()\n"); SectionHeading ("Peak Paging To Disk"); GraphImageLink (true, "peak_hard_faults", ""); fprintf (stdout, "Y axis is IOs per-second. \n\
Peak %d per-second.\n", PeakHardPageFaults); if (ExtractGraph) GraphImageLink (false, "peak_hard_faults", ""); } /*****************************************************************************/ /* Read all records for the specified node in the specified time range, calculating the average and maximum for each of the data categories. Assumes it is only to be called once as it does not initialize any of the storage. */ void SummarizeData () { int i; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SummarizeData()\n"); ProcessDataFiles (&SummarizeRecord, true); /* the averaging must be by the actual sample rate */ DataRecordsProcessedCount /= RecordSampleRate; if (!DataRecordsProcessedCount) return; AvePercentCPU /= DataRecordsProcessedCount; for (i = 0; i < HYPERSPI_CPU_MODE_COUNT; ++i) AvePercentModeCPU[i] /= DataRecordsProcessedCount; AveSystemMemoryPercentInUse /= DataRecordsProcessedCount; AveNumberOfProcesses /= DataRecordsProcessedCount; AveNumberOfCom /= DataRecordsProcessedCount; AvePageSpacePercentInUse /= DataRecordsProcessedCount; AvePageFaults /= DataRecordsProcessedCount; AveHardPageFaults /= DataRecordsProcessedCount; AveBufferedIO /= DataRecordsProcessedCount; AveDirectIO /= DataRecordsProcessedCount; AveMscpIO /= DataRecordsProcessedCount; AveLck /= DataRecordsProcessedCount; AveLckLoc /= DataRecordsProcessedCount; AveLckIn /= DataRecordsProcessedCount; AveLckOut /= DataRecordsProcessedCount; AveNetInt /= DataRecordsProcessedCount; AveNetIntRx /= DataRecordsProcessedCount; AveNetIntTx /= DataRecordsProcessedCount; } /*****************************************************************************/ /* Set the various accumulators according to the data in the current 'SpiRecord'. */ void SummarizeRecord () { static unsigned long RecordCount = 0, NumberOfProcesses = 0, NumberOfCom = 0, SystemMemoryPercentInUse = 0, PageSpacePercentInUse = 0, PercentCPU = 0, PercentModeCPU[HYPERSPI_CPU_MODE_COUNT] = {0, 0, 0, 0, 0, 0}, BufferedIO = 0, DirectIO = 0, MscpIO = 0, PageFaults = 0, HardPageFaults = 0; #ifndef __VAX static unsigned __int64 NetRxTx; #else static unsigned long NetRxTx; #endif int idx; unsigned long tmp; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SummarizeRecord()\n"); /* usually (though not unconditionally) these remain constant! */ if (SpiRecord.NumberOfCPUs > NumberOfCPUs) NumberOfCPUs = SpiRecord.NumberOfCPUs; if (SpiRecord.SystemMemoryMBytes > SystemMemoryMBytes) SystemMemoryMBytes = SpiRecord.SystemMemoryMBytes; if (SpiRecord.PageSpaceMBytes > PageSpaceMBytes) PageSpaceMBytes = SpiRecord.PageSpaceMBytes; /* The percentage CPU values VERY OCCASIONALLY get slightly above 100%. I attribute this behaviour to slight inconsistancies between obtaining system times and actually obtaining the CPU usage data, i.e. to the delta-time used to calculate the percentage. I chose to "massage" the data at the display end rather than the collection/recording end so that this behaviour could be monitored by using the "dump" facility to examine the actual data. */ if (SpiRecord.PercentCPU > 100) SpiRecord.PercentCPU = 100; if (SpiRecord.PeakPercentCPU > 100) SpiRecord.PeakPercentCPU = 100; for (idx = 0; idx < HYPERSPI_CPU_MODE_COUNT; ++idx) if (SpiRecord.PercentModeCPU[idx] > 100) SpiRecord.PercentModeCPU[idx] = 100; /* peaks are always taken as absolutes! */ if (SpiRecord.PeakPercentCPU > PeakPercentCPU) PeakPercentCPU = SpiRecord.PeakPercentCPU; if (SpiRecord.PeakBufferedIO > PeakBufferedIO) PeakBufferedIO = SpiRecord.PeakBufferedIO; if (SpiRecord.PeakDirectIO > PeakDirectIO) PeakDirectIO = SpiRecord.PeakDirectIO; if (SpiRecord.PeakMscpIO > PeakMscpIO) PeakMscpIO = SpiRecord.PeakMscpIO; if (SpiRecord.PeakPageFaults > PeakPageFaults) PeakPageFaults = SpiRecord.PeakPageFaults; if (SpiRecord.PeakHardPageFaults > PeakHardPageFaults) PeakHardPageFaults = SpiRecord.PeakHardPageFaults; /* down convert to kB */ #ifndef __VAX *(__int64*)SpiRecord.NetIntRx = *(__int64*)SpiRecord.NetIntRx >> 10; *(__int64*)SpiRecord.NetIntTx = *(__int64*)SpiRecord.NetIntTx >> 10; #else SpiRecord.NetIntRx[0] = SpiRecord.NetIntRx[0] >> 10; SpiRecord.NetIntTx[0] = SpiRecord.NetIntTx[0] >> 10; #endif SpiRecord.PeakNetIntRx = SpiRecord.PeakNetIntRx >> 10; SpiRecord.PeakNetIntTx = SpiRecord.PeakNetIntTx >> 10; SpiRecord.PeakNetIntRxTx = SpiRecord.PeakNetIntRxTx >> 10; if (SpiRecord.PeakNetIntRxTx > PeakNetIntRxTx) PeakNetIntRxTx = SpiRecord.PeakNetIntRxTx; if (RecordSampleRate > 1) { /* X axis compression, i.e. less than one record per plot point */ PercentCPU += SpiRecord.PercentCPU; PercentUserModeCPU += SpiRecord.PercentUserModeCPU; NumberOfProcesses += SpiRecord.NumberOfProcesses; SystemMemoryPercentInUse += SpiRecord.SystemMemoryPercentInUse; PageSpacePercentInUse += SpiRecord.PageSpacePercentInUse; BufferedIO += SpiRecord.BufferedIO; DirectIO += SpiRecord.DirectIO; MscpIO += SpiRecord.MscpIO; PageFaults += SpiRecord.PageFaults; HardPageFaults += SpiRecord.HardPageFaults; #ifndef __VAX NetRxTx += *(__int64*)SpiRecord.NetIntRx + *(__int64*)SpiRecord.NetIntTx; #else NetRxTx += SpiRecord.NetIntRx[0] + SpiRecord.NetIntTx[0]; #endif if (++RecordCount < RecordSampleRate) return; /* average by dividing the accumlated values by the record sample rate */ SpiRecord.PercentCPU = PercentCPU / RecordCount; SpiRecord.PercentUserModeCPU = PercentUserModeCPU / RecordCount; SpiRecord.NumberOfProcesses = NumberOfProcesses / RecordCount; SpiRecord.SystemMemoryPercentInUse = SystemMemoryPercentInUse / RecordCount; SpiRecord.PageSpacePercentInUse = PageSpacePercentInUse / RecordCount; SpiRecord.BufferedIO = BufferedIO / RecordCount; SpiRecord.DirectIO = DirectIO / RecordCount; SpiRecord.MscpIO = MscpIO / RecordCount; SpiRecord.PageFaults = PageFaults / RecordCount; SpiRecord.HardPageFaults = HardPageFaults / RecordCount; NetRxTx /= RecordCount; /* reset the accumulators to zero */ PercentCPU = PercentUserModeCPU = NumberOfProcesses = SystemMemoryPercentInUse = PageSpacePercentInUse = BufferedIO = DirectIO = MscpIO = NetIntRxTx = PageFaults = HardPageFaults = RecordCount = 0; } else { #ifndef __VAX NetRxTx = *(__int64*)SpiRecord.NetIntRx + *(__int64*)SpiRecord.NetIntTx; #else NetRxTx = SpiRecord.NetIntRx[0] + SpiRecord.NetIntTx[0]; #endif } /* this will need to be divided by the number of records processed */ AvePercentCPU += SpiRecord.PercentCPU; PercentUserModeCPU += SpiRecord.PercentUserModeCPU; if (SpiRecord.PeakPercentUserModeCPU > PeakPercentUserModeCPU) PeakPercentUserModeCPU = SpiRecord.PeakPercentUserModeCPU; /* this will need to be divided by the number of records processed */ for (idx = 0; idx < HYPERSPI_CPU_MODE_COUNT; ++idx) AvePercentModeCPU[idx] += SpiRecord.PercentModeCPU[idx]; /* this will need to be divided by the number of records processed */ AveNumberOfProcesses += SpiRecord.NumberOfProcesses; if (SpiRecord.NumberOfProcesses > MaxNumberOfProcesses) MaxNumberOfProcesses = SpiRecord.NumberOfProcesses; /* this will need to be divided by the number of records processed */ AveNumberOfCom += SpiRecord.Computable; if (SpiRecord.Computable > MaxNumberOfCom) MaxNumberOfCom = SpiRecord.Computable; /* this will need to be divided by the number of records processed */ AveSystemMemoryPercentInUse += SpiRecord.SystemMemoryPercentInUse; if (SpiRecord.SystemMemoryPercentInUse > MaxSystemMemoryPercentInUse) MaxSystemMemoryPercentInUse = SpiRecord.SystemMemoryPercentInUse; /* this will need to be divided by the number of records processed */ AvePageSpacePercentInUse += SpiRecord.PageSpacePercentInUse; if (SpiRecord.PageSpacePercentInUse > MaxPageSpacePercentInUse) MaxPageSpacePercentInUse = SpiRecord.PageSpacePercentInUse; AveBufferedIO += (tmp = SpiRecord.BufferedIO / 60); if (tmp > MaxAveBufferedIO) MaxAveBufferedIO = tmp; AveDirectIO += (tmp = SpiRecord.DirectIO / 60); if (tmp > MaxAveDirectIO) MaxAveDirectIO = tmp; AveMscpIO += (tmp = SpiRecord.MscpIO / 60); if (tmp > MaxAveMscpIO) MaxAveMscpIO = tmp; AvePageFaults += (tmp = SpiRecord.PageFaults / 60); if (tmp > MaxAvePageFaults) MaxAvePageFaults = tmp; AveHardPageFaults += (tmp = SpiRecord.HardPageFaults / 60); if (tmp > MaxAveHardPageFaults) MaxAveHardPageFaults = tmp; AveLck += ((SpiRecord.LckLoc + SpiRecord.LckIn + SpiRecord.LckOut) / 60); AveLckLoc += (SpiRecord.LckLoc / 60); AveLckIn += (SpiRecord.LckIn / 60); AveLckOut += (SpiRecord.LckOut / 60); AveNetIntRxTx += (tmp = (unsigned long)(NetRxTx / 60)); if (tmp > MaxAveNetIntRxTx) MaxAveNetIntRxTx = tmp; } /*****************************************************************************/ /* The application is being called to plot a graph of the data of the specified node in the specified time range, and generate a GIF image of that graph and return it to the browser. */ void GraphData () { int i, j, Xcnt, Ycnt, AtX, AtY, graphDeltaHour, widthHour; char* str; unsigned long clr[7] = /* {0xFF8080, 0x8080FF}; */ {0xFFCCCC, 0x0000CC, 0x00FFFF, 0xFF66CC, 0x33CC33, 0xFF9900, 0xFFFFFF}; /* set which slices to explode, and by how much */ int expl[] = { 0, 0, 0, 0, 0, 0, 0 }; /* set missing slices */ unsigned char missing[] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; int graphWidth; int pieGraph = 0; char chartTitle[60] = ""; char pieTitle[60] = ""; /*********/ /* begin */ /*********/ GDC_title = chartTitle; GDCPIE_title = pieTitle; if (Debug) fprintf (stdout, "GraphData()\n"); #ifdef GIF_EXPIRED CgiLibResponseHeader (200, "image/jpeg", "Expires: Fri, 13 Jan 1978 14:30:00 GMT\n"); #else CgiLibResponseHeader (200, "image/jpeg"); #endif fflush (stdout); #ifdef __DECC /*+ Causes records to be written only when explicitly specified by a call to fflush, close, or fclose. -*/ if ((stdout = freopen ("SYS$OUTPUT", "w", stdout, "ctx=xplct")) == NULL) exit (vaxc$errno); #endif SizeOfPlotX = NumberOfHours * 60 * XMag / RecordSampleRate; SizeOfPlotY = 100 + 150 * YMag; graphWidth = 800; widthHour = SizeOfPlotX / NumberOfHours; if (NumberOfHours <= 24) graphDeltaHour = 1; else if (NumberOfHours <= 48) graphDeltaHour = 4; else if (NumberOfHours <= 192) graphDeltaHour = 12; else graphDeltaHour = 24; if (Debug) fprintf (stdout, "size %d,%d\n", SizeOfPlotX, SizeOfPlotY); HaveDataY = SizeOfMarginY / 6; for (i = 0; i < 6; ++i) Values[i] = calloc(SizeOfPlotX, sizeof(float)); #ifdef NEWLIB_GDCHART GDC_interpolations = FALSE; #endif Labels = calloc(SizeOfPlotX, sizeof(char*)); str = calloc(SizeOfPlotX * 12, 1); /* 7 characters maximum for labels */ for (i = 0; i < SizeOfPlotX; ++i) { Labels[i] = str; Labels[i][0] = '\0'; for (j = 0; j < 6; ++j) #ifdef NEWLIB_GDCHART Values[j][i] = (GDC_interpolations ? GDC_INTERP_VALUE : GDC_NOVALUE); #else Values[j][i] = GDC_NOVALUE; #endif str += 12; } { int status; unsigned long binTime [2]; unsigned long deltaTime [2]; char dateString [256]; $DESCRIPTOR (tempDsc, ""); static char* MonthName [] = { "???", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; tempDsc.dsc$a_pointer = "1 00:00:00.00"; tempDsc.dsc$w_length = 13; if (VMSnok (status = sys$bintim (&tempDsc, &deltaTime))) { CgiLibResponseError (FI_LI, status, CgiFormPeriodPtr); exit (SS$_NORMAL); } tempDsc.dsc$a_pointer = dateString; tempDsc.dsc$w_length = sprintf (dateString, "%d-%s-%d %02.02d:%02.02d", FromDay, MonthName[FromMonth], FromYear, FromHour, FromMinute); if (VMSnok (status = sys$bintim (&tempDsc, &binTime))) { sprintf (dateString, "%02.02d:%02.02d %02.02d/%02.02d/%02.02d", FromHour, FromMinute, FromDay, FromMonth, FromYear); CgiLibResponseError (FI_LI, status, dateString); exit (SS$_NORMAL); } for (i = 0; i < NumberOfHours;) { sprintf(Labels[widthHour * i], "%02d", (FromHour + i) % 24); i += graphDeltaHour; } if (NumberOfHours > 24) { unsigned short numTime [7]; if (FromHour) lib$add_times(&binTime, &deltaTime, &binTime); for (i = (24 - FromHour) % 24; i < NumberOfHours;) { sys$numtim(&numTime, &binTime); sprintf(Labels[widthHour * i], "%02d/%02d", numTime[2], numTime[1]); lib$add_times(&binTime, &deltaTime, &binTime); i += 24; } } } if (ProvidePercentCPU) { /* process specified data calling 'GraphRecordCPU()' for each record */ GraphLinesCnt = 1; ChartType = GDC_AREA; sprintf(GDC_title, "CPU Usage %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordCPU, true); } else if (ProvidePercentModeCPU) { /* process specified data calling 'GraphRecordCPU()' for each record */ GraphLinesCnt = 6; ChartType = GDC_AREA; sprintf(GDC_title, "CPU Modes Usage %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordCPUModes, true); } else if (ProvidePercentModeCPUPie) { int i; /* process specified data calling 'GraphRecordCPU()' for each record */ pieGraph = 1; GraphLinesCnt = 7; sprintf(GDCPIE_title, "CPU Modes Usage %s", CgiFormNodePtr); SummarizeData(); Values[0][0] = AvePercentModeCPU[HYPERSPI_MODE_INTERRUPT]; Values[0][1] = AvePercentModeCPU[HYPERSPI_MODE_MULTIPROC]; Values[0][2] = AvePercentModeCPU[HYPERSPI_MODE_KERNEL]; Values[0][3] = AvePercentModeCPU[HYPERSPI_MODE_EXECUTIVE]; Values[0][4] = AvePercentModeCPU[HYPERSPI_MODE_SUPERVISOR]; Values[0][5] = AvePercentModeCPU[HYPERSPI_MODE_USER]; Values[0][6] = 100; for (i = 0; i < 6; ++i) { if (Values[0][i] == 0) Values[0][i] = 0.1; Values[0][6] -= Values[0][i]; } if (Values[0][6] <= 0) Values[0][6] = 0.1; #if LONG_LABEL Labels[0] = "Interrupt"; Labels[1] = "MP-Sync"; Labels[2] = "Kernel"; Labels[3] = "Executive"; Labels[4] = "Supervisor"; Labels[5] = "User"; Labels[6] = "NULL"; #else Labels[0] = "I"; Labels[1] = "M"; Labels[2] = "K"; Labels[3] = "E"; Labels[4] = "S"; Labels[5] = "U"; Labels[6] = "N"; #endif } else if (ProvideLocks) { /* process specified data calling 'GraphRecordLocks()' for each record */ GraphLinesCnt = 3; ChartType = GDC_AREA; sprintf(GDC_title, "Locking activity (Enq + EnqCvt) %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordLocks, true); } else if (ProvideLocksPie) { /* process specified data calling 'GraphRecordLocks()' for each record */ pieGraph = 1; GraphLinesCnt = 3; sprintf(GDCPIE_title, "Locking activity (Enq + EnqCvt) %s", CgiFormNodePtr); SummarizeData(); Values[0][0] = AveLckIn / (float)(AveLckIn + AveLckOut + AveLckLoc); if (Values[0][0] == 0) Values[0][0] = 0.1; Values[0][1] = AveLckOut / (float)(AveLckIn + AveLckOut + AveLckLoc); if (Values[0][1] == 0) Values[0][1] = 0.1; Values[0][2] = 100 - Values[0][0] - Values[0][1]; Labels[0] = "Incoming"; Labels[1] = "outgoing"; Labels[2] = "Local"; } else if (ProvideMemory) { /* process specified data calling 'GraphRecordMemory()' for each record */ clr[0] = 0xFF8080; ChartType = GDC_LINE; GraphLinesCnt = 2; sprintf(GDC_title, "Memory Usage %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordMemory, true); } else if (ProvideBufferedIO || ProvidePeakBufferedIO || ProvideDirectIO || ProvidePeakDirectIO || ProvideMscpIO || ProvidePeakMscpIO || ProvidePageFaults || ProvidePeakPageFaults || ProvideNetInt || ProvidePeakNetInt || ProvideHardPageFaults || ProvidePeakHardPageFaults || ProvideSoftPageFaults || ProvidePeakSoftPageFaults || ProvideProcesses || ProvideCom) { /* summarize the data to determine the required Y axis */ SummarizeData (); if (ProvideProcesses) { /* process data calling 'GraphRecordProcesses()' for each record */ GraphLinesCnt = 1; ChartType = GDC_LINE; sprintf(GDC_title, "Number of Processes %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordProcesses, true); } else if (ProvideCom) { /* process data calling 'GraphRecordCom()' for each record */ GraphLinesCnt = 1; ChartType = GDC_AREA; sprintf(GDC_title, "Number of Computable Processes %s", CgiFormNodePtr); ProcessDataFiles (&GraphRecordCom, true); } else if (ProvidePageFaults) { GraphLinesCnt = 2; sprintf(GDC_title, "Paging %s", CgiFormNodePtr); ChartType = GDC_AREA; ProcessDataFiles (&GraphRecordRange, true); } else if (ProvideNetInt) { GraphLinesCnt = 2; sprintf(GDC_title, "Network Interface %s", CgiFormNodePtr); ChartType = GDC_AREA; ProcessDataFiles (&GraphRecordRange, true); } else { /* process data calling 'GraphRecordRange()' for each record */ ChartType = GDC_AREA; GraphLinesCnt = 1; if (IncludePeak) GraphLinesCnt = 2; ProcessDataFiles (&GraphRecordRange, true); } } else { CgiLibResponseError (FI_LI, 0, "Internal error."); exit (SS$_NORMAL); } #ifndef NEWLIB_GDCHART GDC_output_type = GDC_JPEG; #endif #if 0 GDC_xtitle = malloc(100); sprintf(GDC_xtitle, "%s", "xtitle); GDC_ytitle = malloc(100); #endif #ifdef __DECC if ((stdout = freopen ("SYS$OUTPUT", "wb", stdout, "ctx=xplct")) == NULL) exit (vaxc$errno); #endif if (GraphLinesCnt == 1) { clr[0] = 0xFF8080; clr[1] = 0x8080FF; } /* ----- call the lib ----- */ if (pieGraph) { /* set options */ /* a lot of options are set here for illustration */ /* none need be - see gdcpie.h for defaults */ GDCPIE_label_line = TRUE; GDCPIE_label_dist = 20; /* dist. labels to slice edge */ /* can be negative */ GDCPIE_LineColor = 0x000000L; GDCPIE_label_size = GDC_GIANT; #if 0 GDCPIE_3d_depth = 25; GDCPIE_3d_angle = 45; /* 0 - 359 */ #endif GDCPIE_explode = expl; /* default: NULL - no explosion */ GDCPIE_Color = clr; GDCPIE_BGColor = 0xFFFFFFL; GDCPIE_EdgeColor = 0x000000L; /* default is GDCPIE_NOCOLOR */ /* for no edging */ /* add percentage to slice label */ /* below the slice label */ GDCPIE_percent_labels = GDCPIE_PCT_RIGHT; GDCPIE_missing = missing; /* default: NULL - none missing */ GDCPIE_percent_labels = GDCPIE_PCT_RIGHT; /* call the lib */ pie_gif(480, /* width */ 360, /* height */ stdout, /* open file pointer */ GDC_2DPIE, /* GDC_3DPIE or GDC_2DPIE */ GraphLinesCnt, /* number of slices */ Labels, /* slice labels (unlike out_gif(), can be NULL */ Values[0]); /* data array */ } else { GDC_BGColor = 0xFFFFFFL; /* backgound color (white) */ GDC_LineColor = 0x000000L; /* line color (black) */ GDC_SetColor = &(clr[0]); /* assign set colors */ GDC_xlabel_spacing = MAXSHORT; GDC_requested_ymax = 0; GDC_ylabel_density = 20; GDC_grid = FALSE; /*+ If all values are 0 out_graph -> floating/decimal divide by zero -*/ for (i = 0; i < SizeOfPlotX; ++i) #ifdef NEWLIB_GDCHART if (Values[0][i] != 0 && Values[0][i] != GDC_NOVALUE && Values[0][i] != GDC_INTERP_VALUE) break; #else if (Values[0][i] != 0 && Values[0][i] != GDC_NOVALUE) break; #endif if (i >= SizeOfPlotX) { Values[0][0] = Values[0][SizeOfPlotX - 1] = 1; } out_graph(graphWidth, SizeOfPlotY, /* short width, height */ stdout, /* FILE* open FILE pointer */ ChartType, /* GDC_CHART_T chart type */ SizeOfPlotX, /* int number of points per data set */ Labels, /* char*[] array of X labels */ GraphLinesCnt, /* int number of data sets */ Values[0], /* float[] data set 1 */ Values[1], /* float[] data set 2 */ Values[2], /* float[] data set 3 */ Values[3], /* float[] data set 4 */ Values[4], /* float[] data set 5 */ Values[5]); /* ... data set 6 */ } } /*****************************************************************************/ /* Plot a CPU record. Either total or user-mode usage, as a line from zero to the percentage value uasage. Optionally and additionally, plot peak total or user-mode usage, or total usage (for use with the user-mode line plot) as a single point. Plot has a Y axis fixed to representPeak 100 percent. */ void GraphRecordCPU () { int Xcnt, Ycnt, ToY, AtX, AtY; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordCPU()\n"); /* The percentage CPU values VERY OCCASIONALLY get slightly above 100%. I attribute this behaviour to slight inconsistancies between obtaining system times and actually obtaining the CPU usage data, i.e. to the delta-time used to calculate the percentage. I chose to "massage" the data at the display end rather than the collection/recording end so that this behaviour could be monitored by using the "dump" facility to examine the actual data. */ if (SpiRecord.PercentCPU > 100) SpiRecord.PercentCPU = 100; if (SpiRecord.PeakPercentCPU > 100) SpiRecord.PeakPercentCPU = 100; if (SpiRecord.PercentUserModeCPU > 100) SpiRecord.PercentUserModeCPU = 100; if (SpiRecord.PeakPercentUserModeCPU > 100) SpiRecord.PeakPercentUserModeCPU = 100; /*********************/ /* plot the value(s) */ /*********************/ AtX = (NumberOfMinutesIntoData / RecordSampleRate); assert(AtX < SizeOfPlotX); /* no value 100 for a nice graph */ if (ProvidePercentCPU) { Values[0][AtX] = (SpiRecord.PercentCPU >= 100) ? 99.999 : (float)SpiRecord.PercentCPU; } } /*****************************************************************************/ /* */ void GraphRecordCPUModes () { int i, Xcnt, Ycnt, ToY, AtX, AtY; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordCPU()\n"); /* The percentage CPU values VERY OCCASIONALLY get slightly above 100%. I attribute this behaviour to slight inconsistancies between obtaining system times and actually obtaining the CPU usage data, i.e. to the delta-time used to calculate the percentage. I chose to "massage" the data at the display end rather than the collection/recording end so that this behaviour could be monitored by using the "dump" facility to examine the actual data. */ if (SpiRecord.PercentCPU > 100) SpiRecord.PercentCPU = 100; if (SpiRecord.PeakPercentCPU > 100) SpiRecord.PeakPercentCPU = 100; /* stack values */ for (i = 1; i < HYPERSPI_CPU_MODE_COUNT; ++i) { SpiRecord.PercentModeCPU[i] += SpiRecord.PercentModeCPU[i - 1]; } /*********************/ /* plot the value(s) */ /*********************/ AtX = (NumberOfMinutesIntoData / RecordSampleRate); assert(AtX < SizeOfPlotX); /* no value 100 for a nice graph */ for (i = 0; i < HYPERSPI_CPU_MODE_COUNT; ++i) { Values[i][AtX] = (SpiRecord.PercentModeCPU[i] >= 100) ? 99.999 : (float)SpiRecord.PercentModeCPU[i]; } } /*****************************************************************************/ /* Plot page space usage as a line from zero to percentage used. Plot physical memory as a point at the percentage used. Plot has a Y axis fixed to represent 100 percent. */ void GraphRecordMemory () { int Xcnt, Ycnt, ToY, AtX, AtY; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordMemory()\n"); AtX = (NumberOfMinutesIntoData / RecordSampleRate); assert(AtX < SizeOfPlotX); ToY = SpiRecord.PageSpacePercentInUse; AtY = SpiRecord.SystemMemoryPercentInUse; Values[0][AtX] = (float)AtY; Values[1][AtX] = (float)ToY; } /*****************************************************************************/ /* Plot the number oif processes on the system as plot-points (forming a semi-continuous line). Requires a variable range for the Y axis. That is data that can vary considerably in the maximum value represented on the Y axis. */ void GraphRecordProcesses () { int Xcnt, Ycnt, AtX, AtY; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordProcesses()\n"); AtX = (NumberOfMinutesIntoData / RecordSampleRate); AtY = SpiRecord.NumberOfProcesses; Values[0][AtX] = (float)AtY; } /*****************************************************************************/ /* */ void GraphRecordCom () { int Xcnt, Ycnt, AtX, AtY; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordCom()\n"); AtX = (NumberOfMinutesIntoData / RecordSampleRate); AtY = SpiRecord.Computable; Values[0][AtX] = (float)AtY; } /*****************************************************************************/ /* */ void GraphRecordLocks () { int AtX; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordLocks()\n"); /* stack values In, Out, Local*/ SpiRecord.LckOut += SpiRecord.LckIn; SpiRecord.LckLoc += SpiRecord.LckOut; AtX = (NumberOfMinutesIntoData / RecordSampleRate); Values[0][AtX] = (float)(SpiRecord.LckIn / 60); Values[1][AtX] = (float)(SpiRecord.LckOut / 60); Values[2][AtX] = (float)(SpiRecord.LckLoc / 60); } /*****************************************************************************/ /* Plot values that require a variable range for the Y axis. That is data that can vary considerably in the maximum value represented on the Y axis. */ void GraphRecordRange () { static unsigned long StaticPeakValue = 0, StaticValue = 0; int Xcnt, Ycnt, ToY, AtX, AtY; unsigned long PeakValue, Value; unsigned long PeakValueB, ValueB; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GraphRecordRange()\n"); if (ProvideBufferedIO) { Value = SpiRecord.BufferedIO; PeakValue = SpiRecord.PeakBufferedIO; sprintf(GDC_title, "Buffered IO %s", CgiFormNodePtr); } else if (ProvidePeakBufferedIO) { Value = PeakValue = SpiRecord.PeakBufferedIO; sprintf(GDC_title, "Peak Buffered IO %s", CgiFormNodePtr); } else if (ProvideDirectIO) { Value = SpiRecord.DirectIO; PeakValue = SpiRecord.PeakDirectIO; sprintf(GDC_title, "Direct IO %s", CgiFormNodePtr); } else if (ProvidePeakDirectIO) { Value = PeakValue = SpiRecord.PeakDirectIO; sprintf(GDC_title, "Peak Direct IO %s", CgiFormNodePtr); } else if (ProvideMscpIO) { Value = SpiRecord.MscpIO; PeakValue = SpiRecord.PeakMscpIO; sprintf(GDC_title, "MSCP IO %s", CgiFormNodePtr); } else if (ProvidePeakMscpIO) { Value = PeakValue = SpiRecord.PeakMscpIO; sprintf(GDC_title, "Peak MSCP IO %s", CgiFormNodePtr); } else if (ProvideNetInt) { #ifndef __VAX Value = (unsigned long)(*(__int64*)SpiRecord.NetIntRx + *(__int64*)SpiRecord.NetIntTx); PeakValue = SpiRecord.PeakNetIntRxTx; ValueB = (unsigned long)*(__int64*)SpiRecord.NetIntRx; PeakValueB = SpiRecord.PeakNetIntRx; #else Value = SpiRecord.NetIntRx[0] + SpiRecord.NetIntTx[0]; PeakValue = SpiRecord.PeakNetIntRxTx; ValueB = SpiRecord.NetIntRx[0]; PeakValueB = SpiRecord.PeakNetIntRx; #endif sprintf(GDC_title, "Network %s", CgiFormNodePtr); } else if (ProvidePeakNetInt) { #ifndef __VAX Value = (unsigned long)(*(__int64*)SpiRecord.NetIntRx + *(__int64*)SpiRecord.NetIntTx); PeakValue = SpiRecord.PeakNetIntRxTx; ValueB = (unsigned long)*(__int64*)SpiRecord.NetIntRx; PeakValueB = SpiRecord.PeakNetIntRx; #else Value = SpiRecord.NetIntRx[0] + SpiRecord.NetIntTx[0]; PeakValue = SpiRecord.PeakNetIntRxTx; ValueB = SpiRecord.NetIntRx[0]; PeakValueB = SpiRecord.PeakNetIntRx; #endif sprintf(GDC_title, "Peak network %s", CgiFormNodePtr); } else if (ProvidePageFaults) { Value = SpiRecord.PageFaults; PeakValue = SpiRecord.PeakPageFaults; ValueB = SpiRecord.HardPageFaults; PeakValueB = SpiRecord.PeakHardPageFaults; sprintf(GDC_title, "Page Faults %s", CgiFormNodePtr); } else if (ProvidePeakPageFaults) { Value = PeakValue = SpiRecord.PeakPageFaults; sprintf(GDC_title, "Peak Pages Faults %s", CgiFormNodePtr); } else if (ProvideSoftPageFaults) { Value = SpiRecord.PageFaults; PeakValue = SpiRecord.HardPageFaults; sprintf(GDC_title, "Soft Pages Faults %s", CgiFormNodePtr); } else if (ProvidePeakSoftPageFaults) { Value = PeakValue = SpiRecord.PeakPageFaults; sprintf(GDC_title, "Peak Soft Pages Faults %s", CgiFormNodePtr); } else if (ProvideHardPageFaults) { Value = SpiRecord.HardPageFaults; PeakValue = SpiRecord.PeakHardPageFaults; sprintf(GDC_title, "Hard Pages Faults %s", CgiFormNodePtr); } else if (ProvidePeakHardPageFaults) { Value = PeakValue = SpiRecord.PeakHardPageFaults; sprintf(GDC_title, "Peak Hard Pages Faults %s", CgiFormNodePtr); } if (Debug) fprintf (stdout, "\"%s\" Value: %d PeakValue: %d\n", GDC_title, Value, PeakValue); /*********************/ /* plot the value(s) */ /*********************/ AtX = (NumberOfMinutesIntoData / RecordSampleRate); if (ProvideBufferedIO || ProvideDirectIO || ProvideMscpIO || ProvideSoftPageFaults || ProvideHardPageFaults) Values[0][AtX] = (float)(Value / 60); else if (ProvidePageFaults || ProvideNetInt) { Values[1][AtX] = (float)(Value / 60); Values[0][AtX] = (float)(ValueB / 60); return; } else Values[0][AtX] = PeakValue; if (IncludePeak) AtY = PeakValue; else { /* no, nothing extra to plot! */ return; } Values[0][AtX] = (float)AtY; } /*****************************************************************************/ /* */ void ListProcessedData () { /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ListProcessedData()\n"); CgiLibResponseHeader (200, "text/html"); fprintf (stdout, "\n\ \n\ \n\ \n\ \n\ \n\ \n\ hyperSPI++ - Processed Data - %s\n\ \n\ %s\ \n\ \n", SoftwareID, SoftwareCopy, CgiEnvironmentPtr, CgiFormNodePtr, DefaultStyle, StyleSheetPtr); fprintf (stdout, "
\
hyperSPI++
\
Processed Data for %s
\
%d %s %d %0.2d:%0.2d
\
\n", CgiFormNodePtr, CurrentNumTime[2], MonthName[CurrentNumTime[1]], CurrentNumTime[0], CurrentNumTime[3], CurrentNumTime[4]); fprintf (stdout, "
\n"); HttpHasBeenOutput = true; ProcessDataFiles (&ListProcessedRecord, true); if (DataFilesProcessedCount) fputs ("\n
\n", stdout); else fputs ("

No matching data files.\n

\n", stdout); ButtonBar (2); fprintf (stdout, "\n\n"); } /*****************************************************************************/ /* */ void ListProcessedRecord () { static int PrevDay = -1, PrevHour = -1; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ListProcessedRecord()\n"); if (DataDay != PrevDay) { if (PrevDay != -1) fputs ("\n", stdout); PrevDay = DataDay; fprintf (stdout, "
%s  %02.02d %s %d
\n\
%s
\n\
",
      CgiFormNodePtr, DataDay, MonthName[DataMonth], DataYear,
      DataFileName);
   }

   if (SpiRecord.Hour != PrevHour)
   {
      if (PrevHour != -1) fputs ("\n", stdout);
      PrevHour = SpiRecord.Hour;
      fprintf (stdout,
"hh:mm  CPU usr  mem pge  b-IO peak  d-IO peak  mscp peak   flts  peak  \
hard peak  \
       NI rx         peak        NI tx         peak   rx+tx peak\n\
-----  --- ---  --- ---  ---- ----  ---- ----  ---- ----  ----- -----  \
---- ----  \
------------ ------------ ------------ ------------ ------------\n");
   }

   fprintf (stdout,
"%02.02d:%02.02d  %3d %3d  %3d %3d  \
%4d %4d  %4d %4d  %4d %4d  %5d %5d  %4d %4d  ",
   SpiRecord.Hour, SpiRecord.Minute,
   SpiRecord.PercentCPU, SpiRecord.PercentUserModeCPU,
   SpiRecord.SystemMemoryPercentInUse,
   SpiRecord.PageSpacePercentInUse,
   SpiRecord.BufferedIO / 60, SpiRecord.PeakBufferedIO,
   SpiRecord.DirectIO / 60, SpiRecord.PeakDirectIO,
   SpiRecord.MscpIO / 60, SpiRecord.PeakMscpIO,
   SpiRecord.PageFaults / 60, SpiRecord.PeakPageFaults,
   SpiRecord.HardPageFaults / 60, SpiRecord.PeakHardPageFaults);

#ifndef __VAX
   fprintf (stdout,
"%12Lu %12u %12Lu %12u %12u\n",
            *(__int64*)&SpiRecord.NetIntRx,
            SpiRecord.PeakNetIntRx,
            *(__int64*)&SpiRecord.NetIntTx,
            SpiRecord.PeakNetIntTx,
            SpiRecord.PeakNetIntRxTx);
#else
   fprintf (stdout,
"%12u %12u %12u %12u %12u\n",
            SpiRecord.NetIntRx[0],
            SpiRecord.PeakNetIntRx,
            SpiRecord.NetIntTx[0],
            SpiRecord.PeakNetIntTx,
            SpiRecord.PeakNetIntRxTx);
#endif
}

/*****************************************************************************/
/*
*/

void DumpData ()

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "DumpData()\n");

   CgiLibResponseHeader (200, "text/html");

   fprintf (stdout,
"\n\
\n\
\n\
\n\
\n\
\n\
\n\
hyperSPI++ - Data Dump - %s\n\
\n\
%s\
\n\
\n",
            SoftwareID, SoftwareCopy,
            CgiEnvironmentPtr,
            CgiFormNodePtr,
            DefaultStyle,
            StyleSheetPtr);

   fprintf (stdout,
"
\
hyperSPI++
\
Data Dump for %s
\
%d %s %d %0.2d:%0.2d
\
\n", CgiFormNodePtr, CurrentNumTime[2], MonthName[CurrentNumTime[1]], CurrentNumTime[0], CurrentNumTime[3], CurrentNumTime[4]); fprintf (stdout, "
\n"); HttpHasBeenOutput = true; ProcessDataFiles (&DumpRecord, true); if (DataFilesProcessedCount) fputs ("
\n\n", stdout); else fputs ("

No matching data files.\n\n", stdout); ButtonBar (2); fprintf (stdout, "\n\n"); } /*****************************************************************************/ /* */ void DumpRecord() { static int PrevDay = -1, PrevHour = -1; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "DumpRecord()\n"); if (DataDay != PrevDay) { if (PrevDay != -1) fputs ("\n", stdout); PrevDay = DataDay; fprintf (stdout, "

%s  %02.02d %s %d
\n\
%s
\n\
",
      CgiFormNodePtr, DataDay, MonthName[DataMonth], DataYear,
      DataFileName);
   }

   if (SpiRecord.Hour != PrevHour)
   {
      fputs ("\n", stdout);
      PrevHour = SpiRecord.Hour;
      fprintf (stdout,
"hh:mm  prc  CPU  pk  usr  pk  mem pge   buf-IO    peak  \
 dir-IO    peak  mscp-IO    peak   faults    peak   hard  peak com \
int mps krn exe sup usr Lck-Loc Lck-In  Lck-Out  \
          rx         peak           tx         peak   rx+tx peak\n\
-----  ---  --- ---  --- ---  --- ---  ------- -------  \
------- -------  ------- -------  ------- -------  ----- ----- --- \
--- --- --- --- --- --- ------- ------- -------  \
------------ ------------ ------------ ------------ ------------\n");
   }

   fprintf (stdout,
"%02.02d:%02.02d  %3d  %3d %3d  %3d %3d  %3d %3d  \
%7d %7d  %7d %7d  %7d %7d  %7d %7d  %5d %5d %3d \
%3d %3d %3d %3d %3d %3d %7d %7d %7d  ",
   SpiRecord.Hour, SpiRecord.Minute,
   SpiRecord.NumberOfProcesses,
   SpiRecord.PercentCPU, SpiRecord.PeakPercentCPU,
   SpiRecord.PercentUserModeCPU, SpiRecord.PeakPercentUserModeCPU,
   SpiRecord.SystemMemoryPercentInUse,
   SpiRecord.PageSpacePercentInUse,
   SpiRecord.BufferedIO, SpiRecord.PeakBufferedIO,
   SpiRecord.DirectIO, SpiRecord.PeakDirectIO,
   SpiRecord.MscpIO, SpiRecord.PeakMscpIO,
   SpiRecord.PageFaults, SpiRecord.PeakPageFaults,
   SpiRecord.HardPageFaults, SpiRecord.PeakHardPageFaults,
   SpiRecord.Computable,
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_INTERRUPT],
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_MULTIPROC],
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_KERNEL],
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_EXECUTIVE],
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_SUPERVISOR],
   SpiRecord.PercentModeCPU[HYPERSPI_MODE_USER],
   SpiRecord.LckLoc,
   SpiRecord.LckIn,
   SpiRecord.LckOut);

#ifndef __VAX
   fprintf (stdout,
"%12Lu %12u %12Lu %12u %12u\n",
            *(__int64*)&SpiRecord.NetIntRx,
            SpiRecord.PeakNetIntRx,
            *(__int64*)&SpiRecord.NetIntTx,
            SpiRecord.PeakNetIntTx,
            SpiRecord.PeakNetIntRxTx);
#else
   fprintf (stdout,
"%12u %12u %12u %12u %12u\n",
            SpiRecord.NetIntRx[0],
            SpiRecord.PeakNetIntRx,
            SpiRecord.NetIntTx[0],
            SpiRecord.PeakNetIntTx,
            SpiRecord.PeakNetIntRxTx);
#endif
}

/*****************************************************************************/
/*
The first parameter to this function is the address (a pointer to) the 
function used to process each file name found.
*/ 
 
int ProcessDataFiles
(
int (*ProcessFileFunction)(),
boolean OpenDataFile
)
{
   char  *cptr, *sptr;

   int  status;
   char  ExpandedFileName [256],
         Scratch [256];
   struct FAB  SearchFab;
   struct RAB  SearchRab;
   struct NAM  SearchNam;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "ProcessDataFiles() |%s|\n", DataFileSpec);

   DataFilesFoundCount = DataFilesProcessedCount =
      DataRecordsReadCount = DataRecordsProcessedCount = 0;

   SearchFab = cc$rms_fab;
   SearchFab.fab$l_fna = DataFileSpec;
   SearchFab.fab$b_fns = DataFileSpecLength;
   SearchFab.fab$l_fop = FAB$M_NAM;
   SearchFab.fab$l_nam = &SearchNam;

   SearchNam = cc$rms_nam;
   SearchNam.nam$l_esa = ExpandedFileName;
   SearchNam.nam$b_ess = sizeof(ExpandedFileName)-1;
   SearchNam.nam$l_rsa = DataFileName;
   SearchNam.nam$b_rss = sizeof(DataFileName)-1;

   if (VMSnok (status = sys$parse (&SearchFab, 0, 0)))
   {
      if (Debug) fprintf (stdout, "sys$parse() %%X%08.08X\n", status);
      CgiLibResponseError (FI_LI, status, DataFileSpec);
      exit (SS$_NORMAL);
   }

   while (VMSok (status = sys$search (&SearchFab, 0, 0)))
   {
      DataFilesFoundCount++;

      SearchNam.nam$l_ver[SearchNam.nam$b_ver] = '\0';
      DataFileNameLength = SearchNam.nam$b_rsl;
      if (Debug) fprintf (stdout, "DataFileName |%s|\n", DataFileName);

      /*
         Pull the node name and time components from the data file name.
         Format: "HYPERSPI_v_node_ddmmyy.DAT"
         ("v" represents the data file version, a single digit number)
      */
      cptr = SearchNam.nam$l_name;
      /* skip "HYPERSPI_version_" */
      while (*cptr && *cptr != '_') cptr++;
      if (*cptr) cptr++;
      while (*cptr && *cptr != '_') cptr++;
      if (*cptr) cptr++;
      /* get the node name this data represents */
      sptr = DataNode;
      while (*cptr && *cptr != '_') *sptr++ = *cptr++;
      *sptr = '\0';
      if (*cptr) cptr++;
      /* get the day, month and year */
      sptr = Scratch;
      if (*cptr) *sptr++ = *cptr++;
      if (*cptr) *sptr++ = *cptr++;
      *sptr = '\0';
      DataDay = atoi (Scratch);
      sptr = Scratch;
      if (*cptr) *sptr++ = *cptr++;
      if (*cptr) *sptr++ = *cptr++;
      *sptr = '\0';
      DataMonth = atoi (Scratch);
      sptr = Scratch;
      if (*cptr) *sptr++ = *cptr++;
      if (*cptr) *sptr++ = *cptr++;
      *sptr = '\0';
      DataYear = atoi (Scratch);
      if (Debug)
         fprintf (stdout, "data-file-name |%s|%d|%d|%d|\n",
                  DataNode, DataDay, DataMonth, DataYear);

      /* filter on year, month and day */
      if (DataYear <= 90)
         DataYear += 2000;
      else
         DataYear += 1900;
      if (DataYear < FromYear || DataYear > ToYear) continue;
      if (DataYear == FromYear)
      {
         if (DataMonth < FromMonth) continue;
         if (DataMonth == FromMonth && DataDay < FromDay) continue;
      }
      if (DataYear == ToYear)
      {
         if (DataMonth > ToMonth) continue;
         if (DataMonth == ToMonth && DataDay > ToDay) continue;
      }

      DataFilesProcessedCount++;

      /* can be used to just count the number of matching files! */
      if (ProcessFileFunction == NULL) continue;

      if (OpenDataFile)
         ProcessDataFileRecords (ProcessFileFunction);
      else
         /* by pointer, call the function to process this file name */
         (*ProcessFileFunction) ();
   }
   if (Debug) fprintf (stdout, "sys$search() %%X%08.08X\n", status);

   if (SearchFab.fab$l_sts == RMS$_FNF || SearchFab.fab$l_sts == RMS$_NMF)
      return (SS$_NORMAL);

   CgiLibResponseError (FI_LI, status, DataFileSpec);
   exit (SS$_NORMAL);
}

/*****************************************************************************/
/*
Open the 'DataFileName', read each record and call a specified function to 
process it, then close the file.  The first parameter to this function is the 
address (a pointer to) the function used to process the SPI data record.
*/ 

void ProcessDataFileRecords (int (*ProcessDataFunction)(struct HyperSpiData*))

{
   static long  LibJulianDate = LIB$K_JULIAN_DATE;
   static unsigned short  PrevNumTime [7] = {0,0,0,0,0,0,0};

   int  status;
   unsigned long  JulDate,
                  BinTime [2];
   struct FAB  DataFileFab;
   struct RAB  DataFileRab;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "ProcessDataFileRecords() |%s|\n", DataFileName);

   DataFileFab = cc$rms_fab;
   DataFileFab.fab$b_fac = FAB$M_GET;
   DataFileFab.fab$l_fna = DataFileName;  
   DataFileFab.fab$b_fns = DataFileNameLength;
   DataFileFab.fab$b_shr = FAB$M_SHRGET | FAB$M_SHRPUT;

   if (VMSnok (status = sys$open (&DataFileFab, 0, 0)))
   {
      if (Debug) fprintf (stdout, "sys$open() %%X%08.08X\n", status);
      if (status == RMS$_FNF)
      {
         CgiLibResponseError (FI_LI, status, DataNode);
         exit (SS$_NORMAL);
      }
      CgiLibResponseError (FI_LI, status, DataNode);
      exit (SS$_NORMAL);
   }

   DataFileRab = cc$rms_rab;
   DataFileRab.rab$l_fab = &DataFileFab;
   /* 2 buffers and read ahead performance option */
   DataFileRab.rab$b_mbf = 2;
   DataFileRab.rab$l_rop = RAB$M_RAH;
   DataFileRab.rab$l_ubf = (char*)&SpiRecord;
   DataFileRab.rab$w_usz = sizeof(SpiRecord);

   if (VMSnok (status = sys$connect (&DataFileRab, 0, 0)))
   {
      if (Debug) fprintf (stdout, "sys$connect() %%X%08.08X\n", status);
      sys$close (&DataFileFab, 0, 0);
      CgiLibResponseError (FI_LI, status, DataNode);
      exit (SS$_NORMAL);
   }

   while (VMSok (status = sys$get (&DataFileRab, 0, 0)))
   {
      DataRecordsReadCount++;

      /* filter on hour and minute */
      if (SpiRecord.Day == FromDay)
      {
         if (SpiRecord.Hour < FromHour) continue;
         if (SpiRecord.Hour == FromHour && SpiRecord.Minute < FromMinute)
            continue;
      }
      if (SpiRecord.Day == ToDay)
      {
         if (SpiRecord.Hour > ToHour) continue;
         if (SpiRecord.Hour == ToHour && SpiRecord.Minute > ToMinute) continue;
      }

      if (SpiRecord.Hour != PrevNumTime[3] ||
          SpiRecord.Day != PrevNumTime[2] ||
          SpiRecord.Month != PrevNumTime[1] ||
          SpiRecord.Year != PrevNumTime[0])
      {
         PrevNumTime[3] = SpiRecord.Hour;
         PrevNumTime[2] = SpiRecord.Day;
         PrevNumTime[1] = SpiRecord.Month;
         PrevNumTime[0] = SpiRecord.Year;

         lib$cvt_vectim (&PrevNumTime, &BinTime);
         lib$cvt_from_internal_time (&LibJulianDate, &JulDate, &BinTime);
         NumberOfDaysIntoData = JulDate - FromJulianDate;
         StartMinuteOfData = NumberOfDaysIntoData * 1440;
         if (Debug)
            fprintf (stdout,
               "NumberOfDaysIntoData: %d StartMinuteOfData: %d\n",
               NumberOfDaysIntoData, StartMinuteOfData);
      }
      NumberOfMinutesIntoData = StartMinuteOfData +
                                ((SpiRecord.Hour * 60) + SpiRecord.Minute) -
                                StartMinuteOnFirstDay;

      DataRecordsProcessedCount++;

      /* by pointer, call the function to process this SPI data record */
      (*ProcessDataFunction) (&SpiRecord);
   }

   sys$close (&DataFileFab, 0, 0);

   if (status == RMS$_EOF) status = SS$_NORMAL;
   if (VMSnok (status))
   {
      CgiLibResponseError (FI_LI, status, DataNode);
      exit (SS$_NORMAL);
   }
}

/*****************************************************************************/
/*
The specified parameter is the name of the file, excluding directory and file 
type, just the name.  Construct a full HTML file name and open it, read each 
record just passing the contents into the HTTP output stream, the close the 
file.  If the file cannot be found the status RMS$_FNF is returned, all other 
errors are reported and the image exits.
*/ 

IncludeFile (char *Name)

{
   int  status;
   char  FileName [256],
         Line [256],
         Scratch [256];
   struct FAB  FileFab;
   struct RAB  FileRab;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "IncludeFile() |%s|\n", Name);

   sprintf (FileName, "%s%s.HTML", HyperSpiDirectoryPtr, Name);
   if (Debug) fprintf (stdout, "FileName |%s|\n", FileName);

   FileFab = cc$rms_fab;
   FileFab.fab$b_fac = FAB$M_GET;
   FileFab.fab$l_fna = FileName;  
   FileFab.fab$b_fns = strlen(FileName);  
   FileFab.fab$b_shr = FAB$M_SHRGET;

   if (VMSnok (status = sys$open (&FileFab, 0, 0)))
   {
      if (Debug) fprintf (stdout, "sys$open() %%X%08.08X\n", status);
      if (status == RMS$_FNF || status == RMS$_DNF) return (status);
      CgiLibResponseError (FI_LI, status, Name);
      exit (SS$_NORMAL);
   }

   FileRab = cc$rms_rab;
   FileRab.rab$l_fab = &FileFab;
   /* 2 buffers and read ahead performance option */
   FileRab.rab$b_mbf = 2;
   FileRab.rab$l_rop = RAB$M_RAH;
   FileRab.rab$l_ubf = Line;
   FileRab.rab$w_usz = sizeof(Line)-1;

   if (VMSnok (status = sys$connect (&FileRab, 0, 0)))
   {
      if (Debug) fprintf (stdout, "sys$connect() %%X%08.08X\n", status);
      sys$close (&FileFab, 0, 0);
      CgiLibResponseError (FI_LI, status, Name);
      exit (SS$_NORMAL);
   }

   while (VMSok (status = sys$get (&FileRab, 0, 0)))
   {
      Line[FileRab.rab$w_rsz++] = '\r';
      Line[FileRab.rab$w_rsz++] = '\n';
      Line[FileRab.rab$w_rsz] = '\0';
      if (Debug) fprintf (stdout, "Line |%s|\n", Line);
      fputs (Line, stdout);
   }

   sys$close (&FileFab, 0, 0);

   if (status == RMS$_EOF) return (status);

   CgiLibResponseError (FI_LI, status, Name);
   exit (SS$_NORMAL);
}

/*****************************************************************************/
/*
Return a pointer to a unique number built up of time components.  Used to 
place a unique component into the URL of a graph GIF, ensuring a cached 
version is not retrieved.
*/

char* UniqueNumber ()

{
   static char  String [16];

   unsigned long  BinTime [2];
   unsigned short  NumTime [7];

   sys$gettim (&BinTime);
   sys$numtim (&NumTime, &BinTime);

   sprintf (String, "%d%d%d%d%d%d%d",
            NumTime[0] % 10, NumTime[1], NumTime[2], NumTime[3],
            NumTime[4], NumTime[5], NumTime[6]);
   return (String);
}

/*****************************************************************************/
/*
Translate the logical name HYPERSPI_AGENT_PID containing the agent process ID
(binary) and issue a $FORCEX against the image.
*/

int ShutdownAgent ()

{
   static $DESCRIPTOR (LnmSystemDsc, "LNM$SYSTEM");
   static $DESCRIPTOR (PidLogNameDsc, "HYPERSPI_AGENT_PID");

   static unsigned long  Pid;
   static struct
   {
      unsigned short  buf_len;
      unsigned short  item;
      void   *buf_addr;
      unsigned short  *short_ret_len;
   }
   LnmPidItem [] =
   {
      { sizeof(Pid), LNM$_STRING, &Pid, 0 },
      { 0,0,0,0 }
   };

   int  status;

   /*********/
   /* begin */
   /*********/

   status = sys$trnlnm (0, &LnmSystemDsc, &PidLogNameDsc, 0, &LnmPidItem);
   if (VMSok (status)) status = sys$forcex (&Pid, 0, SS$_NORMAL);
   return (status);
}

/****************************************************************************/
/*
*/

char* SystemNodeName ()

{
   static char  SyiNodeName [15+1];
   static unsigned short  SyiNodeNameLength;
   static struct {
      short BufferLength;
      short ItemCode;
      void  *BufferPtr;
      void  *LengthPtr;
   }
   SyiItems [] =
   {
      { 15, SYI$_NODENAME, &SyiNodeName, &SyiNodeNameLength },
      { 0,0,0,0 }
   };
   struct {
      unsigned long  Status;
      unsigned long  Reserved;
   } IOsb;

   int  status;

   /*********/
   /* begin */
   /*********/

   status = sys$getsyiw (0, 0, 0, &SyiItems, &IOsb, 0, 0);

   if (Debug)
      fprintf (stdout, "sys$getsyiw() %%X%08.08X IOsb: %%X%08.08X\n",
               status, IOsb.Status);

   if (VMSok (IOsb.Status))
      SyiNodeName[SyiNodeNameLength] = '\0';
   else
      sprintf(SyiNodeName, "%%X%08.08X", IOsb.Status);

   if (Debug) fprintf (stdout, "SyiNodeName |%s|\n", SyiNodeName);

   return (SyiNodeName);
}

/****************************************************************************/
/*
Does a case-insensitive, character-by-character string compare and returns 
true if two strings are the same, or false if not.  If a maximum number of 
characters are specified only those will be compared, if the entire strings 
should be compared then specify the number of characters as 0.
*/ 

boolean strsame
(
char *sptr1,
char *sptr2,
int  count
)
{
   while (*sptr1 && *sptr2)
   {
      if (toupper (*sptr1++) != toupper (*sptr2++)) return (false);
      if (count)
         if (!--count) return (true);
   }
   if (*sptr1 || *sptr2)
      return (false);
   else
      return (true);
}

/*****************************************************************************/