Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ribalba committed Sep 20, 2023
1 parent 805ec2d commit 1373880
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 275 deletions.
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# hog
# The Power Hog

<img src="logo.png" width="100"/>

The hog is a tool that periodically collects energy statistics of your mac and makes them available to you.
The power hog is a tool that periodically collects energy statistics of your mac and makes them available to you.

There are two main aims:

1) Identify which apps are using a lot of energy on your machine.
2) Collecting the data from as many machines as possible to identify wasteful apps.
2) Collecting the data from as many machines as possible to identify wasteful apps globally.

The hog consists of 2 apps.
We provide a website for detailed analytics of your data. The hog by default uploads your measurement data to our
[Green Metrics Tool](https://github.com/green-coding-berlin/green-metrics-tool) backend. We put in a lot of effort
to make sure that no confidential information is exposed but please refer to the [settings](#settings) section if you
want to disable the upload or submit the data to your own [backend](https://docs.green-coding.berlin/docs/installation/installation-linux/).

The hog consists of 2 apps that run on your local system. You need to power logger but not the app!

## Power logger

Expand All @@ -20,7 +25,20 @@ give some statistics. You can either call it by hand and send it to the backgrou
For development purposes we recommend to always first run the program in the foreground and see if everything works fine
and then use the launch agent.

### Launch agent
If you want to avoid running the desktop app you can call the `power_logger.py` script with `-w` which will give
you the details url.

You can also run the `powermetrics` process yourself and then use `power_logger.py` to process the data and upload it.
You can use the `-f` parameter with a filename. Please submit the data in the plist format. You can use the following call string:
`powermetrics --show-all -i 5000 -f plist -o FILENAME` and to run the powermetrics process yourself.

### Parameter list

- `-d`: Set's debug/ development mode to true. The Settings are set to local environments and we output statistics when running.
- `-w`: Gives you the url of the analysis website and exits. This is especially useful when not using the desktop app
- `-f filename`: Use the file as powermetrics input and don't start the process internally.

### Setup of the power collection script

This is a description on how to set everything up if you did a git clone. You can also just do

Expand All @@ -29,6 +47,8 @@ curl -fsSL https://raw.githubusercontent.com/green-coding-berlin/hog/main/instal
```
which will do the whole install for you.

#### Do it manually

Make the `power_logger.py` script executable with `chmod a+x power_logger.py`

Please modify the `berlin.green-coding.hog.plist` file to reference the right path. There is a script below that does
Expand Down Expand Up @@ -69,16 +89,30 @@ sudo launchctl unload /Library/LaunchDaemons/berlin.green-coding.hog.plist
### Settings

It is possible to configure your own settings by using a `settings.ini` file in the same directory as the `power_logger.py`
script. Following keys are currently used:
script or adding a `.hog_settings.ini` to your home folder. The home folder settings will be prioritized.

Following keys are currently used:

- `powermetrics`: This is the delta in ms that power metrics should take samples. So if you set this to 5000 powermetrics will return the aggregated values every 5 seconds
- `upload_delta`: This is the time delta data should be uploaded in seconds.
- `api_url`: The url endpoint the data should be uploaded to. You can use the https://github.com/green-coding-berlin/green-metrics-tool if you want but also write/ use your own backend.
- `web_url`: The url where the analytics can be found. We will append the machine ID to this so make sure the end of the string is a `=`

## The desktop App

The hog desktop app gives you analytics of the data that was recorded. Please move this into your app folder.

### Description of the headings

- `Name`: This is the name of the process coalition. A coalition can be multiple processes. For example a program might fork
new process which will all show up in the coalition. Sometimes a shell might turn up here. Please tell us so we can
add this as an exception
- `Energy Impact`: This is the value mac gives it's processes. The exact formula is not known but we know that quite some
factors are considered. For now this is the best value we've got 🫣
- `AVG Cpu Time %`: This is how long this coalition has spent on the CPUs. We take a percentage which can be over 100% as
the coalition could run on multiple cpus at the same time. So if a process takes up 100% of cpu time and runs on 4 cpus
the time will be 400%.

## Database

All data is saved in an sqlite database that is located under:
Expand Down
22 changes: 17 additions & 5 deletions app/hog/hog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1500;
TargetAttributes = {
0AEC07722A40D4C2003C82E7 = {
CreatedOnToolsVersion = 14.3.1;
Expand Down Expand Up @@ -307,6 +307,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -336,9 +337,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -368,6 +371,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -397,9 +401,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down Expand Up @@ -429,21 +435,22 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"hog/Preview Content\"";
DEVELOPMENT_TEAM = SBWA476E6F;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = hog/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Hog;
INFOPLIST_KEY_CFBundleDisplayName = "Power Hog";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = "berlin.green-coding.hog";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -462,21 +469,22 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"hog/Preview Content\"";
DEVELOPMENT_TEAM = SBWA476E6F;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = hog/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Hog;
INFOPLIST_KEY_CFBundleDisplayName = "Power Hog";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = "berlin.green-coding.hog";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -491,6 +499,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = SBWA476E6F;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
Expand All @@ -510,6 +519,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = SBWA476E6F;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.3;
Expand All @@ -528,6 +538,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = SBWA476E6F;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand All @@ -545,6 +556,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = SBWA476E6F;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion app/hog/hog.xcodeproj/xcshareddata/xcschemes/hog.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit 1373880

Please sign in to comment.