570 Commits

Author SHA1 Message Date
Mark Wielaard
9d6d45cfde Add cachegrind/tests/ann-diff4b-aux/w.rs
Missing testfile from commit 1fdf0e728a047f0aab4de805576b6a3a84f37b79
"Add diff and merge capability to `cg_annotate`."
2023-04-21 16:15:19 +02:00
Nicholas Nethercote
b12703598a Fix two xmllint errors. 2023-04-21 23:00:39 +10:00
Nicholas Nethercote
c2e62127ad Rewrite Cachegrind docs.
For all the changes I've made recently. And also various other changes
that occurred over the past 20 years that didn't previously make it into
the docs.

Also, this change de-emphasises the cache and branch simulation aspect,
because they're no longer that useful. Instead it emphasises the
precision and reproducibility of instruction count profiling.
2023-04-21 22:18:10 +10:00
Nicholas Nethercote
15a11f98f5 Get rid of cache config warnings with --cache-sim=no.
By not configuring the caches in that case. This requires moving a few
assertions around, because they currently assume that the caches are
configured.
2023-04-21 22:18:09 +10:00
Nicholas Nethercote
2cccba7cae Tweak printing of I refs and D refs lines.
Because `--cache-sim=no` is the default now, and `I   refs:` looks weird
by itself.
2023-04-21 22:18:09 +10:00
Nicholas Nethercote
307f96a519 Reorder options in Cachegrind's -h output.
Put the commonly used ones first.
2023-04-21 22:18:09 +10:00
Nicholas Nethercote
1fdf0e728a Add diff and merge capability to cg_annotate.
And deprecate the use of `cg_diff` and `cg_merge`.

Because `cg_annotate` can do a better job, even annotating source files
when doing diffs in some cases.

The user requests merging by passing multiple cgout files to
`cg_annotate`, and diffing by passing two cgout files to `cg_annotate`
along with `--diff`.
2023-04-21 22:18:09 +10:00
Nicholas Nethercote
b0e9fef201 cg_annotate: Remove the -I/--include option.
For much the same reasons that I removed user annotations recently: it's
rarely/never used, and complicates things.
2023-04-19 08:41:08 +10:00
Nicholas Nethercote
57dbcacfdb Make --cache-sim=no the default for Cachegrind.
Also, don't print cache simulation details in the `desc:` line when the
cache simulation is disabled.

Docs changes are yet to come.
2023-04-12 11:08:15 +10:00
Nicholas Nethercote
8765b3358f Overhaul cg_annotate output.
Most notable, the "Function summary" section, which printed one CC for each
`file:function` combination, has been replaced by two sections, "File:function
summary" and "Function:file summary".

These new sections both feature "deep CCs", which have an "outer CC" for the
file (or function), and one or more "inner CCs" for the paired functions (or
files).

Here is a file:function example, which helps show which files have a lot of
events, even if those events are spread across a lot of functions.
```
> 12,427,830 (5.4%, 26.3%)  /home/njn/moz/gecko-dev/js/src/ds/LifoAlloc.h:
   6,107,862 (2.7%)           js::frontend::ParseNodeVerifier::visit(js::frontend::ParseNode*)
   3,685,203 (1.6%)           js::detail::BumpChunk::setBump(unsigned char*)
   1,640,591 (0.7%)           js::LifoAlloc::alloc(unsigned long)
     711,008 (0.3%)           js::detail::BumpChunk::assertInvariants()
```
And here is a function:file example, which shows how heavy inlining can result
in a machine code function being derived from source code from multiple files:
```
>  1,343,736 (0.6%, 35.6%)  js::gc::TenuredCell::isMarkedGray() const:
     651,108 (0.3%)           /home/njn/moz/gecko-dev/js/src/d64/dist/include/js/HeapAPI.h
     292,672 (0.1%)           /home/njn/moz/gecko-dev/js/src/gc/Cell.h
     254,854 (0.1%)           /home/njn/moz/gecko-dev/js/src/gc/Heap.h
```
Previously these patterns were very hard to find, and it was easy to overlook a
hot piece of code because its counts were spread across multiple non-adjacent
entries. I have already found these changes very useful for profiling Rust
code.

