aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2016-01-04 23:28:01 -0300
committerMatias Linares <matiaslina@openmailbox.org>2016-01-04 23:28:01 -0300
commit2a41abbed0dfb70447a9c83b17b6d98fcb3c65c6 (patch)
tree1b45eb4a8ac37f346b82f5f6dcfaa5f9e42aad1a
parent2f11d2b1088dcd5d8391d4bd61e342db6198be07 (diff)
downloadprofile-2a41abbed0dfb70447a9c83b17b6d98fcb3c65c6.tar.gz
Finish struct rusage struct fields.
-rw-r--r--Makefile3
-rw-r--r--README.md59
-rw-r--r--profile.c24
3 files changed, 60 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 7bba597..f1a44d8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
CC=clang
-CFLAGS=-Wall -Wextra -O0 -g
+# Enable _ALLOW_UNMANTAINED for non Linux systems
+CFLAGS=-Wall -Wextra -O0 -g # -D_ALLOW_UNMANTAINED
EXE=profile
SOURCES=profile.c
diff --git a/README.md b/README.md
index 43df49b..1d33006 100644
--- a/README.md
+++ b/README.md
@@ -4,31 +4,48 @@ Profile a single program giving stats for CPU, memory and other things (see man
2 getrusage). The standard input is closed for the child process, so programs
like `cat` or `xargs` can't be profiled (for now).
-## Example
+The following list is the data that this software can tell you (on Linux
+systems). The second list is all the features that are unmaintained for linux,
+maybe on other systems it could be useful.
+
+* user CPU time used
+* system CPU time used
+* maximum resident set size
+* page reclaims (soft page faults)
+* page faults (hard page faults)
+* block input operations
+* block output operations
+* voluntary context switches
+* involuntary context switches
+
+### Unmaintained fields
- > ./profile echo hello world
- user CPU time used: 0 3333
- system CPU time used: 0 0
- residet set size used: 2336
+* integral shared memory size
+* integral unshared data size
+* integral unshared stack size
+* swaps
+* IPC messages sent
+* IPC messages received
+* signals received
## TODO
-* [x] user CPU time used
-* [x] system CPU time used
-* [x] maximum resident set size
-* [ ] integral shared memory size
-* [ ] integral unshared data size
-* [ ] integral unshared stack size
-* [ ] page reclaims (soft page faults)
-* [ ] page faults (hard page faults)
-* [ ] swaps
-* [ ] block input operations
-* [ ] block output operations
-* [ ] IPC messages sent
-* [ ] IPC messages received
-* [ ] signals received
-* [ ] voluntary context switches
-* [ ] involuntary context switches
+* Express the CPU time on CPU cycles.
+* Check if there are another function/library that could tell us more info about
+ a child process.
+
+## Example
+
+ > ./profile thunar
+ user CPU time used: 0s 206666us
+ system CPU time used: 0s 49999us
+ residet set size used: 35864
+ page reclaims (soft page faults): 3979
+ page faults (hard page faults): 0
+ block input operations: 0
+ block output operations: 16
+ voluntary context switches: 343
+ involuntary context switches: 26
## Copyright
diff --git a/profile.c b/profile.c
index aa50bee..c447f08 100644
--- a/profile.c
+++ b/profile.c
@@ -120,7 +120,7 @@ int main(int argc, char **argv)
O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
}
- process_child(prog_name, args, fd_out);
+ spawn_child(prog_name, args, fd_out);
}
else
{
@@ -131,9 +131,25 @@ int main(int argc, char **argv)
getrusage(who, &usage);
- printf("user CPU time used:\t%lu %lu\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
- printf("system CPU time used:\t%lu %lu\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
- printf("residet set size used: %ld\n", usage.ru_maxrss);
+ printf("user CPU time used: %lus %luus\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
+ printf("system CPU time used: %lus %luus\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
+ printf("residet set size used: %ld\n", usage.ru_maxrss);
+ printf("page reclaims (soft page faults): %ld\n", usage.ru_minflt);
+ printf("page faults (hard page faults): %ld\n", usage.ru_majflt);
+ printf("block input operations: %ld\n", usage.ru_inblock);
+ printf("block output operations: %ld\n", usage.ru_oublock);
+ printf("voluntary context switches: %ld\n", usage.ru_nvcsw);
+ printf("involuntary context switches: %ld\n", usage.ru_nivcsw);
+
+#ifdef _ALLOW_UNMANTAINED
+ printf("integral shared memory size: %ld\n", usage.ru_ixrss);
+ printf("integral unshared data size: %ld\n", usage.ru_idrss);
+ printf("integral unshared stack size: %ld\n", usage.ru_isrss);
+ printf("swaps: %ld\n", usage.ru_nswap);
+ printf("IPC messages sent: %ld\n", usage.ru_msgsnd);
+ printf("IPC messages received: %ld\n", usage.ru_msgrcv);
+ printf("signals received: %ld\n", usage.ru_nsignals);
+#endif
}
return status;