Commit 91c2cbdb by Arnaud Charlet

[multiple changes]

2009-04-29  Arnaud Charlet  <charlet@adacore.com>

	* s-taskin.adb (Initialize): Remove pragma Warnings Off and remove
	unused assignment.

2009-04-29  Thomas Quinot  <quinot@adacore.com>

	* make.adb: Minor reformatting.
	Minor code reorganization throughout.

2009-04-29  Matteo Bordin  <bordin@adacore.com>

	* s-stausa.ads: Changed visibility of type Task_Result: moved to
	public part to give application visibility over it.
	This is for future improvement and to build a public API on top of it.
	Changed record components name of type Task_Result to reflect the new
	way of reporting. 

	* s-stausa.adb: Actual_Size_Str changed to reflect the new way of
	reporting Stack usage.

	* gnat_ugn.texi: Update doc of stack usage report.

	* g-tastus.ads, s-stusta.ads, s-stusta.adb: New files.

	* Makefile.rtl: Add new run-time files.

From-SVN: r146942
parent 6d47b1e3
2009-04-29 Arnaud Charlet <charlet@adacore.com>
* s-taskin.adb (Initialize): Remove pragma Warnings Off and remove
unused assignment.
2009-04-29 Thomas Quinot <quinot@adacore.com>
* make.adb: Minor reformatting.
Minor code reorganization throughout.
2009-04-29 Matteo Bordin <bordin@adacore.com>
* s-stausa.ads: Changed visibility of type Task_Result: moved to
public part to give application visibility over it.
This is for future improvement and to build a public API on top of it.
Changed record components name of type Task_Result to reflect the new
way of reporting.
* s-stausa.adb: Actual_Size_Str changed to reflect the new way of
reporting Stack usage.
* gnat_ugn.texi: Update doc of stack usage report.
* g-tastus.ads, s-stusta.ads, s-stusta.adb: New files.
* Makefile.rtl: Add new run-time files.
2009-04-29 Pascal Obry <obry@adacore.com>
* initialize.c: Do not expand quoted arguments.
......
......@@ -41,6 +41,7 @@ GNATRTL_TASKING_OBJS= \
g-boumai$(objext) \
g-semaph$(objext) \
g-signal$(objext) \
g-tastus$(objext) \
g-thread$(objext) \
s-asthan$(objext) \
s-inmaop$(objext) \
......@@ -50,6 +51,7 @@ GNATRTL_TASKING_OBJS= \
s-osinte$(objext) \
s-proinf$(objext) \
s-solita$(objext) \
s-stusta$(objext) \
s-taenca$(objext) \
s-taprob$(objext) \
s-taprop$(objext) \
......
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . T A S K _ S T A C K _ U S A G E --
-- --
-- S p e c --
-- --
-- Copyright (C) 2009, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
------------------------------------------------------------------------------
-- This package provides an API to query for tasks stack usage at runtime
-- and during debug.
-- See file s-stusta.ads for full documentation of the interface
with System.Stack_Usage.Tasking;
package GNAT.Task_Stack_Usage renames System.Stack_Usage.Tasking;
......@@ -20270,7 +20270,7 @@ output this info at program termination. Results are displayed in four
columns:
@noindent
Index | Task Name | Stack Size | Actual Use [min - max]
Index | Task Name | Stack Size | Stack Usage [Value +/- Variation]
@noindent
where:
......@@ -20285,11 +20285,11 @@ is the name of the task analyzed.
@item Stack Size
is the maximum size for the stack.
@item Actual Use
is the measure done by the stack analyzer. In order to prevent overflow,
the stack is not entirely analyzed, and it's not possible to know exactly how
much has actually been used. The real amount of stack used is between the min
and max values.
@item Stack Usage
is the measure done by the stack analyzer. In order to prevent overflow, the stack
is not entirely analyzed, and it's not possible to know exactly how
much has actually been used. The report thus contains the theoretical stack usage
(Value) and the possible variation (Variation) around this value.
@end table
......@@ -173,7 +173,7 @@ package body System.Stack_Usage is
Index_Str : constant String := "Index";
Task_Name_Str : constant String := "Task Name";
Stack_Size_Str : constant String := "Stack Size";
Actual_Size_Str : constant String := "Stack usage [min - max]";
Actual_Size_Str : constant String := "Stack usage [Value +/- Variation]";
function Get_Usage_Range (Result : Task_Result) return String;
-- Return string representing the range of possible result of stack usage
......@@ -204,8 +204,8 @@ package body System.Stack_Usage is
Result_Array.all :=
(others =>
(Task_Name => (others => ASCII.NUL),
Min_Measure => 0,
Max_Measure => 0,
Variation => 0,
Value => 0,
Max_Size => 0));
-- Set the Is_Enabled flag to true, so that the task wrapper knows that
......@@ -222,16 +222,16 @@ package body System.Stack_Usage is
if Stack_Size_Chars /= Null_Address then
declare
Stack_Size : Integer;
My_Stack_Size : Integer;
begin
Stack_Size := System.CRTL.atoi (Stack_Size_Chars) * 1024;
My_Stack_Size := System.CRTL.atoi (Stack_Size_Chars) * 1024;
Initialize_Analyzer
(Environment_Task_Analyzer,
"ENVIRONMENT TASK",
Stack_Size,
Stack_Size,
My_Stack_Size,
My_Stack_Size,
System.Storage_Elements.To_Integer (Bottom_Of_Stack'Address));
Fill_Stack (Environment_Task_Analyzer);
......@@ -318,7 +318,7 @@ package body System.Stack_Usage is
procedure Initialize_Analyzer
(Analyzer : in out Stack_Analyzer;
Task_Name : String;
Stack_Size : Natural;
My_Stack_Size : Natural;
Max_Pattern_Size : Natural;
Bottom : Stack_Address;
Pattern : Unsigned_32 := 16#DEAD_BEEF#)
......@@ -327,7 +327,7 @@ package body System.Stack_Usage is
-- Initialize the analyzer fields
Analyzer.Bottom_Of_Stack := Bottom;
Analyzer.Stack_Size := Stack_Size;
Analyzer.Stack_Size := My_Stack_Size;
Analyzer.Pattern_Size := Max_Pattern_Size;
Analyzer.Pattern := Pattern;
Analyzer.Result_Id := Next_Id;
......@@ -414,11 +414,11 @@ package body System.Stack_Usage is
---------------------
function Get_Usage_Range (Result : Task_Result) return String is
Min_Used_Str : constant String := Natural'Image (Result.Min_Measure);
Max_Used_Str : constant String := Natural'Image (Result.Max_Measure);
Variation_Used_Str : constant String :=
Natural'Image (Result.Variation);
Value_Used_Str : constant String := Natural'Image (Result.Value);
begin
return "[" & Min_Used_Str (2 .. Min_Used_Str'Last) & " -"
& Max_Used_Str & "]";
return "[" & Value_Used_Str & " +/- " & Variation_Used_Str & "]";
end Get_Usage_Range;
---------------------
......@@ -431,16 +431,16 @@ package body System.Stack_Usage is
Max_Stack_Size_Len : Natural;
Max_Actual_Use_Len : Natural)
is
Result_Id_Str : constant String := Natural'Image (Result_Id);
Stack_Size_Str : constant String := Natural'Image (Result.Max_Size);
Actual_Use_Str : constant String := Get_Usage_Range (Result);
Result_Id_Str : constant String := Natural'Image (Result_Id);
My_Stack_Size_Str : constant String := Natural'Image (Result.Max_Size);
Actual_Use_Str : constant String := Get_Usage_Range (Result);
Result_Id_Blanks : constant
String (1 .. Index_Str'Length - Result_Id_Str'Length) :=
(others => ' ');
Stack_Size_Blanks : constant
String (1 .. Max_Stack_Size_Len - Stack_Size_Str'Length) :=
String (1 .. Max_Stack_Size_Len - My_Stack_Size_Str'Length) :=
(others => ' ');
Actual_Use_Blanks : constant
......@@ -453,7 +453,7 @@ package body System.Stack_Usage is
Put (" | ");
Put (Result.Task_Name);
Put (" | ");
Put (Stack_Size_Blanks & Stack_Size_Str);
Put (Stack_Size_Blanks & My_Stack_Size_Str);
Put (" | ");
Put (Actual_Use_Blanks & Actual_Use_Str);
New_Line;
......@@ -488,8 +488,8 @@ package body System.Stack_Usage is
for J in Result_Array'Range loop
exit when J >= Next_Id;
if Result_Array (J).Max_Measure
> Result_Array (Max_Actual_Use_Result_Id).Max_Measure
if Result_Array (J).Value
> Result_Array (Max_Actual_Use_Result_Id).Value
then
Max_Actual_Use_Result_Id := J;
end if;
......@@ -559,12 +559,13 @@ package body System.Stack_Usage is
Result : Task_Result :=
(Task_Name => Analyzer.Task_Name,
Max_Size => Analyzer.Stack_Size,
Min_Measure => 0,
Max_Measure => 0);
Variation => 0,
Value => 0);
Overflow_Guard : constant Integer :=
Analyzer.Stack_Size
- Stack_Size (Analyzer.Top_Pattern_Mark, Analyzer.Bottom_Of_Stack);
Max, Min : Positive;
begin
if Analyzer.Pattern_Size = 0 then
......@@ -572,15 +573,17 @@ package body System.Stack_Usage is
-- at all. In other words, we used at least everything (and possibly
-- more).
Result.Min_Measure := Analyzer.Stack_Size - Overflow_Guard;
Result.Max_Measure := Analyzer.Stack_Size;
Min := Analyzer.Stack_Size - Overflow_Guard;
Max := Analyzer.Stack_Size;
else
Result.Min_Measure := Stack_Size
(Analyzer.Topmost_Touched_Mark,
Analyzer.Bottom_Of_Stack);
Result.Max_Measure := Result.Min_Measure + Overflow_Guard;
Min := Stack_Size
(Analyzer.Topmost_Touched_Mark, Analyzer.Bottom_Of_Stack);
Max := Min + Overflow_Guard;
end if;
Result.Value := (Max + Min) / 2;
Result.Variation := (Max - Min) / 2;
if Analyzer.Result_Id in Result_Array'Range then
-- If the result can be stored, then store it in Result_Array
......
......@@ -46,6 +46,27 @@ package System.Stack_Usage is
(Value : System.Address) return Stack_Address
renames System.Storage_Elements.To_Integer;
Task_Name_Length : constant := 32;
-- The maximum length of task name displayed.
-- ??? Consider merging this variable with Max_Task_Image_Length.
type Task_Result is record
Task_Name : String (1 .. Task_Name_Length);
Value : Natural;
-- Amount of the stack used; the value is calculated on the basis of
-- the mechanism used by GNAT to allocate it, and it is NOT a precise
-- value.
Variation : Natural;
-- Possible variation in the amount of used stack. The real stack usage
-- may vary in the range Value +/- Variation
Max_Size : Natural;
end record;
type Result_Array_Type is array (Positive range <>) of Task_Result;
type Stack_Analyzer is private;
-- Type of the stack analyzer tool. It is used to fill a portion of the
-- stack with Pattern, and to compute the stack used after some execution.
......@@ -206,7 +227,7 @@ package System.Stack_Usage is
procedure Initialize_Analyzer
(Analyzer : in out Stack_Analyzer;
Task_Name : String;
Stack_Size : Natural;
My_Stack_Size : Natural;
Max_Pattern_Size : Natural;
Bottom : Stack_Address;
Pattern : Interfaces.Unsigned_32 := 16#DEAD_BEEF#);
......@@ -256,10 +277,6 @@ package System.Stack_Usage is
private
Task_Name_Length : constant := 32;
-- The maximum length of task name displayed.
-- ??? Consider merging this variable with Max_Task_Image_Length.
package Unsigned_32_Addr is
new System.Address_To_Access_Conversions (Interfaces.Unsigned_32);
......@@ -308,20 +325,6 @@ private
Compute_Environment_Task : Boolean;
type Task_Result is record
Task_Name : String (1 .. Task_Name_Length);
Min_Measure : Natural;
-- Minimum value for the measure
Max_Measure : Natural;
-- Maximum value for the measure, taking into account the actual size
-- of the pattern filled.
Max_Size : Natural;
end record;
type Result_Array_Type is array (Positive range <>) of Task_Result;
type Result_Array_Ptr is access all Result_Array_Type;
Result_Array : Result_Array_Ptr;
......
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . S T A C K _ U S A G E . T AS K I N G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2009, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNARL; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
with System.Stack_Usage;
-- This is why this package is part of GNARL:
with System.Tasking.Debug;
with System.Task_Primitives.Operations;
with System.IO;
package body System.Stack_Usage.Tasking is
use System.IO;
procedure Report_For_Task (Id : System.Tasking.Task_Id);
-- A generic procedure calculating stack usage for a given task
procedure Compute_All_Tasks;
-- Compute the stack usage for all tasks and saves it in
-- System.Stack_Usage.Result_Array
procedure Compute_Current_Task;
-- Compute the stack usage for a given task and saves it in the a precise
-- slot in System.Stack_Usage.Result_Array;
procedure Report_Impl (All_Tasks : Boolean; Do_Print : Boolean);
-- Report the stack usage of either all tasks (All_Tasks = True) or of the
-- current task (All_Task = False). If Print is True, then results are
-- printed on stderr
procedure Convert
(TS : System.Stack_Usage.Task_Result;
Res : out Stack_Usage_Result);
-- Convert an object of type System.Stack_Usage in a Stack_Usage_Result
--------------
-- Convert --
--------------
procedure Convert
(TS : System.Stack_Usage.Task_Result;
Res : out Stack_Usage_Result) is
begin
Res := TS;
end Convert;
----------------------
-- Report_For_Task --
----------------------
procedure Report_For_Task (Id : System.Tasking.Task_Id) is
begin
System.Stack_Usage.Compute_Result (Id.Common.Analyzer);
System.Stack_Usage.Report_Result (Id.Common.Analyzer);
end Report_For_Task;
------------------------
-- Compute_All_Tasks --
------------------------
procedure Compute_All_Tasks is
Id : System.Tasking.Task_Id;
use type System.Tasking.Task_Id;
begin
if not System.Stack_Usage.Is_Enabled then
Put ("Stack Usage not enabled: bind with -uNNN switch");
else
-- Loop over all tasks
for J in System.Tasking.Debug.Known_Tasks'First + 1
.. System.Tasking.Debug.Known_Tasks'Last
loop
Id := System.Tasking.Debug.Known_Tasks (J);
exit when Id = null;
-- Calculate the task usage for a given task
Report_For_Task (Id);
end loop;
end if;
end Compute_All_Tasks;
---------------------------
-- Compute_Current_Task --
---------------------------
procedure Compute_Current_Task is
begin
if not System.Stack_Usage.Is_Enabled then
Put ("Stack Usage not enabled: bind with -uNNN switch");
else
-- The current task
Report_For_Task (System.Tasking.Self);
end if;
end Compute_Current_Task;
------------------
-- Report_Impl --
------------------
procedure Report_Impl (All_Tasks : Boolean; Do_Print : Boolean) is
begin
-- Lock the runtime
System.Task_Primitives.Operations.Lock_RTS;
-- Calculate results
if All_Tasks then
Compute_All_Tasks;
else
Compute_Current_Task;
end if;
-- Output results
if Do_Print then
System.Stack_Usage.Output_Results;
end if;
-- Unlock the runtime
System.Task_Primitives.Operations.Unlock_RTS;
end Report_Impl;
----------------------
-- Report_All_Task --
----------------------
procedure Report_All_Tasks is
begin
Report_Impl (True, True);
end Report_All_Tasks;
--------------------------
-- Report_Current_Task --
--------------------------
procedure Report_Current_Task is
Res : Stack_Usage_Result;
begin
Res := Get_Current_Task_Usage;
Print (Res);
end Report_Current_Task;
--------------------------
-- Get_All_Tasks_Usage --
--------------------------
function Get_All_Tasks_Usage return Stack_Usage_Result_Array is
Res : Stack_Usage_Result_Array
(1 .. System.Stack_Usage.Result_Array'Length);
begin
Report_Impl (True, False);
for J in Res'Range loop
Convert (System.Stack_Usage.Result_Array (J), Res (J));
end loop;
return Res;
end Get_All_Tasks_Usage;
-----------------------------
-- Get_Current_Task_Usage --
-----------------------------
function Get_Current_Task_Usage return Stack_Usage_Result is
Res : Stack_Usage_Result;
Original : System.Stack_Usage.Task_Result;
Found : Boolean := False;
begin
Report_Impl (False, False);
-- Look for the task info in System.Stack_Usage.Result_Array;
-- the search is based on task name
for T in System.Stack_Usage.Result_Array'Range loop
if System.Stack_Usage.Result_Array (T).Task_Name =
System.Tasking.Self.Common.Analyzer.Task_Name
then
Original := System.Stack_Usage.Result_Array (T);
Found := True;
exit;
end if;
end loop;
-- Be sure a task has been found
pragma Assert (Found);
Convert (Original, Res);
return Res;
end Get_Current_Task_Usage;
------------
-- Print --
------------
procedure Print (Obj : Stack_Usage_Result) is
Pos : Positive;
begin
-- Simply trim the string containing the task name
for S in Obj.Task_Name'Range loop
if Obj.Task_Name (S) = ' ' then
Pos := S;
exit;
end if;
end loop;
declare
T_Name : constant String := Obj.Task_Name
(Obj.Task_Name'First .. Pos);
begin
Put_Line
("| " & T_Name & " | " & Natural'Image (Obj.Max_Size) & " [" &
Natural'Image (Obj.Value) & " +/- " &
Natural'Image (Obj.Variation) & "]");
end;
end Print;
end System.Stack_Usage.Tasking;
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . S T A C K _ U S A G E . T AS K I N G --
-- --
-- S p e c --
-- --
-- Copyright (C) 2009, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNARL; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides exported subprograms to be called at debug time to
-- measure stack usage at run-time.
-- Note: this package must be a child package of System.Stack_Usage to have
-- visibility over its private part; it is however part of GNARL because it
-- needs to access tasking features via System.Tasking.Debug and
-- System.Task_Primitives.Operations;
package System.Stack_Usage.Tasking is
procedure Report_All_Tasks;
-- Print the current stack usage of all tasks on stderr. Exported to be
-- called also in debug mode.
pragma Export
(C,
Report_All_Tasks,
"__gnat_tasks_stack_usage_report_all_tasks");
procedure Report_Current_Task;
-- Print the stack usage of current task on stderr. Exported to be called
-- also in debug mode.
pragma Export
(C,
Report_Current_Task,
"__gnat_tasks_stack_usage_report_current_task");
subtype Stack_Usage_Result is System.Stack_Usage.Task_Result;
-- This type is a descriptor for task stack usage result.
type Stack_Usage_Result_Array is
array (Positive range <>) of Stack_Usage_Result;
function Get_Current_Task_Usage return Stack_Usage_Result;
-- Return the current stack usage for the invoking task
function Get_All_Tasks_Usage return Stack_Usage_Result_Array;
-- Return an array containing the stack usage results for all tasks
procedure Print (Obj : Stack_Usage_Result);
-- Print Obj on stderr
end System.Stack_Usage.Tasking;
......@@ -176,9 +176,7 @@ package body System.Tasking is
procedure Initialize is
T : Task_Id;
Base_Priority : Any_Priority;
Success : Boolean;
pragma Warnings (Off, Success);
Success : Boolean;
begin
if Initialized then
......@@ -195,7 +193,6 @@ package body System.Tasking is
Base_Priority := Priority (Main_Priority);
end if;
Success := True;
T := STPO.New_ATCB (0);
Initialize_ATCB
(null, null, Null_Address, Null_Task, null, Base_Priority,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment