Skip to content

Commit

Permalink
Merge pull request #48 from joular/develop
Browse files Browse the repository at this point in the history
0.7.3
  • Loading branch information
adelnoureddine authored Apr 2, 2024
2 parents 509d181 + 00c6458 commit 2308f2e
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ada.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ada (GNAT)
name: Build

on:
push:
Expand All @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up GNAT toolchain
run: >
Expand Down
2 changes: 1 addition & 1 deletion alire.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "powerjoular"
description = "Monitoring the power consumption of multiple platforms and processes"
version = "0.7.2"
version = "0.7.3"

authors = ["Adel Noureddine"]
maintainers = ["Adel Noureddine <[email protected]>"]
Expand Down
39 changes: 28 additions & 11 deletions installer/create-packages.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
#!/bin/sh

# Create folders for pacakge formats
mkdir deb
# For Debian, Ubuntu (.deb package)

# Create folder structure for debian
mkdir -p deb/powerjoular/usr/bin deb/powerjoular/etc/systemd/system deb/powerjoular/DEBIAN
for ARCH in amd64 arm64 armhf
do
rm -rf $ARCH

# Create folder for architecture and package format
mkdir -p $ARCH/powerjoular/usr/bin $ARCH/powerjoular/etc/systemd/system $ARCH/powerjoular/DEBIAN

# Copy binary files for deb package
cp ../obj/powerjoular ./deb/powerjoular/usr/bin/
cp ../systemd/powerjoular.service ./deb/powerjoular/etc/systemd/system/
cp ./debian-control-$1.txt ./deb/powerjoular/DEBIAN/control
# Copy binary files for deb package
cp ../obj/powerjoular ./$ARCH/powerjoular/usr/bin/
cp ../systemd/powerjoular.service ./$ARCH/powerjoular/etc/systemd/system/
cp ./debian-control-$ARCH.txt ./$ARCH/powerjoular/DEBIAN/control

# Create deb package
cd deb
dpkg-deb --build powerjoular
# Create deb package
cd ./$ARCH
VERSION=$(grep '^Version:' powerjoular/DEBIAN/control | awk '{print $2}')
dpkg-deb --build powerjoular
mv powerjoular.deb powerjoular_${VERSION}_${ARCH}.deb
cd ..
done

# For Red Hat, Fedora (.rpm package)
rm -rf rpmbuild
mkdir rpmbuild
cd rpmbuild
mkdir BUILD RPMS SOURCES SPECS SRPMS
cd ..
cp ../obj/powerjoular ./rpmbuild/SOURCES/
cp ../systemd/powerjoular.service ./rpmbuild/SOURCES/
cp ./powerjoular.spec ./rpmbuild/SPECS/
rpmbuild -bb --define "_topdir $(pwd)/rpmbuild" ./rpmbuild/SPECS/powerjoular.spec
2 changes: 1 addition & 1 deletion installer/debian-control-amd64.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: powerjoular
Version: 0.7.2
Version: 0.7.3
Maintainer: Adel Noureddine
Architecture: amd64
Description: PowerJoular allows monitoring power consumption of multiple platforms and processes.
2 changes: 1 addition & 1 deletion installer/debian-control-arm64.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: powerjoular
Version: 0.7.2
Version: 0.7.3
Maintainer: Adel Noureddine
Architecture: arm64
Description: PowerJoular allows monitoring power consumption of multiple platforms and processes.
2 changes: 1 addition & 1 deletion installer/debian-control-armhf.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: powerjoular
Version: 0.7.2
Version: 0.7.3
Maintainer: Adel Noureddine
Architecture: armhf
Description: PowerJoular allows monitoring power consumption of multiple platforms and processes.
2 changes: 1 addition & 1 deletion src/help_info.adb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

package body Help_Info is

Version_Number : constant String := "0.7.2";
Version_Number : constant String := "0.7.3";

procedure Show_Help is
begin
Expand Down
22 changes: 22 additions & 0 deletions src/intel_rapl_sysfs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,26 @@ package body Intel_RAPL_sysfs is
--Put_Line ("Error reading file " & Package_Name & " for Intel RAPL.");
end;

