diff --git a/src/cpu_stat_app.ads b/src/cpu_stat_app.ads index 3389837..1c47997 100644 --- a/src/cpu_stat_app.ads +++ b/src/cpu_stat_app.ads @@ -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; diff --git a/src/cpu_stat_pid.ads b/src/cpu_stat_pid.ads index 8a2e0c8..0431ad8 100644 --- a/src/cpu_stat_pid.ads +++ b/src/cpu_stat_pid.ads @@ -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; diff --git a/src/csv_power.adb b/src/csv_power.adb index ded8ecb..2abc8ab 100644 --- a/src/csv_power.adb +++ b/src/csv_power.adb @@ -11,7 +11,7 @@ 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; @@ -19,7 +19,7 @@ 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 @@ -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 @@ -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); @@ -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; diff --git a/src/csv_power.ads b/src/csv_power.ads index cad41ef..4384633 100644 --- a/src/csv_power.ads +++ b/src/csv_power.ads @@ -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; diff --git a/src/intel_rapl_sysfs.adb b/src/intel_rapl_sysfs.adb index 5a813c7..182c7f6 100644 --- a/src/intel_rapl_sysfs.adb +++ b/src/intel_rapl_sysfs.adb @@ -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; @@ -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; diff --git a/src/intel_rapl_sysfs.ads b/src/intel_rapl_sysfs.ads index e8999ef..326bb74 100644 --- a/src/intel_rapl_sysfs.ads +++ b/src/intel_rapl_sysfs.ads @@ -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 diff --git a/src/nvidia_smi.adb b/src/nvidia_smi.adb index c53b062..29e401d 100644 --- a/src/nvidia_smi.adb +++ b/src/nvidia_smi.adb @@ -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 @@ -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; diff --git a/src/nvidia_smi.ads b/src/nvidia_smi.ads index a3d9ae6..833d03e 100644 --- a/src/nvidia_smi.ads +++ b/src/nvidia_smi.ads @@ -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; diff --git a/src/powerjoular.adb b/src/powerjoular.adb index 0ea6cd4..c0d8e33 100644 --- a/src/powerjoular.adb +++ b/src/powerjoular.adb @@ -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; @@ -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 @@ -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; @@ -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 @@ -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 @@ -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 diff --git a/src/raspberry_pi_cpu_formula.adb b/src/raspberry_pi_cpu_formula.adb index 04cbd24..a94c059 100644 --- a/src/raspberry_pi_cpu_formula.adb +++ b/src/raspberry_pi_cpu_formula.adb @@ -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 diff --git a/src/raspberry_pi_cpu_formula.ads b/src/raspberry_pi_cpu_formula.ads index 9fb84dd..2d9dc1b 100644 --- a/src/raspberry_pi_cpu_formula.ads +++ b/src/raspberry_pi_cpu_formula.ads @@ -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;