Extracting power consumption for a specific process from ubuntu powertop tool

1.2k views Asked by At

I need to measure the power consumption of one of my algorithms and I'm using powertop utility for this purpose. However, I need to be able to extract the power consumption for my specific process from the list displayed the interactive shell in predefined intervals.

Could someone please help me with this task?.

Thanks in advance.

1

There are 1 answers

0
Taylor Kidd On

"powertop -d" doesn't use an interactive shell so you can use it with a for, while or other such bash construct.

One way is to do your collection programmatically in a loop in a program you write using the system() command.

Another way is to do the same thing but using the bash shell's for/while/until looping construct and piping it into the command you want. You can write your own special program if you want to do complex parsing, such as "powertop -d | my_parsing_and_display_program". If you want simple parsing, you can just pipe the output into grep, awk or sed:

for i in 1 2; do powertop -d | sed -n '?bus/usb? p' ; done

You can also substitute grep or awk in place of sed. (Yes, I'm a sed person.)