Skip to content

Commit

Permalink
Hotfix for handling exceptions for command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
adelnoureddine committed Jul 8, 2024
1 parent 1841a2b commit 5fe6092
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 51 deletions.
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 = "1.0.2"
version = "1.0.3"

authors = ["Adel Noureddine"]
maintainers = ["Adel Noureddine <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion installer/aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintainer: Adel Noureddine <[email protected]>
pkgname=powerjoular
pkgver=1.0.2
pkgver=1.0.3
pkgrel=1
pkgdesc="PowerJoular allows monitoring power consumption of multiple platforms and processes."
arch=('x86_64' 'aarch64' 'armv7h')
Expand Down
4 changes: 3 additions & 1 deletion installer/powerjoular.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: powerjoular
Version: 1.0.2
Version: 1.0.3
Release: 1%{?dist}
Summary: PowerJoular allows monitoring power consumption of multiple platforms and processes.

Expand All @@ -22,6 +22,8 @@ install -m 644 %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/systemd/system/%{name}.
%{_sysconfdir}/systemd/system/%{name}.service

%changelog
* Thu Jul 08 2024 Adel Noureddine <[email protected]> - 1.0.3-1
- Hotfix for handle exceptions for invalid command line arguments
* Thu Jul 08 2024 Adel Noureddine <[email protected]> - 1.0.2-1
- Handle exceptions for invalid command line arguments
- Add doc for VM in -h command
Expand Down
2 changes: 1 addition & 1 deletion release-version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION=1.0.2
VERSION=1.0.3

# First cross compiler

Expand Down
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 := "1.0.2";
Version_Number : constant String := "1.0.3";

procedure Show_Help is
begin
Expand Down
98 changes: 52 additions & 46 deletions src/powerjoular.adb
Original file line number Diff line number Diff line change
Expand Up @@ -113,59 +113,65 @@ procedure Powerjoular is
OS_Exit (0);
end CtrlCHandler;

procedure Manage_OPT is
begin
-- Loop over command line options
loop
case Getopt ("h v t d f: p: a: o: u l m: s: k") is
when 'h' => -- Show help
Show_Help;
OS_Exit (0);
when 'v' => -- Show help
Show_Version;
OS_Exit (0);
when 't' => -- Show power data on terminal
Show_Terminal := True;
when 'd' => -- Show debug info on terminal
Show_Debug := True;
when 'p' => -- Monitor a particular PID
-- PID_Number := Integer'Value (Parameter);
CPU_PID_Monitor.PID_Number := Integer'Value (Parameter);
Monitor_PID := True;
when 'a' => -- Monitor a particular application by its name
CPU_App_Monitor.App_Name :=
To_Unbounded_String (Parameter);
Monitor_App := True;
when 'f' => -- Specifiy a filename for CSV file (append data)
CSV_Filename := To_Unbounded_String (Parameter);
Print_File := True;
when 'o' => -- Specifiy a filename for CSV file (overwrite data)
CSV_Filename := To_Unbounded_String (Parameter);
Print_File := True;
Overwrite_Data := True;
when 'l' => -- Use linear regression model instead of polynomial models
Algorithm_Name := To_Unbounded_String ("linear");
when 'm' => -- Specify a filename for the power consumption of the VM
VM_File_Name := To_Unbounded_String (Parameter);
Monitor_VM := True;
when 's' => -- Specify a data format for the VM power
VM_Power_Format := To_Unbounded_String (Parameter);
Monitor_VM := True;
when 'k' => -- Use TIDs to calculate PID stats instead of PID stat directly (Experimental feature)
TID_PID := True;
when others =>
exit;
end case;
end loop;
exception
when Invalid_Switch | Invalid_Parameter =>
Put_Line ("Invalid command line option, or option not used properly.");
OS_Exit (0);
end Manage_OPT;

begin
-- Capture Ctrl+C and redirect to handler
Install_Handler(Handler => CtrlCHandler'Unrestricted_Access);

-- Default CSV filename
CSV_Filename := To_Unbounded_String ("./powerjoular-power.csv");

-- Loop over command line options
loop
case Getopt ("h v t d f: p: a: o: u l m: s: k") is
when 'h' => -- Show help
Show_Help;
return;
when 'v' => -- Show help
Show_Version;
return;
when 't' => -- Show power data on terminal
Show_Terminal := True;
when 'd' => -- Show debug info on terminal
Show_Debug := True;
when 'p' => -- Monitor a particular PID
-- PID_Number := Integer'Value (Parameter);
CPU_PID_Monitor.PID_Number := Integer'Value (Parameter);
Monitor_PID := True;
when 'a' => -- Monitor a particular application by its name
CPU_App_Monitor.App_Name :=
To_Unbounded_String (Parameter);
Monitor_App := True;
when 'f' => -- Specifiy a filename for CSV file (append data)
CSV_Filename := To_Unbounded_String (Parameter);
Print_File := True;
when 'o' => -- Specifiy a filename for CSV file (overwrite data)
CSV_Filename := To_Unbounded_String (Parameter);
Print_File := True;
Overwrite_Data := True;
when 'l' => -- Use linear regression model instead of polynomial models
Algorithm_Name := To_Unbounded_String ("linear");
when 'm' => -- Specify a filename for the power consumption of the VM
VM_File_Name := To_Unbounded_String (Parameter);
Monitor_VM := True;
when 's' => -- Specify a data format for the VM power
VM_Power_Format := To_Unbounded_String (Parameter);
Monitor_VM := True;
when 'k' => -- Use TIDs to calculate PID stats instead of PID stat directly (Experimental feature)
TID_PID := True;
when others =>
exit;
end case;
end loop;
exception
when Invalid_Switch | Invalid_Parameter =>
Put_Line ("Invalid command line option, or option not used properly.");
OS_Exit (0);
-- Check command line arguments
Manage_OPT;

if (Argument_Count = 0) then
Show_Terminal := True;
Expand Down

0 comments on commit 5fe6092

Please sign in to comment.