40
submitted 9 months ago* (last edited 9 months ago) by N0x0n@lemmy.ml to c/linux@lemmy.ml

Hello everyone !

I have no idea if I’m in the right community, because it’s a mix of hardware and some light code/command to extract the power consumption out of my old laptop. I need some assistance and if someone way more intelligent than me could check the code and give feedback :)

Important infos

  • 12 year old ASUS N76 laptop
  • Bare bone server running Debian 12
  • No battery (died long time ago)

Because I have no battery connected to my laptop It's impossible to use tools like lm-sensors, powerstat, powertop to output the wattage. But from the following ressource I can estimate the power based on the Energy.

time=1
declare T0=($(sudo cat /sys/class/powercap/*/energy_uj)); sleep $time; declare T1=($(sudo cat /sys/class/powercap/*/energy_uj))
for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\", $((${T1[i]}-${T0[i]})) / $time / 1e6 }" ; done

While It effectively outputs something, I'm not sure if I can rely on that to estimate the power consumption and if the code is actually correct? :/

Thanks :).

Edit:

My goal is to calculate the power drawn from my laptop without any electric appliance (maybe a worded my question/title wrong?). While It could be easily done with the top package or lm-sensors, this only work by measuring the battery discharge, which in my case is impossible because my laptop is directly connected to the outlet with his power cord (battery died years ago).

I dug a bit further through the web and found someone who asked the same question on superuser.com. While this gives a different reference point, nobody actually could answer the question.

This seems a bit harder than I though and is actually related to the /sys/class/powercap/*/energy_uj files and though someone could give me a bit more details on how this works and what the output actually shows.

This is also related to the power capping framework in the linux kernel? And as per the documentation this is representing the CPU packages current energy counter in micro joules.

So I came a bit closer in understanding how it works and what it does, even tough I’m still not sure what am I actually looking at :\ .

all 17 comments
sorted by: hot top controversial new old
[-] NeonWoofGenesis@l.henlo.fi 22 points 9 months ago

Why not buy a wattmeter and observe the real usage?

[-] N0x0n@lemmy.ml 5 points 9 months ago

This is probably the most precise way ! It feels a bit stupid to say... But I have actually no idea how to use that device :/... Maybe something I need to add to my toLearn list.

Also, I'm trying to find my way arround linux and because everything is mathematically doable with the right values, a good estimate through a code/command is more convenient.

[-] fuckwit_mcbumcrumble@lemmy.world 9 points 9 months ago

Kill-a-watt is the most popular one. In the US they’re sold in harbor freight stores for like $30.

I put that meter on everything. I love it.

[-] MrZee@lemm.ee 7 points 9 months ago

If you look for a “watt meter plug”, you’ll pribably understand what it is at a glance. It’s a device you plug into your wall outlet (or surge protector or whatever). It has a power outlet on it, which you plug your device into, and a screen that shows watts drawn and watt-hours over time. Super simple. I think “Kill A Watt” is the most well known brand.

[-] rambos@lemm.ee 2 points 9 months ago

Shelly plug S

Install mobile app and you can see everything there

[-] fuckwit_mcbumcrumble@lemmy.world 11 points 9 months ago

What is your goal with measuring this? Be aware that power consumption is designed to spike and return low. Most modern laptops won’t run very fast with a dead battery. Even with a high wattage charger because the spikes are too intense. Even with the highest wattage charger.

The average power estimates that hwinfo in windows gets me is pretty accurate, but even it can’t account fully for the spikes. I’m not sure what the best equivalent is for Linux.

[-] N0x0n@lemmy.ml 1 points 9 months ago

My goal is to calculate the power drawn from my laptop without any electric appliance (maybe a worded my question/title wrong?). While It could be easily done with the top package or lm-sensors, this only work by measuring the battery discharge, which in my case is impossible because my laptop is directly connected to the outlet with his power cord (battery died years ago).

I dug a bit further through the web and found someone who asked the same question on superuser.com. While this gives a different reference point, nobody actually could answer the question.

This seems a bit harder than I though and is actually related to the /sys/class/powercap/*/energy_uj files and though someone could give me a bit more details on how this works and what the output actually shows.

This is also related to the power capping framework in the linux kernel? And as per the documentation this is representing CPU packages current energy counter in micro joules.

So I came a bit closer in understanding how it works and what it does, even tough I'm not sure what am I actually looking at :\ .

[-] Doombot1@lemmy.one 3 points 9 months ago

If you’re not running with a battery, the maximum wattage of the charging brick should be shown on the brick itself. Either that or you can calculate it with P=I*V (amps * volts). That won’t give you what the laptop draws on average (likely much less than the calculated value) but it will give you a maximum.

[-] atzanteol@sh.itjust.works 4 points 9 months ago

It will give you the maximum of what the power supply is capable of providing which is nothing like what the laptop actually uses.

[-] Still@programming.dev 2 points 9 months ago

all the laptops I've ever had have been able to reliability pull the full power (like within 30 watts) of their power adapter rating so that's a good estimate

[-] N0x0n@lemmy.ml 2 points 9 months ago

I'm not sure about that. Specially because it's used as a bare bone server without any GUI with the lid closed. So it will draw way less power than showed on the charging brick.

[-] Still@programming.dev 1 points 9 months ago

ah I misunderstood, thought you talking about underload, not idle power use

[-] N0x0n@lemmy.ml 1 points 9 months ago

Naaah maybad ! My title was probably a bit missleading and not precise enough.

[-] just_another_person@lemmy.world 1 points 9 months ago

On machine, powertop can estimate battery drain. For ACTUAL measurement, smartplug I guess. I think monoprice has them cheap.

this post was submitted on 01 Mar 2024
40 points (95.5% liked)

Linux

48687 readers
361 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS