cputil is a valgrind tool for estimating CPU utilization within user code. Users can call a GETCTR hook to get the current count of clock cycles.
Matthew Wette 817e1327c4 update to VG 3.22 | 1 year ago | |
---|---|---|
cuts | 1 year ago | |
docs | 8 years ago | |
patch | 1 year ago | |
tests | 1 year ago | |
.gitignore | 8 years ago | |
COPYING | 8 years ago | |
Makefile.am | 8 years ago | |
Makefile.in | 1 year ago | |
README.md | 1 year ago | |
cputil.h | 4 years ago | |
cputildefs.h | 8 years ago | |
cu_main.c | 1 year ago | |
gen_header.py | 3 years ago | |
gen_tables.py | 3 years ago | |
gen_utils.py | 3 years ago | |
mindist.in | 1 year ago | |
upd-vg-files | 1 year ago |
Copyright (C) 2016-2017,2021,2023 -- Matthew Wette.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included with the distribution as COPYING.DOC.
The cputil program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This valgrind tool provides approximate cycle counts for user-defined regions of code. It works on a per-thread basis. The following program, when executed under cputil/valgrind will report the estimated number of clock cycles required to execute foo(). The default processor model is a PowerPC750, but can be changed with a user-loadable table.
#include <stdio.h>
#include "cputil.h"
int main() {
long cycles;
CU_REGTHR(); /* register the current thread */
for (i = 0; i < 5; i++) {
CU_CLRCTR(); /* clear the cycle counter */
foo(i);
cycles += CU_GETCTR(); /* read the cycle counter */
bar(i);
}
printf("clk-cycles=%d\n", cycles)
}
This works with valgrind-3.22.0. I assume it will work with 3.22.X. To work with older versions of valgrind, try other git branches.
To install:
Download and unpack valgrind-3.22.X
Clone or otherwise install this cputil distribution in a directory called cputil under valgrind-3.22.X
In the valgrind top-level directory execute:
$ cputil/upd-vg-files
$ ./autogen.sh
4a. In the valgrind top directory run configure, make and install:
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
On macOS, you may need to perform the following steps:
$ CFLAGS="" ./configure --prefix=/usr/local \
./configure --enable-only64bit --prefix=/usr/local
4b. Optionally, if you want a minimal distribution, use this sequence,
using /var/tmp/mindist as a place to install the distribution:
$ ./configure --prefix=/usr/local
$ make
$ mkdir -p /var/tmp/mindist
$ make DESTDIR=/var/tmp/mindist/ install
$ sh cputil/mindist DESTDIR=/var/tmp/mindist
The above will generate a distribution. To install, become root if necessary, then execute the following:
# cd /var/tmp/mindist
# cd usr/local
# tar cf - . | (cd /usr/local; tar xvf -)
In this case, the command to execute is cputil'
instead of
valgrind --tool=cputil`.
To dump the internal table execute
$ valgrind --tool=cputil --dump-op-table=dump.cut true
[OR, for min dist, cputil --dump-op-table=dump.cut true]
There is no way to dump the op-table w/o specifing a program to so we use use /bin/true.
A dumped op table can be edited for clock counts and used for another run:
$ valgrind --tool=cputil --load-op-table=dump.cut my_program
Support for multi-threaded code has been added.
Look in cputil/tests/demo1.c
If you see the following error during compilation then your version of valgrind still does works to MPI1.
libmpiwrap.c: In function 'showTy': libmpiwrap.c:281:19: error: 'MPI_UB' undeclared (first use in this function);
did you mean 'MPI_IO'?
281 | else if (ty == MPI_UB) fprintf(f,"UB");
| ^~~~~~
| MPI_IO
The included patch
0001-Drop-MPI-1-support.patch
from
https://bugs.kde.org/show_bug.cgi?id=401416#c3
should help. To apply, from valgring top directory,
$ patch -b -p1 < cputil/patch/0001-Drop-MPI-1-support.patch