aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md9
-rw-r--r--i915-watt.c31
3 files changed, 42 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b187608
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+CFLAGS ?= -O3 -march=native
+i915-watt:
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ee36e16
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+### i915-watt
+
+This tool displays second-long samples of power usage of the Intel graphics card.
+
+```
+$ git clone https://git.zx2c4.com/i915-watt && cd i915-watt
+$ make
+$ sudo ./i915-watt
+```
diff --git a/i915-watt.c b/i915-watt.c
new file mode 100644
index 0000000..bfbb64b
--- /dev/null
+++ b/i915-watt.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *f;
+ uint64_t this_microjoules, last_microjoules = ~UINT64_C(0);
+
+ setbuf(stdout, NULL);
+ f = fopen("/sys/kernel/debug/dri/0/i915_energy_uJ", "r");
+ if (!f) {
+ perror("fopen(/sys/kernel/debug/dri/0/i915_energy_uJ)");
+ return 1;
+ }
+
+ printf("Measuring...");
+ for (;;) {
+ if (fscanf(f, "%" PRIu64, &this_microjoules) != 1) {
+ perror("fscanf");
+ return 1;
+ }
+ rewind(f);
+ if (last_microjoules != ~UINT64_C(0))
+ printf("\x1b[0G\x1b[0K%.2f W", (double)(this_microjoules - last_microjoules) / 1000000.0);
+ last_microjoules = this_microjoules;
+ sleep(1);
+ }
+ return 0;
+}