iai_callgrind/client_requests/
cachegrind.rs

1// Copyright (C) 2023-2023 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 `cachegrind.h` header file with some
35// small adjustments, so above is the original license from `cachegrind.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 `cachegrind.h` header file
42//!
43//! See also [Cachegrind specific client
44//! requests](https://valgrind.org/docs/manual/cg-manual.html#cg-manual.clientrequests)
45
46use super::{bindings, fatal_error, valgrind_do_client_request_stmt};
47
48/// Start Cachegrind instrumentation if not already enabled.
49///
50/// Use this in combination with [`stop_instrumentation`] and `--instr-at-start` to measure only
51/// part of a client program's execution.
52#[inline(always)]
53pub fn start_instrumentation() {
54    do_client_request!(
55        "cachegrind::start_instrumentation",
56        bindings::IC_CachegrindClientRequest::IC_CG_START_INSTRUMENTATION,
57        0,
58        0,
59        0,
60        0,
61        0
62    );
63}
64
65/// Stop Cachegrind instrumentation if not already disabled.
66///
67/// Use this in combination with [`start_instrumentation`] and `--instr-at-start` to measure only
68/// part of a client program's execution.
69#[inline(always)]
70pub fn stop_instrumentation() {
71    do_client_request!(
72        "cachegrind::stop_instrumentation",
73        bindings::IC_CachegrindClientRequest::IC_CG_STOP_INSTRUMENTATION,
74        0,
75        0,
76        0,
77        0,
78        0
79    );
80}