Also, cumulative percentages on the outer CCs (e.g. the 26.3% and 35.6% in the
example) tell you what fraction of all events are covered by the entries so
far, something I've wanted for a long time.

Some other, related changes:
- Column event headers are now padded with `_`, e.g. `Ir__________`. This makes
  the column/event mapping clearer.
- The "Cachegrind profile" section is now called "Metadata", which is
  shorter and clearer.
- A few minor test tweaks, beyond those required for the output changes.
- I converted some doc comments to normal comments. Not standard Python, but
  nicer to read, and there are no public APIs here.
- Roughly 2x speedups to `cg_annotate` and smaller improvements for `cg_diff`
  and `cg_merge`, due to the following.
  - Change the `Cc` class to a type alias for `list[int]`, to avoid the class
    overhead (sigh).
  - Process event count lines in a single split, instead of a regex
    match + split.
  - Add the `add_cc_to_ccs` function, which does multiple CC additions in a
    single function call.
  - Better handling of dicts while reading input, minimizing lookups.
  - Pre-computing the missing CC string for each CcPrinter, instead of
    regenerating it each time.
2023-04-11 09:58:43 +10:00
Nicholas Nethercote
81c7be88b2 Improve pylintrc.
- Move it to `auxprogs/`, alongside `pybuild.sh`.
- Disable the annoying design lints, instead of just modifying the
  values (which often requires modifying them again later).
