Commit Graph

583 Commits

Author SHA1 Message Date
Petr Pavlu
32fc9cc751 riscv64: Add initial support: Valgrind modifications
The following people contributed to the initial RISC-V support:
Petr Pavlu <petr.pavlu@dagobah.cz>
Xeonacid <h.dwwwwww@gmail.com>
laokz <laokz@foxmail.com>
Chelsea E. Manning <me@xychelsea.is>
zhaomingxin <zhaomingxin.zmx@alibaba-inc.com>
Jojo R <rjiejie@linux.alibaba.com>

https://bugs.kde.org/show_bug.cgi?id=493507
2025-02-25 17:04:36 +01:00
Mark Wielaard
26ebac7b4c Add prereqs for tests using python 3.9+
Adds a script tests/python_test.sh that checks whether there is a python3
binary and that it supports python version 3.9 or higher. Use this script
in the various cachegrind/tests annotate vgtests as prereq.
2024-04-24 21:30:48 +02:00
Mark Wielaard
d216fff966 Update emitted Copyright years to include 2024
Also adjust test exp and filters.
2024-04-20 04:13:04 +02:00
Paul Floyd
6c949b8576 regtest: try to make cachegrind/tests/ann-merge2.vgtest deterministic
Add a touch of the cgout files so that they are more recent than the
source file. git clone seems to sometimes timestamp the source
after the cgout files which generates a warning and a post failure.
At least with FreeBSD on ZFS.
2023-12-28 21:50:06 +01:00
Paul Floyd
cc1aed1ce2 DHAT: only handle own user reqs, ignore others
Make other tools consistent with this as well
(using memcheck as the model). Also refactored
the DRD user req names to make it clearer which
are Valgrind user reqs, which are DRD public
user reqs and which are DRD internal user reqs.
2023-10-09 23:23:03 +02:00
Paul Floyd
0ed244b88f coverity: most of the remaining unsigned comparisons >= 0 warnings 2023-10-08 09:21:12 +02:00
Nicholas Nethercote
a12e480c21 Minor tweaks for Python tooling updates.
Annoying that these are necessary, but that seems to be standard for
this stuff.
2023-10-03 08:44:15 +11:00
Paul Floyd
dc25e4c552 cachegrind: exit with error if line size or associativity is zero
Detected with Coverity
2023-09-30 21:54:21 +02:00
Paul Floyd
36b194bcec coverity: lots of checks that unsigned are >= 0 which is always true
Also put back the isFF flag initialization (used for FreeBSD
non-fixed RO ELF segmentd) . I had intended to delete it but
in the end kept it for traces but had already deleted the init code.
2023-09-29 22:45:32 +02:00
Nicholas Nethercote
f74738b64e Add some client requests to Cachegrind. 2023-09-14 10:51:19 +10:00
Paul Floyd
75321f92b1 Fix various clang warnings
Mostly missing 'void' in function prototypes.
2023-08-25 23:00:58 +02:00
Nicholas Nethercote
e7bfa5a8e9 Update Cachegrind description in the usage message and header comments.
This matches an earlier change to the description in the user manual.

And fix indentation of the license in a couple of files.
2023-08-23 16:16:08 +10:00
Nicholas Nethercote
fd3719c1ed Correct an error in Cachegrind's usage message. 2023-08-23 14:20:42 +10:00
Mark Wielaard
9d6d45cfde Add cachegrind/tests/ann-diff4b-aux/w.rs
Missing testfile from commit 1fdf0e728a
"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