Skip to content

Commit

Permalink
Merge pull request #43 from gcorrall/long_float
Browse files Browse the repository at this point in the history
Change Floats to Long_Floats
  • Loading branch information
adelnoureddine authored Feb 17, 2024
2 parents 13031a2 + 7420c22 commit 447bfe2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/cpu_stat_app.ads
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package CPU_STAT_App is
Before_Time : Long_Integer; -- Total time, before monitoring
After_Time : Long_Integer; -- Total time, after monitoring
App_Name : Unbounded_String; -- App name to monitor
Power : Float; -- Power consumption in monitoring cycle for PID
Power : Long_Float; -- Power consumption in monitoring cycle for PID
Monitored_Time : Long_Integer; -- Monitored CPU time in the monitoring cycle
PID_Array : PID_Array_Int; -- Array of all PIDs of the application
end record;
Expand Down
2 changes: 1 addition & 1 deletion src/cpu_stat_pid.ads
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package CPU_STAT_PID is
Before_Time : Long_Integer; -- Total time, before monitoring
After_Time : Long_Integer; -- Total time, after monitoring
PID_Number : Integer; -- PID to monitor
Power : Float; -- Power consumption in monitoring cycle for PID
Power : Long_Float; -- Power consumption in monitoring cycle for PID
Monitored_Time : Long_Integer; -- Monitored CPU time in the monitoring cycle
end record;

Expand Down
18 changes: 9 additions & 9 deletions src/csv_power.adb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

package body CSV_Power is

procedure Save_To_CSV_File (Filename : String; Utilization : Float; Total_Power : Float; CPU_Power : Float; GPU_Power : Float; Overwrite_Data : Boolean) is
procedure Save_To_CSV_File (Filename : String; Utilization : Long_Float; Total_Power : Long_Float; CPU_Power : Long_Float; GPU_Power : Long_Float; Overwrite_Data : Boolean) is
F : File_Type; -- File handle
Now : Time := Clock; -- Current UTC time

Expand Down Expand Up @@ -57,7 +57,7 @@ package body CSV_Power is
raise PROGRAM_ERROR with "Error in accessing or creating the CSV file";
end;

procedure Save_PID_To_CSV_File (Filename : String; Utilization : Float; Power : Float; Overwrite_Data : Boolean) is
procedure Save_PID_To_CSV_File (Filename : String; Utilization : Long_Float; Power : Long_Float; Overwrite_Data : Boolean) is
F : File_Type; -- File handle
Now : Time := Clock; -- Current UTC time

Expand Down Expand Up @@ -91,9 +91,9 @@ package body CSV_Power is
raise PROGRAM_ERROR with "Error in accessing or creating the CSV file";
end;

procedure Show_On_Terminal (Utilization : Float; Power : Float; Previous_Power : Float; CPU_Power : Float; GPU_Power : Float; GPU_Supported : Boolean) is
Utilization_Percentage : Float;
Power_Difference : Float;
procedure Show_On_Terminal (Utilization : Long_Float; Power : Long_Float; Previous_Power : Long_Float; CPU_Power : Long_Float; GPU_Power : Long_Float; GPU_Supported : Boolean) is
Utilization_Percentage : Long_Float;
Power_Difference : Long_Float;
begin
Utilization_Percentage := Utilization * 100.0;
Put (CR);
Expand Down Expand Up @@ -124,9 +124,9 @@ package body CSV_Power is
end if;
end;

procedure Show_On_Terminal_PID (PID_Utilization : Float; PID_Power : Float; Utilization : Float; Power : Float; Is_PID : Boolean) is
Utilization_Percentage : Float;
PID_Utilization_Percentage : Float;
procedure Show_On_Terminal_PID (PID_Utilization : Long_Float; PID_Power : Long_Float; Utilization : Long_Float; Power : Long_Float; Is_PID : Boolean) is
Utilization_Percentage : Long_Float;
PID_Utilization_Percentage : Long_Float;
begin
Utilization_Percentage := Utilization * 100.0;
PID_Utilization_Percentage := PID_Utilization * 100.0;
Expand Down
8 changes: 4 additions & 4 deletions src/csv_power.ads
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
package CSV_Power is

