with Implementation_Dependencies;
use Implementation_Dependencies;
with Type_Definitions;
use Type_Definitions;
with String_Pkg;
use String_Pkg;

------------------------
package Run_Time_Monitor is
    ------------------------


    --| Overview
    --|     This is the Run Time Monitor package for the Ada Test and
    --| Analysis Tool Set (ATETS). Its purpose is to dynamically record
    --| information about the execution of programs written in the
    --| Ada language. The Run Time Monitor is common to the following
    --| ATETS tools:
    --|
    --|   1) Path     - Path Analyzer
    --|   2) AutoPath - Automatic Path Analyzer
    --|   3) SMART    - Self Metric Analysis and Reporting Tool
    --|   4) Profile  - Performance Analyzer
    --|
    --|     The Run Time Monitor is implemented as a package that is
    --| WITHed and USEd by the Ada program being tested.  All WITHs,
    --| USEs, and calls to the Run Time Monitor procedures are inserted
    --| into the target Ada program by the ATETS Source Instrumenter.
    --| The execution data about each Ada program unit that has been
    --| instrumented is recorded at runtime in an Execution Log File (ELF).
    --|
    --|     The user must select the recording options to be used at
    --| run time by specifying one of the above tools as a runtime
    --| parameter. Additionally, the user may specify the name of the
    --| log file to be generated during execution of the target Ada
    --| program. If no log file name is specified by the user then the
    --| default log file name will be <toolname>".LOG".  The Run Time
    --| Monitor checks for the existance of the logfile and if it exists
    --| the user must choose to write over it, append to it or select
    --| a new filename.
    --|
    --| Requires
    --| The Ada program to be tested must have been instrumented by
    --| the Ada Source Instrumenter to insert "hooks", or calls, to the
    --| the Runtime Monitor.  Information about each program unit in an
    --| instrumented compilation unit must be recorded in the ELF via
    --| a call to the procedure Unit_Information prior to execution of
    --| the program unit. An Ada program unit is a procedure, function,
    --| package, task, or generic.

    --| N/A:  Errors, Raises, Modifies

    --  Version         : 5.0
    --  Author          : Mary Koppes  Intermetrcs, Inc.
    --  Initial Release : 03/23/85
    --  Last Modified   : 07/16/85


    task Rtm is

        --| Overview
        --| The Run Time Monitor has been implemented as a task in order
        --| to synchronize calls from the instrumented program and prevent
        --| interleaving of output to th log file.


        ----------------------
        entry Unit_Information
                 ( --| Defines a compilation unit to the RTM

                  Compilation_Unit : in Ada_Name;
                  --| The name of the compilation unit

                  Breakpoint_Number : in Breakpoint_Number_Range;
                  --| Total number of break points in the compilation unit
                  --| assigned by the Source Instrumenter

                  List_Of_Procedures : in Procedure_List
                  --| A list of the names of all of the program units in
                  --| the compilation unit

                  );

        --| Effects
        --| Unit_Information is the procedure used to define information about
        --| each program unit in a compilation unit.  If the program unit is
        --| the first program unit to be defined by a call to Unit_Information
        --| the user is asked to enter the Tool_Name, Logfile Name and a
        --| unique test identification string, if desired.  The logfile is
        --| opened.  The rest of the information is not recorded to the logfile
        --| at this time.  A unique identifier is created by the Source
        --| Instrumenter for each program unit which provides a mechanism for
        --| handling overloading of unit names. This procedure defines the
        --| correlation between program unit names and program unit ID's
        --| assigned by the Source Instrumenter. The information is recorded
        --| in the execution log file for later use by the report generators.

        --| Requires
        --| Each program unit must be previously defined to the Runtime Monitor
        --| by a call to this procedure prior to being "entered" or "exited."

        --| Raises
        --| User_Input_Error

        --| N/A:  Errors, Modifies


        -------------------
        entry Entering_Unit
                 ( --| Logs program unit and start time to ELF

                  Enclosing_Unit : in String_Type;
                  --| The name of the compilation unit

                  Unit_Number : in Program_Unit_Number_Range;
                  --| The Program Unit Number

                  Unit_Type : in Program_Unit_Type;
                  --| The type of unit ( procedure, function task generic or package )

                  Task_Number : in out Task_Type_Activation_Number_Range
                  --| A unique number assigned by the Runtime Monitor

                  );

        --| Effects
        --| Entering_Unit first creates a Unit_Identifier from the
        --| four procedure parameters.  If the program unit is
        --| the first program unit to be entered outside of Package
        --| initialization and its UNIT_TYPE is PROCEDURE_TYPE, then
        --| it is assumed to be the main program unit.
        --| When the main procedure is entered, the Tool_Name, Test ID and
        --| the Main procedure name are written to the logfile.
        --| For each program unit entered, the Logfile_Key "Unit_START"
        --| and the unit ID assigned by the Source Instrumenter (Unit_Identifier)
        --| are recorded in the log file by calling the Start_Unit procedure
        --| which is part of the Write_Log package.
        --| If the unit being entered is a task then if the Task_List has not
        --| been created it is and the ID is added to the list.  The purpose of
        --| this list is to maintain the Task_Type_Activation_Number. This
        --| number is initially 1 and each time a task of the same type is
        --| added to the Task_List, the activation number is incremented.
        --| The Task_Type_Activation_Number is written to the logfile and is
        --| used by the ATETS report generators to determine which copy of a
        --| task is executing.  The IN OUT parameter, Task_Number is also
        --| updated to pass back to the calling program.

        --| Requires
        --| A program unit must be previously defined to the Runtime Monitor
        --| via a call to the procedure Unit_Information prior to being "entered."

        --| N/A:  Raises, Errors, Modifies


        ------------------
        entry Exiting_Unit ( --| Logs program unit and stop time to ELF

                            Unit_Identifier : in Program_Unit_Unique_Identifier
                            --| A unique ID assigned by the Source Instrumenter

                            );

        --| Effects
        --| Exiting_Unit records to the logfile the Logfile_Key "UNIT_STOP"
        --| and the Unit_Identifier assigned by the Source Instrumenter.
        --| If Package Initialization is not in progress, then the
        --| Unit_Identifier is deleted from the Entered_Unit_List.
        --| The main program unit is "held" from exiting until all
        --| other program units have terminated. If the unit being is
        --| the main program unit then the logfile is closed and if
        --| the user has chosen to append to an existing logfile
        --| it is done at this time.

        --| Requires
        --| The program unit must be previously defined to the RTM via a call
        --| to the procedure Unit_Information.
        --| The program unit must have been previously "entered" via a call to
        --| the procedure Entering_Unit prior to being "exited."

        --| Raises
        --| Unit_Exit_Error

        --| N/A:  Errors, Modifies


        -------------------
        entry Breakpoint_At
                 ( --| Process program breakpoint

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter

                  Breakpoint_Type : in Breakpoint_Types;
                  --| The type of breakpoint

                  Current_Breakpoint : in Breakpoint_Number_Range
                  --| Breakpoint number assigned by Source Instrumenter

                  );

        --| Effects
        --| case TOOL_NAME
        --|   when PATH_TOOL | AUTOPATH_TOOL | SMART_TOOL =>
        --|        log program unit ID (Unit_ID)
        --|        log type of breakpoint (Breakpoint_Type)
        --|        log the current breakpoint number (Current_Breakpoint)
        --|   when PROFILE_TOOL => null;  -- no action for PROFILE
        --|   when others  => null;
        --| end case;

        --| Requires
        --| The program unit must be previously defined to the RTM via a call
        --| to the procedure Unit_Information.
        --| The program unit must have been previously "entered" via a call to
        --| the procedure Entering_Unit.

        --| N/A:  Raises, Errors, Modifies


        -------------------------
        entry Put_Call_Parameters (--| Log AutoPath input parameter list to ELF

                                   Call_Parameters : in Input_Parameter_List
                                   --| The user specified input parameter list

                                   );

        --| Effects
        --| Logs the calling parameter list for a single execution of the
        --| unit under test by the AutoPath shell.

        --| N/A:  Raises, Requires, Modifies, Errors


        ---------------
        entry Put_Value
                 (--| Logs value of integer variable to the ELF

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter for the current unit

                  Variable_Name : in String;      --| The name of the variable

                  Integer_Value : in Integer  --| The variable's value

                  );

        --| Effects
        --| Logs integer values to the execution log file.
        --| Puts the program unit, variable name, and current value.

        --| N/A:  Raises, Requires, Modifies, Errors


        ---------------
        entry Put_Value
                 (--| Logs value of Long_Integer variable to the ELF

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter for the current unit

                  Variable_Name : in
                     String;          --| The name of the variable

                  Long_Integer_Value : in Long_Integer --| The variable's value

                  );

        --| Effects
        --| Logs long_integer values to the execution log file.
        --| Puts the program unit, variable name, and current value.

        --| N/A:  Raises, Requires, Modifies, Errors


        ---------------
        entry Put_Value
                 (--| Logs value of FLOAT variable to the ELF

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter for the current unit

                  Variable_Name : in String;     --| The name of the variable

                  Float_Value : in Float   --| The variable's value

                  );

        --| Effects
        --| Logs floating point values to the execution log file
        --| Puts the program unit, variable name, and current value

        --| N/A:  Raises, Requires, Modifies, Errors


        ---------------
        -- Rational Environment note: Long_Float not implemented; following removed -jwb
        --        entry Put_Value (--| Logs value of Long_Float variable to the ELF

        --                         Unit_Identifier : in Program_Unit_Unique_Identifier;
        --| A unique ID assigned by the Source Instrumenter for the current unit

        --                         Variable_Name : in String;      --| The name of the variable

        --                         Long_Float_Value : in Long_Float  --| The variable's value

        --                         );

        --| Effects
        --| Logs long_float values to the execution log file.
        --| Puts the program unit, variable name, and current value.

        --| N/A:  Raises, Requires, Modifies, Errors


        ---------------
        entry Put_Value
                 (--| Logs value of string variable to the ELF

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter for the current unit

                  Variable_Name : in String;     --| The name of the variable

                  String_Value : in String  --| The variable's value

                  );

        --| Effects
        --| Logs string values to the execution log file
        --| Puts the program unit, variable name, and current value
        --| This procedure used to log the value of
        --|        strings
        --|        characters
        --|        enumerated data types (including booleans)

        --| N/A:  Raises, Requires, Modifies, Errors


        -----------------
        entry Start_Delay
                 (--| Records a delay for the specified unit and
                  --| duration in the ELF

                  Unit_Identifier : in Program_Unit_Unique_Identifier;
                  --| A unique ID assigned by the Source Instrumenter for the current unit

                  Seconds : in Duration
                  --| The length of the delay in seconds

                  );

        --| Effects
        --| Records a delay for the specified unit and duration in the
        --| Execution Log File. This entry is not called directly by the
        --| the instrumented program. It is called by the function
        --| Starting_Delay.

        --| N/A:  Raises, Requires, Modifies, Errors


    end Rtm;


    -----------------------
    function Starting_Delay
                (--| Records a delay for the specified unit and
                 --| duration in the ELF

                 Unit_Identifier : in Program_Unit_Unique_Identifier;
                 --| A unique ID assigned by the Source Instrumenter for the current unit

                 Seconds : in Duration

                 )
                return Duration;

    --| Effects
    --| Records a delay for the specified unit and duration in the
    --| Execution Log File. The length of the Delay is returned to
    --| the calling unit. This unit is implemented as a function
    --| to enable trapping of delay times in timed entry statements.

    --| N/A:  Raises, Requires, Modifies, Errors


end Run_Time_Monitor;
