iai_callgrind/client_requests/
dhat.rs

1// Copyright (C) 2020 Nicholas Nethercote.  All rights reserved.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions
5// are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
8//    and the following disclaimer.
9//
10// 2. The origin of this software must not be misrepresented; you must not claim that you wrote the
11//    original software.  If you use this software in a product, an acknowledgment in the product
12//    documentation would be appreciated but is not required.
13//
14// 3. Altered source versions must be plainly marked as such, and must not be misrepresented as
15//    being the original software.
16//
17// 4. The name of the author may not be used to endorse or promote products derived from this
18//    software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//
32// ----------------------------------------------------------------
33//
34// We're using a lot of the original documentation from the `dhat.h` header file with some
35// small adjustments, so above is the original license from `dhat.h` file.
36//
37// This file is distributed under the same License as the rest of `iai-callgrind`.
38//
39// ----------------------------------------------------------------
40//
41//! All client requests from the `dhat.h` header file
42//!
43//! See also the [DHAT documentation](https://valgrind.org/docs/manual/dh-manual.html#dh-manual)
44
45use super::arch::valgrind_do_client_request_stmt;
46use super::{bindings, fatal_error};
47
48/// Record an ad hoc event
49///
50/// If DHAT is invoked with `--mode=ad-hoc`, instead of profiling heap operations (allocations and
51/// deallocations), it profiles calls to this `ad_hoc_event` client request.
52///
53/// The meaning of the `weight` argument will depend on what the event represents, which is up to
54/// the user. If no meaningful `weight` argument exists, just use 1.
55///
56/// See also [Ad hoc profiling](https://valgrind.org/docs/manual/dh-manual.html#dh-manual.ad-hoc-profiling)
57#[inline(always)]
58pub fn ad_hoc_event(weight: usize) {
59    do_client_request!(
60        "dhat::ad_hoc_event",
61        bindings::IC_DHATClientRequest::IC_DHAT_AD_HOC_EVENT,
62        weight,
63        0,
64        0,
65        0,
66        0
67    );
68}
69
70/// For access to count histograms of memory larger than 1k
71///
72/// The size of the blocks that measure and display access counts is limited to 1024 bytes. This is
73/// done to limit the performance overhead and also to keep the size of the generated output
74/// reasonable. However, it is possible to override this limit using this client request. The
75/// use-case for this is to first run DHAT normally, and then identify any large blocks that you
76/// would like to further investigate with access count histograms. The function call should be
77/// placed immediately after the call to the allocator, and use the pointer returned by the
78/// allocator.
79///
80/// See also [Access Counts](https://valgrind.org/docs/manual/dh-manual.html#dh-access-counts)
81#[inline(always)]
82pub fn histogram_memory(addr: *const ()) {
83    do_client_request!(
84        "dhat::histogram_memory",
85        bindings::IC_DHATClientRequest::IC_DHAT_HISTOGRAM_MEMORY,
86        addr as usize,
87        0,
88        0,
89        0,
90        0
91    );
92}