-- Save CPU utilization and power conusmption to CSV file
procedure Save_To_CSV_File (Filename : String; Utilization : Float; Total_Power : Float; CPU_Power : Float; GPU_Power : Float; Overwrite_Data : Boolean);
procedure Save_To_CSV_File (Filename : String; Utilization : Long_Float; Total_Power : Long_Float; CPU_Power : Long_Float; GPU_Power : Long_Float; Overwrite_Data : Boolean);

-- Save PID's CPU utilization and power conusmption to CSV file
procedure Save_PID_To_CSV_File (Filename : String; Utilization : Float; Power : Float; Overwrite_Data : Boolean);
procedure Save_PID_To_CSV_File (Filename : String; Utilization : Long_Float; Power : Long_Float; Overwrite_Data : Boolean);

-- Print CPU utilization, CPU, GPU and total power conusmption on the terminal
procedure Show_On_Terminal (Utilization : Float; Power : Float; Previous_Power : Float; CPU_Power : Float; GPU_Power : Float; GPU_Supported : Boolean);
procedure Show_On_Terminal (Utilization : Long_Float; Power : Long_Float; Previous_Power : Long_Float; CPU_Power : Long_Float; GPU_Power : Long_Float; GPU_Supported : Boolean);

-- Print CPU utilization and CPU power conusmption on the terminal of monitored PID
procedure Show_On_Terminal_PID (PID_Utilization : Float; PID_Power : Float; Utilization : Float; Power : Float; Is_PID : Boolean);
procedure Show_On_Terminal_PID (PID_Utilization : Long_Float; PID_Power : Long_Float; Utilization : Long_Float; Power : Long_Float; Is_PID : Boolean);

end CSV_Power;
6 changes: 3 additions & 3 deletions src/intel_rapl_sysfs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ package body Intel_RAPL_sysfs is
-- Read energy_uj which is in micro joules
Open (F_Name, In_File, Folder_Name & "intel-rapl:1/energy_uj");
-- Store energy value divided by 1000000 to get it in joules
RAPL_Data.psys := Float'Value (Get_Line (F_Name)) / 1000000.0;
RAPL_Data.psys := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
RAPL_Data.total_energy := RAPL_Data.psys;
elsif RAPL_Data.pkg_supported then
-- Read energy_uj which is in micro joules
Open (F_Name, In_File, Folder_Name & "intel-rapl:0/energy_uj");
-- Store energy value divided by 1000000 to get it in joules
RAPL_Data.pkg := Float'Value (Get_Line (F_Name)) / 1000000.0;
RAPL_Data.pkg := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
RAPL_Data.total_energy := RAPL_Data.pkg;

Expand All @@ -39,7 +39,7 @@ package body Intel_RAPL_sysfs is
-- Read energy_uj which is in micro joules
Open (F_Name, In_File, Folder_Name & "intel-rapl:0/intel-rapl:0:2/energy_uj");
-- Store energy value divided by 1000000 to get it in joules
RAPL_Data.dram := Float'Value (Get_Line (F_Name)) / 1000000.0;
RAPL_Data.dram := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
RAPL_Data.total_energy := RAPL_Data.pkg + RAPL_Data.dram;
end if;
Expand Down
8 changes: 4 additions & 4 deletions src/intel_rapl_sysfs.ads
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ package Intel_RAPL_sysfs is
type Intel_RAPL_Data is
record
-- Data to store energy measures
psys : Float; -- Energy for psys (whole SOC)
pkg : Float; -- Energy for all packages
dram : Float; -- Energy for all dram
psys : Long_Float; -- Energy for psys (whole SOC)
pkg : Long_Float; -- Energy for all packages
dram : Long_Float; -- Energy for all dram

-- Total energy is equal to psys if supoprted, or to pkg + dram
total_energy : Float := 0.0; -- Total energy
total_energy : Long_Float := 0.0; -- Total energy

-- Data to store if packages are supported
psys_supported : Boolean := False; -- if system supports psys
Expand Down
6 changes: 3 additions & 3 deletions src/nvidia_smi.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

