summaryrefslogtreecommitdiffstats
path: root/pcitool
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-12-13 22:21:24 +0100
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-12-13 22:21:24 +0100
commite43e3c44e9dee571c11a0fed16c27dff177d8c38 (patch)
tree6bb4c2f83e4431a0d2cca4899e38f08a4713b79e /pcitool
parent8ce8c60d7b335d4c1b64a9c726665759a6dd17ba (diff)
downloadpcitool-e43e3c44e9dee571c11a0fed16c27dff177d8c38.tar.gz
pcitool-e43e3c44e9dee571c11a0fed16c27dff177d8c38.tar.bz2
pcitool-e43e3c44e9dee571c11a0fed16c27dff177d8c38.tar.xz
pcitool-e43e3c44e9dee571c11a0fed16c27dff177d8c38.zip
Do event counting when rawcallback is used to stream the data
Diffstat (limited to 'pcitool')
-rw-r--r--pcitool/CMakeLists.txt4
-rw-r--r--pcitool/formaters.c47
-rw-r--r--pcitool/formaters.h12
3 files changed, 61 insertions, 2 deletions
diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt
index ad2cb4e..6dc7942 100644
--- a/pcitool/CMakeLists.txt
+++ b/pcitool/CMakeLists.txt
@@ -2,7 +2,7 @@ include_directories(
${CMAKE_SOURCE_DIR}
)
-set(HEADERS ${HEADERS} sysinfo.h)
+set(HEADERS ${HEADERS} sysinfo.h formaters.h)
-add_library(pcitool STATIC sysinfo.c)
+add_library(pcitool STATIC sysinfo.c formaters.c)
diff --git a/pcitool/formaters.c b/pcitool/formaters.c
new file mode 100644
index 0000000..91b8c77
--- /dev/null
+++ b/pcitool/formaters.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+
+void PrintTime(size_t duration) {
+ if (duration > 999999999999) printf("%4.1lf""d", 1.*duration/86400000000);
+ else if (duration > 99999999999) printf("%4.1lf""h", 1.*duration/3600000000);
+ else if (duration > 9999999999) printf("%4.2lf""h", 1.*duration/3600000000);
+ else if (duration > 999999999) printf("%4.1lf""m", 1.*duration/60000000);
+ else if (duration > 99999999) printf("%4.2lf""m", 1.*duration/60000000);
+ else if (duration > 9999999) printf("%4.1lf""s", 1.*duration/1000000);
+ else if (duration > 999999) printf("%4.2lf""s", 1.*duration/1000000);
+ else if (duration > 999) printf("%3lu""ms", duration/1000);
+ else printf("%3lu""us", duration);
+}
+
+void PrintNumber(size_t num) {
+ if (num > 999999999999999999) printf("%3lue", num/1000000000000000000);
+ else if (num > 999999999999999) printf("%3lup", num/1000000000000000);
+ else if (num > 999999999999) printf("%3lut", num/1000000000000);
+ else if (num > 999999999) printf("%3lug", num/1000000000);
+ else if (num > 999999) printf("%3lum", num/1000000);
+ else if (num > 9999) printf("%3luk", num/1000);
+ else printf("%4lu", num);
+}
+
+void PrintSize(size_t num) {
+ if (num >= 112589990684263) printf("%4.1lf PB", 1.*num/1125899906842624);
+ else if (num >= 109951162778) printf("%4.1lf TB", 1.*num/1099511627776);
+ else if (num >= 107374183) printf("%4.1lf GB", 1.*num/1073741824);
+ else if (num >= 1048576) printf("%4lu MB", num/1048576);
+ else if (num >= 1024) printf("%4lu KB", num/1024);
+ else printf("%5lu B", num);
+}
+
+void PrintPercent(size_t num, size_t total) {
+ if (num >= total) printf(" 100");
+ else printf("%4.1lf", 100.*num/total);
+
+}
+
+char *GetPrintSize(char *str, size_t size) {
+ if (size >= 1073741824) sprintf(str, "%.1lf GB", 1.*size / 1073741824);
+ else if (size >= 1048576) sprintf(str, "%.1lf MB", 1.*size / 1048576);
+ else if (size >= 1024) sprintf(str, "%lu KB", size / 1024);
+ else sprintf(str, "%lu B ", size);
+
+ return str;
+}
diff --git a/pcitool/formaters.h b/pcitool/formaters.h
new file mode 100644
index 0000000..c854da5
--- /dev/null
+++ b/pcitool/formaters.h
@@ -0,0 +1,12 @@
+#ifndef _PCITOOL_FORMATERS_H
+#define _PCITOOL_FORMATERS_H
+
+void PrintTime(size_t duration);
+void PrintNumber(size_t num);
+void PrintSize(size_t num);
+void PrintPercent(size_t num, size_t total);
+char *GetPrintSize(char *str, size_t size);
+
+
+#endif /* _PCITOOL_FORMATERS_H */
+