2023-04-06 09:29:08 +10:00
Nicholas Nethercote
004ba8c0da cg_annotate: Remove support for user-annotated files.
They're of little use, and removing them opens the possibility of adding
`cg_merge`'s profile-merging functionality into `cg_annotate` itself.
2023-04-04 12:12:48 +10:00
Paul Floyd
3c0405a63d Add missing entries to cachegrind EXTRA_DIST 2023-03-31 12:09:45 +02:00
Nicholas Nethercote
2d97182f0d cg_annotate: use <unspecified> for an unspecified filename.
Users shouldn't ever see this, but it's useful to distinguish this
malformed data file case from the missing symbol case (which is still
shown as `???`).
2023-03-29 09:15:56 +11:00
Nicholas Nethercote
6436be0a3f cg_annotate.in: fix a small bug in the printing of past-the-end lines. 2023-03-28 17:22:42 +11:00
Nicholas Nethercote
ca44cbbd7b Fix some problems in cachegrind/tests/Makefile.am. 2023-03-28 16:30:01 +11:00
Nicholas Nethercote
e95328b12c Simpler and more consistent cachegrind/tests/*.vgtest files.
- Always use `python3`, never `python`.
- Avoid unnecessary `../cachegrind/` in paths.
2023-03-28 15:44:34 +11:00
Nicholas Nethercote
551874920f Rewrite cg_merge in Python.
It's currently written in C, but `cg_annotate` and `cg_diff` are written in
Python. It's better to have them all in the same language.

The good news is that the Python code is 4.5x shorter than the C code.
The bad news is that the Python code is roughly 3x slower than the C
code. But `cg_merge` isn't used that often, so I think it's a reasonable
trade-off.
2023-03-28 14:54:27 +11:00
Nicholas Nethercote
8a75eecbad Rewrite cg_diff in Python.
For all the same reasons I rewrote `cg_annotate` in Python.

The commit also moves the Python "build" steps into
`auxprogs/pybuild.sh`, for easy sharing.

Finally, it very slightly tweaks the whitespace in the output of
`cg_annotate`.
2023-03-28 14:54:25 +11:00
Nicholas Nethercote
29d1f00e20 Rename ann-diff test as ann-diff1.
To make room for another test.
2023-03-27 11:03:45 +11:00
Nicholas Nethercote
3f1bbe12fe Make section formatting more consistent.
- Every section now has a heading with the long `----` lines above and
  below.
- Event names are always shown below that heading, rather than within
  it.
- Each Unreadable file now gets its own section, much like files that
  lack any data.
2023-03-27 09:01:38 +11:00
Nicholas Nethercote
d7081e936e Rename a bunch of cg_annotate test files.
For more consistency.
2023-03-27 08:52:28 +11:00
Nicholas Nethercote
179fc84ba7 Add more annotated/unannotated lines at the end.
This way, all CCs are categorised, which is useful for understanding
why thing were/weren't annotated.
2023-03-23 13:20:44 +11:00
Nicholas Nethercote
05d01cd681 Change Threshold: to Thresholds:.
Because all the thresholds other than the first one were always 100, due
to historical reasons.
2023-03-23 13:00:17 +11:00
Nicholas Nethercote
3f8494c8a4 Just use one decimal place for all percentages.
Simpler, shorter, and good enough in practice.
2023-03-23 13:00:17 +11:00
Nicholas Nethercote
b8a90ee968 Improve formatting of percentage columns.
Currently their width is mostly hard-wired in a quick and dirty fashion.
This commit does them properly, so:
- all columns are always the right width, even ones with really large
  percentages
- things like `( 1.00%)` are now `(1.00%)`
- any percentages that would involve a division by zero now show as
  `(n/a)` rather than `( 0.00%)`
2023-03-23 13:00:17 +11:00
Nicholas Nethercote
e9e7b663fb Make cg_annotate work with Python 3.9, by avoiding TypeAlias. 2023-03-23 09:50:21 +11:00
Paul Floyd
bb35cd572f Make cg_annotate independent of python3 install location 2023-03-22 20:43:30 +01:00
Mark Wielaard
3bb907290a cachegrind/tests/Makefile.am EXTRA_DIST add ann3.{{post,stderr}.exp,vgtest} 2023-03-22 11:41:53 +01:00
Nicholas Nethercote
4650b7949a Rewrite cg_annotate in Python.
Perl was a reasonable choice for `cg_annotate` in 2002, but not in 2023.
Also, the existing structure of the code is not good. These two things
make it hard to modify `cg_annotate` in any significant way.

Benefits of the change:
- Now written in a language that is (a) nice, and (b) not moribund.
- Easier to maintain, due to (a) abovementioned better language, (b)
  better code structure, and (c) better language tooling, such as
  formatters, type checkers, and linters.
- The new version is a little shorter.
- It runs about 2x faster.
- Argument handling is more standard. E.g. things like `--context 2`,
  `--auto`, `--no-auto` are supported. (The old forms that require `=`
  are still supported, though the `=yes`/`=no` forms are deprecated.)

The behaviour and output of the new version is identical for typical
uses, but there are some very minor changes for edge cases, which nobody
is likely to notice. For example:
- The file format is slightly changed: I removed support for '.'
  counts, which had the same meaning as '0'. This was a feature that
  Cachegrind never used, and the old script handled it inconsistently.
- The new version will abort on a malformed data line. The old version
  would just print a warning and continue.

The commit also adds a new test `ann3` that tests many parts of
`cg_annotate` that weren't tested previously, and tweaks the existing
`ann2` test.
2023-03-22 10:12:27 +11:00
Mark Wielaard
206dbcfed9 {callgrind,callgrind}/tests/ann{1,2}.vgtest touch cgout-test
Both a.c and cgout-test are checked into the repository and
used in testcases. Make sure cgout-test is newer than a.c
before running the post script to prevent warnings liks:

@@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@ WARNING @@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Source file 'a.c' is more recent than input file
../../cachegrind/tests/cgout-test'.
@ Annotations may not be correct.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2022-10-22 17:31:58 +02:00
Nicholas Nethercote
624fcaa4af Add a test for cg_diff. 2021-12-06 08:56:54 +11:00
Nicholas Nethercote
8e60cde69e Fix cg_annotate warnings when using cg_diff.
When running `cg_annotate` on files produced with `cg_diff`, it's common
to get multiple occurrences of this pair of errors:
```
Use of uninitialized value $pairs[0] in numeric lt (<) at
/home/njn/grind/ws1/cachegrind/cg_annotate line 848.
Use of uninitialized value $high in numeric lt (<) at
/home/njn/grind/ws1/cachegrind/cg_annotate line 859.
```

This is because `cg_annotate` wasn't properly handling the case where no
source code lines have annotations, which never happens in the normal
case but does happen in `cg_diff` output.

Happily, it turns out that the warnings were harmless, the fix is
trivial, and it doesn't change the output at all.
2021-12-06 08:12:34 +11:00
Nicholas Nethercote
1cf2cf91e7 Fix handling of # chars in cg_diff.
Rust v0 symbols can have `#` chars in them, things like this:
```
core::panic::unwind_safe::AssertUnwindSafe<<proc_macro::bridge::server::Dispat
cher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>> as proc_macro::bridge::server::DispatcherTrait>::dispatch::{closure#14}>, ()>
```

`cg_diff` currently messes these up in two ways.
- It treats anything after a `#` in the input file as a comment. In
  comparison, `cg_annotate` only treats a `#` as starting a comment at
  the start of a line.
- It uses `#` to temporarily join file names and function names while
  processing.

This commit adjusts the parsing to fix the first problem, and changes
the joiner sequence to `###` to fix the second problem.
2021-11-30 14:16:39 +11:00
Paul Floyd
e2583c02a5 FreeBSD support, patch 2
Files in the root directory
Several Makefile.am files that have dependencies on FreeBSD autoconf
variables. Included a few new filter files to act as placeholders
to create new freebsd subdirectories.

Updated NEWS with the FreeBSD bugzilla items plus a couple of other
items fixed indirectly.
2021-10-07 08:18:47 +02:00
Mark Wielaard
21ceb09d5d Set refmiscinfo class to version in all manpages.
Otherwise xsltproc will complain while producing the manpage that
it doesn't know how to interpret the release string.
2020-05-14 19:11:26 +02:00
Mark Wielaard
28b8d8b5a1 Turn manpages-index.xml into a "real" book, so it can be validated.
manpages-index.xml is just to easily get at each individual man page
with xsltproc. It wasn't a complete docbookx xml file. Now that it is
we can validate it with xmllint. It doesn't fully validate, but we
are close.
2020-05-14 16:10:27 +02:00
Mark Wielaard
555ddc4753 Use DTD DocBook XML V4.5 everywhere.
This makes the rule for xmllint easier since it doesn't need to
override the DTD to validate against. It also helps with other tools
tryinf to process the docbookx xml files.
2020-05-14 15:12:02 +02:00
Mark Wielaard
c0916494f6 docbook xml doesn't allow xref inside option, use link instead 2020-05-14 12:43:39 +02:00
Mark Wielaard
1922e36228 Don't use similar ids for varlistentry in cg-manual and cl-manual. 2020-05-13 23:40:51 +02:00
Mark Wielaard
168dc79146 cg-manual.xml: Use cg-manual.forkingprograms id, not ms-manual. 2020-05-13 16:50:21 +02:00
Nicholas Nethercote
40ab2f14db Flip the default value of --auto and --show-percs to yes.
In both `cg_annotate` and `callgrind_annotate`.
2020-02-21 09:40:23 +11:00
Petar Jovanovic
24c1f4ada3 mips: Add nanoMIPS support to Valgrind 3/4
Necessary changes to support nanoMIPS on Linux.

Part 3/4 - Coregrind and tools changes

Patch by Aleksandar Rikalo, Dimitrije Nikolic, Tamara Vlahovic,
Nikola Milutinovic and Aleksandra Karadzic.

Related KDE issue: #400872.
2019-12-31 09:44:42 +00:00
Andreas Arnez
7f63a88426 callgrind_annotate, cg_annotate: don't truncate function names at '#'
C++ function names can contain substrings like "{lambda()#1}".  But
callgrind_annotate and cg_annotate interpret the '#'-character as a
comment marker anywhere on each input line, and thus truncate such names
there.

On the other hand, the documentation in docs/cl-format.xml, states:

  Everywhere, comments on own lines starting with '#' are allowed.

This seems to imply that a comment line must start with '#' in the first
column.  Thus skip exactly such lines in the input file and don't handle
'#' as a comment marker anywhere else.

Signed-off-by: Philippe Waroquiers <philippe.waroquiers@skynet.be>
2019-11-03 17:39:36 +01:00
Mark Wielaard
461cc5c003 Cleanup GPL header address notices by using http://www.gnu.org/licenses/
Sync VEX/LICENSE.GPL with top-level COPYING file. We used 3 different
addresses for writing to the FSF to receive a copy of the GPL. Replace
all different variants with an URL <http://www.gnu.org/licenses/>.

The following files might still have some slightly different (L)GPL
copyright notice because they were derived from other programs:

- files under coregrind/m_demangle which come from libiberty:
  cplus-dem.c, d-demangle.c, demangle.h, rust-demangle.c,
  safe-ctype.c and safe-ctype.h
- coregrind/m_demangle/dyn-string.[hc] derived from GCC.
- coregrind/m_demangle/ansidecl.h derived from glibc.
- VEX files for FMA detived from glibc:
  host_generic_maddf.h and host_generic_maddf.c
- files under coregrin/m_debuginfo derived from LZO:
  lzoconf.h, lzodefs.h, minilzo-inl.c and minilzo.h
- files under coregrind/m_gdbserver detived from GDB:
  gdb/signals.h, inferiors.c, regcache.c, regcache.h,
  regdef.h, remote-utils.c, server.c, server.h, signals.c,
  target.c, target.h and utils.c

Plus the following test files:

- none/tests/ppc32/testVMX.c derived from testVMX.
- ppc tests derived from QEMU: jm-insns.c, ppc64_helpers.h
  and test_isa_3_0.c
- tests derived from bzip2 (with embedded GPL text in code):
  hackedbz2.c, origin5-bz2.c, varinfo6.c
- tests detived from glibc: str_tester.c, pth_atfork1.c
- test detived from GCC libgomp: tc17_sembar.c
- performance tests derived from bzip2 or tinycc (with embedded GPL
  text in code): bz2.c, test_input_for_tinycc.c and tinycc.c
2019-05-26 20:07:51 +02:00
Mark Wielaard
08f20ed4af Add missing cachegrind/tests/a.c to EXTRA_DIST.
cachegrind/callgrind fails ann[12] tests because of missing a.c

These testcases fail because the dist tar is missing the a.c
(auto-annotated) source file. Fix by adding it to EXTRA_DIST.

https://bugs.kde.org/show_bug.cgi?id=406352
2019-04-10 17:00:27 +02:00
Nicholas Nethercote
46fb3eb81c Fix path handling in the new Cachegrind and Callgrind tests. 2018-12-12 20:52:33 +11:00
Nicholas Nethercote
e6e8377521 Add a --show-percs option to cg_annotate and callgrind_annotate.
Because it's very useful. As part of this, the "percentage of events
annotated" numbers at the bottom of the output is changed to "events
annotated" so that --show-percs doesn't compute a percentage of a
percentage.

Example output lines:
```
4,967,137,442 (100.0%)  PROGRAM TOTALS

4,543 (25.23%)    17,566 ( 0.43%)    47,993 ( 0.92%) /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c

1 ( 0.01%) 2,000,001 (49.29%) 3,000,004 (57.36%)     for (int i = 0; i < 1000000; i++) {
```

The commit also adds some much-needed tests for cg_annotate and
callgrind_annotate.
2018-12-10 14:14:20 +11:00
Nicholas Nethercote
18d4bf8f0c Fix Cachegrind's --help message. 2018-11-16 16:48:13 +11:00
Petar Jovanovic
fc6c463d57 Introduce RegWord type
On majority of architectures size of long matches register width.
On mips n32 size of long is 32 bits and register width is 64 bits.
Valgrind is written with assumption that long size matches register
width. This is the reason why both UWord for Valgrind and HWord for VEX
match size of long. Long size differs from register size on mips n32 ABI.

Introducing RegWord type that will match size of registers.

Part of the changes required for BZ issue - #345763.

Contributed by:
  Tamara Vlahovic and Dimitrije Nikolic.
2018-04-10 14:09:08 +02:00