intel / pcm

Intel® Performance Counter Monitor (Intel® PCM)
BSD 3-Clause "New" or "Revised" License
2.79k stars 476 forks source link

Timestamp per measurement #467

Open thatsdone opened 2 years ago

thatsdone commented 2 years ago

Hi, This is a suggestion.

I'm working on detailed power consumption analysis for various workload patterns using PCM, and I thought it would be a good idea to have a timestamp field per measurement result for time series behavior analysis.

The below is an example of my local modification of 'pcm-power'

[root@host1 pcm]#  build/bin/pcm-power 1

 Intel(r) Performance Counter Monitor ($Format:%ci ID=%h$)

 Power Monitoring Utility

=====  Processor information  =====
Linux arch_perfmon flag  : yes

(snip)

----------------------------------------------------------------------------------------------
Timestamp (us): 1667463641461974  <== TIMESTAMP per measurement HERE
Time elapsed: 997 ms
Called sleep function for 1000 ms
S0; Uncore Freq: 2.40 Ghz; Core Freq: 1.69 Ghz; Core Power License 0: 100.00%; Core Power License 1: 0.00%; Core Power License 2: 0.00%;
S0P0; UPI Clocks: 1297835485; L0p Tx Cycles: 0.00%; L1 Cycles: 0.00%
S0P1; UPI Clocks: 1297837626; L0p Tx Cycles: 0.00%; L1 Cycles: 0.00%
(snip)

Also, my modifications are just below. In this sense, this can be true for other tools like 'pcm-core', 'pcm-memory' etc.

# git log -n 1 --oneline
0b320ca (HEAD -> master, origin/master, origin/HEAD) Merge pull request #466 from intel/push-2022-10-31
# git diff
diff --git a/src/pcm-power.cpp b/src/pcm-power.cpp
index e9ebc74..3c414a9 100644
--- a/src/pcm-power.cpp
+++ b/src/pcm-power.cpp
@@ -357,6 +357,9 @@ int main(int argc, char * argv[])

         if (!csv) cout << flush;

+        struct timeval timestamp;
+        gettimeofday(&timestamp, NULL);
+
         const auto delay_ms = calibratedSleep(delay, sysCmd, mainLoop, m);

         AfterTime = m->getTickCount();
@@ -365,6 +368,7 @@ int main(int argc, char * argv[])

         m->getAllCounterStates(dummySystemState, afterSocketState, dummyCoreStates, false);

+        cout << "Timestamp (us): " << (timestamp.tv_sec * 1000000 + timestamp.tv_sec) << "\n";
         cout << "Time elapsed: " << AfterTime - BeforeTime << " ms\n";
         cout << "Called sleep function for " << delay_ms << " ms\n";
         for (uint32 socket = 0; socket < numSockets; ++socket)

Regards, Masanori

rdementi commented 1 year ago

thanks for the suggestion. Since not users need this I would suggest to make it optional and also platform independent. Does it compile on Windows/FreeBSD/etc?