procedure Get_Max_Energy_Range (RAPL_Data : in out Intel_RAPL_Data; Package_Name : in String) is
F_Name : File_Type; -- File handle
Folder_Name : constant String := "/sys/class/powercap/intel-rapl/"; -- Folder prefix for file to read
begin
if (Package_Name = "psys") then
Open (F_Name, In_File, Folder_Name & "intel-rapl:1/max_energy_range_uj");
RAPL_Data.psys_max_energy_range := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
elsif (Package_Name = "pkg") then
Open (F_Name, In_File, Folder_Name & "intel-rapl:0/max_energy_range_uj");
RAPL_Data.pkg_max_energy_range := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
elsif (Package_Name = "dram") then
Open (F_Name, In_File, Folder_Name & "intel-rapl:0/intel-rapl:0:2/max_energy_range_uj");
RAPL_Data.dram_max_energy_range := Long_Float'Value (Get_Line (F_Name)) / 1000000.0;
Close (F_Name);
end if;
exception
when others =>
return;
end;

end Intel_RAPL_sysfs;
6 changes: 6 additions & 0 deletions src/intel_rapl_sysfs.ads
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ package Intel_RAPL_sysfs is
psys_supported : Boolean := False; -- if system supports psys
pkg_supported : Boolean := False; -- if system supports pkg 0
dram_supported : Boolean := False; -- if system support dram 0

-- Data to store max energy ranges
pkg_max_energy_range : Long_Float := 0.0; -- pkg max_energy_range_uj
psys_max_energy_range : Long_Float := 0.0; -- psys max_energy_range_uj
dram_max_energy_range : Long_Float := 0.0; -- dram max_energy_range_uj
end record;

-- Calculate total energy consumption from Linux powercap sysfs
Expand All @@ -38,4 +43,5 @@ package Intel_RAPL_sysfs is
-- So far, only package 0 is supported (and dram in package 0)
procedure Check_Supported_Packages (RAPL_Data : in out Intel_RAPL_Data; Package_Name : in String);

procedure Get_Max_Energy_Range (RAPL_Data : in out Intel_RAPL_Data; Package_Name : in String);
end Intel_RAPL_sysfs;
39 changes: 33 additions & 6 deletions src/powerjoular.adb
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,28 @@ begin
if Check_Intel_Supported_System (Platform_Name) then
-- For Intel RAPL, check and populate supported packages first
Check_Supported_Packages (RAPL_Before, "psys");
if RAPL_Before.psys_supported and Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL psys: " & Boolean'Image (RAPL_Before.Psys_Supported));

if RAPL_Before.psys_supported then
Get_Max_Energy_Range (RAPL_Before, "psys");
if Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL psys: " & Boolean'Image (RAPL_Before.Psys_Supported));
end if;
end if;

if (not RAPL_Before.psys_supported) then -- Only check for pkg and dram if psys is not supported
Check_Supported_Packages (RAPL_Before, "pkg");
Check_Supported_Packages (RAPL_Before, "dram");
if RAPL_Before.Pkg_Supported and Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL pkg: " & Boolean'Image (RAPL_Before.pkg_supported));
if RAPL_Before.Pkg_Supported then
Get_Max_Energy_Range (RAPL_Before, "pkg");
if Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL pkg: " & Boolean'Image (RAPL_Before.pkg_supported));
end if;
end if;
if RAPL_Before.Dram_Supported and Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL dram: " & Boolean'Image (RAPL_Before.Dram_Supported));
if RAPL_Before.Dram_Supported then
Get_Max_Energy_Range (RAPL_Before, "dram");
if Show_Debug then
Put_Line (Ada.Characters.Latin_1.HT & "Intel RAPL dram: " & Boolean'Image (RAPL_Before.Dram_Supported));
end if;
end if;
end if;
RAPL_After := RAPL_Before; -- Populate the "after" data type with same checking as the "before" (insteaf of wasting redundant calls to procedure)
Expand Down Expand Up @@ -257,6 +267,23 @@ begin
if Check_Intel_Supported_System (Platform_Name) then
-- Calculate Intel RAPL energy consumption
RAPL_Energy := RAPL_After.total_energy - RAPL_Before.total_energy;

if RAPL_Before.total_energy > RAPL_After.total_energy then
-- energy has wrapped
if RAPL_Before.psys_supported then
RAPL_Energy := RAPL_Energy + RAPL_Before.psys_max_energy_range;
elsif RAPL_Before.Pkg_Supported then
RAPL_Energy := RAPL_Energy + RAPL_Before.pkg_max_energy_range;
end if;
end if;

if RAPL_Before.Pkg_Supported and RAPL_Before.Dram_supported then
if RAPL_Before.dram > RAPL_After.dram then
-- dram has wrapped
RAPL_Energy := RAPL_Energy + RAPL_Before.dram_max_energy_range;
end if;
end if;

CPU_Power := RAPL_Energy;
Total_Power := CPU_Power;
end if;
Expand Down

0 comments on commit 2308f2e

Please sign in to comment.