package body Nvidia_SMI is

function Get_Nvidia_SMI_Power return Float is
function Get_Nvidia_SMI_Power return Long_Float is
Command : String := "nvidia-smi --format=csv,noheader,nounits --query-gpu=power.draw";
Args : Argument_List_Access;
Status : aliased Integer;
Subs : String_Split.Slice_Set; -- Used to slice the read data from stat file
Seps : constant String := CR & LF; -- Seperator (space) for slicing string
Slice_number_count : String_Split.Slice_Number;
GPU_Energy : Float := 0.0;
GPU_Energy : Long_Float := 0.0;
begin
Args := Argument_String_To_List (Command);
declare
Expand All @@ -47,7 +47,7 @@ package body Nvidia_SMI is
Slice_number_count := String_Split.Slice_Count (Subs);

for I in 1 .. Slice_number_count loop
GPU_Energy := GPU_Energy + Float'Value (String_Split.Slice (Subs, 1));
GPU_Energy := GPU_Energy + Long_Float'Value (String_Split.Slice (Subs, 1));
end loop;

return GPU_Energy;
Expand Down
2 changes: 1 addition & 1 deletion src/nvidia_smi.ads
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package Nvidia_SMI is

-- Function to return the current Nvidia board power consumption using nvidia-smi
function Get_Nvidia_SMI_Power return Float;
function Get_Nvidia_SMI_Power return Long_Float;

-- Function to check if we have a supported Nvidia card and drivers and nvidia-smi tool
function Check_Nvidia_Supported_System return Boolean;
Expand Down
38 changes: 19 additions & 19 deletions src/powerjoular.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
--

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO;
with GNAT.Command_Line; use GNAT.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with GNAT.OS_Lib; use GNAT.OS_Lib;
Expand All @@ -33,26 +33,26 @@ procedure Powerjoular is
-- Power variables
--
-- CPU Power
CPU_Power : Float; -- Entire CPU power consumption
Previous_CPU_Power : Float := 0.0; -- Previous CPU power consumption (t - 1)
PID_CPU_Power : Float; -- CPU power consumption of monitored PID
App_CPU_Power : Float; -- CPU power consumption of monitored application
CPU_Energy : Float := 0.0;
CPU_Power : Long_Float; -- Entire CPU power consumption
Previous_CPU_Power : Long_Float := 0.0; -- Previous CPU power consumption (t - 1)
PID_CPU_Power : Long_Float; -- CPU power consumption of monitored PID
App_CPU_Power : Long_Float; -- CPU power consumption of monitored application
CPU_Energy : Long_Float := 0.0;
--
-- GPU Power
GPU_Power : Float := 0.0;
Previous_GPU_Power : Float := 0.0; -- Previous GPU power consumption (t - 1)
GPU_Energy : Float := 0.0;
GPU_Power : Long_Float := 0.0;
Previous_GPU_Power : Long_Float := 0.0; -- Previous GPU power consumption (t - 1)
GPU_Energy : Long_Float := 0.0;
--
-- Total Power and Energy
Previous_Total_Power : Float := 0.0; -- Previous entire total power consumption (t - 1)
Total_Power : Float := 0.0; -- Total power consumption of all hardware components
Total_Energy : Float := 0.0; -- Total energy consumed since start of PowerJoular until exit
Previous_Total_Power : Long_Float := 0.0; -- Previous entire total power consumption (t - 1)
Total_Power : Long_Float := 0.0; -- Total power consumption of all hardware components
Total_Energy : Long_Float := 0.0; -- Total energy consumed since start of PowerJoular until exit

-- Data types for Intel RAPL energy monitoring
RAPL_Before : Intel_RAPL_Data; -- Intel RAPL data
RAPL_After : Intel_RAPL_Data; -- Intel RAPL data
RAPL_Energy : Float; -- Intel RAPL energy difference for monitoring cycle
RAPL_Energy : Long_Float; -- Intel RAPL energy difference for monitoring cycle

-- Data types for Nvidia energy monitoring
Nvidia_Supported : Boolean; -- If nvidia card, drivers and smi tool are available
Expand All @@ -67,9 +67,9 @@ procedure Powerjoular is
CPU_App_Monitor : CPU_STAT_App_Data; -- Monitored App CPU cycles and power

-- CPU utilization variables
CPU_Utilization : Float; -- Entire CPU utilization
PID_CPU_Utilization : Float; -- CPU utilization of monitored PID
App_CPU_Utilization : Float; -- CPU utilization of monitored application
CPU_Utilization : Long_Float; -- Entire CPU utilization
PID_CPU_Utilization : Long_Float; -- CPU utilization of monitored PID
App_CPU_Utilization : Long_Float; -- CPU utilization of monitored application

-- OS name
OS_Name : String := Get_OS_Name;
Expand Down Expand Up @@ -246,7 +246,7 @@ begin
end if;

-- Calculate entire CPU utilization
CPU_Utilization := (Float (CPU_CCI_After.cbusy) - Float (CPU_CCI_Before.cbusy)) / (Float (CPU_CCI_After.ctotal) - Float (CPU_CCI_Before.ctotal));
CPU_Utilization := (Long_Float (CPU_CCI_After.cbusy) - Long_Float (CPU_CCI_Before.cbusy)) / (Long_Float (CPU_CCI_After.ctotal) - Long_Float (CPU_CCI_Before.ctotal));

if Check_Raspberry_Pi_Supported_System (Platform_Name) then
-- Calculate power consumption for Raspberry
Expand All @@ -271,7 +271,7 @@ begin

-- If a particular PID is monitored, calculate its CPU time, CPU utilization and CPU power
if Monitor_PID then
PID_CPU_Utilization := (Float (CPU_PID_Monitor.Monitored_Time)) / (Float (CPU_CCI_After.ctotal) - Float (CPU_CCI_Before.ctotal));
PID_CPU_Utilization := (Long_Float (CPU_PID_Monitor.Monitored_Time)) / (Long_Float (CPU_CCI_After.ctotal) - Long_Float (CPU_CCI_Before.ctotal));
PID_CPU_Power := (PID_CPU_Utilization * CPU_Power) / CPU_Utilization;

-- Show CPU power data on terminal of monitored PID
Expand All @@ -288,7 +288,7 @@ begin
-- If a particular application is monitored, calculate its CPU time, CPU utilization and CPU power
if Monitor_App then
-- PID_Time := CPU_PID_After.total_time - CPU_PID_Before.total_time;
App_CPU_Utilization := (Float (CPU_App_Monitor.Monitored_Time)) / (Float (CPU_CCI_After.ctotal) - Float (CPU_CCI_Before.ctotal));
App_CPU_Utilization := (Long_Float (CPU_App_Monitor.Monitored_Time)) / (Long_Float (CPU_CCI_After.ctotal) - Long_Float (CPU_CCI_Before.ctotal));
App_CPU_Power := (App_CPU_Utilization * CPU_Power) / CPU_Utilization;

-- Show CPU power data on terminal of monitored PID
Expand Down
2 changes: 1 addition & 1 deletion src/raspberry_pi_cpu_formula.adb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ with Ada.Text_IO; use Ada.Text_IO;

package body Raspberry_Pi_CPU_Formula is

function Calculate_CPU_Power (CPU_Utilization : Float; Platform_Name : String; Algorithm_Name : String) return Float is
function Calculate_CPU_Power (CPU_Utilization : Long_Float; Platform_Name : String; Algorithm_Name : String) return Long_Float is
begin
-- Formulas are based on empirical experimentation and linear/polynomial regression

Expand Down
2 changes: 1 addition & 1 deletion src/raspberry_pi_cpu_formula.ads
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Raspberry_Pi_CPU_Formula is

-- Function to calculate CPU power consumption based on CPU utilization
function Calculate_CPU_Power (CPU_Utilization : Float; Platform_Name : String; Algorithm_Name : String) return Float;
function Calculate_CPU_Power (CPU_Utilization : Long_Float; Platform_Name : String; Algorithm_Name : String) return Long_Float;

end Raspberry_Pi_CPU_Formula;

0 comments on commit 447bfe2

Please sign in to comment.