iai_callgrind/lib_bench.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
use std::ffi::OsString;
use derive_more::AsRef;
use iai_callgrind_macros::IntoInner;
use crate::{internal, EntryPoint};
/// The main configuration of a library benchmark.
///
/// See [`LibraryBenchmarkConfig::callgrind_args`] for more details.
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .callgrind_args(["toggle-collect=something"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
#[derive(Debug, Default, IntoInner, AsRef, Clone)]
pub struct LibraryBenchmarkConfig(internal::InternalLibraryBenchmarkConfig);
impl LibraryBenchmarkConfig {
/// Create a new `LibraryBenchmarkConfig` with initial callgrind arguments
///
/// See also [`LibraryBenchmarkConfig::callgrind_args`].
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// # fn main() {
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// main!(
/// config =
/// LibraryBenchmarkConfig::with_callgrind_args(["toggle-collect=something"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
#[deprecated = "Please use with_callgrind_args"]
pub fn with_raw_callgrind_args<I, T>(args: T) -> Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
Self(internal::InternalLibraryBenchmarkConfig {
env_clear: Option::default(),
callgrind_args: internal::InternalRawArgs::from_iter(args),
valgrind_args: internal::InternalRawArgs::default(),
envs: Vec::default(),
flamegraph_config: Option::default(),
regression_config: Option::default(),
tools: internal::InternalTools::default(),
tools_override: Option::default(),
output_format: Option::default(),
entry_point: Option::default(),
})
}
/// Add callgrind arguments to this `LibraryBenchmarkConfig`
///
/// The arguments don't need to start with a flag: `--toggle-collect=some` or
/// `toggle-collect=some` are both understood.
///
/// Not all callgrind arguments are understood by `iai-callgrind` or cause problems in
/// `iai-callgrind` if they would be applied. `iai-callgrind` will issue a warning in such
/// cases. Most of the defaults can be overwritten. The default settings are:
///
/// * `--I1=32768,8,64`
/// * `--D1=32768,8,64`
/// * `--LL=8388608,16,64`
/// * `--cache-sim=yes`
/// * `--toggle-collect=...` (see also [`LibraryBenchmarkConfig::entry_point`])
/// * `--collect-atstart=no`
/// * `--compress-pos=no`
/// * `--compress-strings=no`
///
/// Note that `toggle-collect` is an array and the default [`EntryPoint`] for library benchmarks
/// is the benchmark function.
///
/// See also [Callgrind Command-line
/// Options](https://valgrind.org/docs/manual/cl-manual.html#cl-manual.options)
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// # fn main() {
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .callgrind_args(["toggle-collect=something"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
#[deprecated = "Please use callgrind_args"]
pub fn raw_callgrind_args<I, T>(&mut self, args: T) -> &mut Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
#[allow(deprecated)]
self.raw_callgrind_args_iter(args);
self
}
/// Add elements of an iterator over callgrind arguments to this `LibraryBenchmarkConfig`
///
/// See also [`LibraryBenchmarkConfig::callgrind_args`]
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .raw_callgrind_args_iter(["toggle-collect=something"].iter());
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
#[deprecated = "Please use callgrind_args"]
pub fn raw_callgrind_args_iter<I, T>(&mut self, args: T) -> &mut Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
self.0.callgrind_args.extend_ignore_flag(args);
self
}
/// Create a new `LibraryBenchmarkConfig` with callgrind arguments
///
/// See also [`LibraryBenchmarkConfig::callgrind_args`].
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// # fn main() {
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// main!(
/// config =
/// LibraryBenchmarkConfig::with_callgrind_args(["toggle-collect=something"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn with_callgrind_args<I, T>(args: T) -> Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
Self(internal::InternalLibraryBenchmarkConfig {
callgrind_args: internal::InternalRawArgs::from_iter(args),
..Default::default()
})
}
/// Add callgrind arguments to this `LibraryBenchmarkConfig`
///
/// The arguments don't need to start with a flag: `--toggle-collect=some` or
/// `toggle-collect=some` are both understood.
///
/// Not all callgrind arguments are understood by `iai-callgrind` or cause problems in
/// `iai-callgrind` if they would be applied. `iai-callgrind` will issue a warning in such
/// cases. Most of the defaults can be overwritten. The default settings are:
///
/// * `--I1=32768,8,64`
/// * `--D1=32768,8,64`
/// * `--LL=8388608,16,64`
/// * `--cache-sim=yes`
/// * `--toggle-collect=...` (see also [`LibraryBenchmarkConfig::entry_point`])
/// * `--collect-atstart=no`
/// * `--compress-pos=no`
/// * `--compress-strings=no`
///
/// Note that `toggle-collect` is an array and the default [`EntryPoint`] for library benchmarks
/// is the benchmark function.
///
/// See also [Callgrind Command-line
/// Options](https://valgrind.org/docs/manual/cl-manual.html#cl-manual.options)
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// # fn main() {
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .callgrind_args(["toggle-collect=something"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn callgrind_args<I, T>(&mut self, args: T) -> &mut Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
self.0.callgrind_args.extend_ignore_flag(args);
self
}
/// Pass valgrind arguments to all tools
///
/// Only core [valgrind
/// arguments](https://valgrind.org/docs/manual/manual-core.html#manual-core.options) are
/// allowed.
///
/// These arguments can be overwritten by tool specific arguments for example with
/// [`LibraryBenchmarkConfig::callgrind_args`] or [`crate::Tool::args`].
///
/// # Examples
///
/// Specify `--trace-children=no` for all configured tools (including callgrind):
///
/// ```rust
/// # use iai_callgrind::{library_benchmark_group, library_benchmark};
/// # #[library_benchmark] fn bench_me() {}
/// # library_benchmark_group!(
/// # name = my_group;
/// # benchmarks = bench_me
/// # );
/// use iai_callgrind::{main, LibraryBenchmarkConfig, Tool, ValgrindTool};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .valgrind_args(["--trace-children=no"])
/// .tool(Tool::new(ValgrindTool::DHAT));
/// library_benchmark_groups = my_group
/// );
/// # }
/// ```
///
/// Overwrite the valgrind argument `--num-callers=25` for `DHAT` with `--num-callers=30`:
///
/// ```rust
/// # use iai_callgrind::{library_benchmark_group, library_benchmark};
/// # #[library_benchmark] fn bench_me() {}
/// # library_benchmark_group!(
/// # name = my_group;
/// # benchmarks = bench_me
/// # );
/// use iai_callgrind::{main, LibraryBenchmarkConfig, Tool, ValgrindTool};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .valgrind_args(["--num-callers=25"])
/// .tool(Tool::new(ValgrindTool::DHAT)
/// .args(["--num-callers=30"])
/// );
/// library_benchmark_groups = my_group
/// );
/// # }
/// ```
pub fn valgrind_args<I, T>(&mut self, args: T) -> &mut Self
where
I: AsRef<str>,
T: IntoIterator<Item = I>,
{
self.0.valgrind_args.extend_ignore_flag(args);
self
}
/// Clear the environment variables before running a benchmark (Default: true)
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().env_clear(false);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn env_clear(&mut self, value: bool) -> &mut Self {
self.0.env_clear = Some(value);
self
}
/// Add an environment variables which will be available in library benchmarks
///
/// These environment variables are available independently of the setting of
/// [`LibraryBenchmarkConfig::env_clear`].
///
/// # Examples
///
/// An example for a custom environment variable, available in all benchmarks:
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().env("FOO", "BAR");
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self
where
K: Into<OsString>,
V: Into<OsString>,
{
self.0.envs.push((key.into(), Some(value.into())));
self
}
/// Add multiple environment variables which will be available in library benchmarks
///
/// See also [`LibraryBenchmarkConfig::env`] for more details.
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config =
/// LibraryBenchmarkConfig::default().envs([("MY_CUSTOM_VAR", "SOME_VALUE"), ("FOO", "BAR")]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn envs<K, V, T>(&mut self, envs: T) -> &mut Self
where
K: Into<OsString>,
V: Into<OsString>,
T: IntoIterator<Item = (K, V)>,
{
self.0
.envs
.extend(envs.into_iter().map(|(k, v)| (k.into(), Some(v.into()))));
self
}
/// Specify a pass-through environment variable
///
/// Usually, the environment variables before running a library benchmark are cleared
/// but specifying pass-through variables makes this environment variable available to
/// the benchmark as it actually appeared in the root environment.
///
/// Pass-through environment variables are ignored if they don't exist in the root
/// environment.
///
/// # Examples
///
/// Here, we chose to pass through the original value of the `HOME` variable:
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().pass_through_env("HOME");
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn pass_through_env<K>(&mut self, key: K) -> &mut Self
where
K: Into<OsString>,
{
self.0.envs.push((key.into(), None));
self
}
/// Specify multiple pass-through environment variables
///
/// See also [`LibraryBenchmarkConfig::pass_through_env`].
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().pass_through_envs(["HOME", "USER"]);
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn pass_through_envs<K, T>(&mut self, envs: T) -> &mut Self
where
K: Into<OsString>,
T: IntoIterator<Item = K>,
{
self.0
.envs
.extend(envs.into_iter().map(|k| (k.into(), None)));
self
}
/// Option to produce flamegraphs from callgrind output using the [`crate::FlamegraphConfig`]
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main, FlamegraphConfig};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().flamegraph(FlamegraphConfig::default());
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn flamegraph<T>(&mut self, config: T) -> &mut Self
where
T: Into<internal::InternalFlamegraphConfig>,
{
self.0.flamegraph_config = Some(config.into());
self
}
/// Enable performance regression checks with a [`crate::RegressionConfig`]
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main, RegressionConfig};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default().regression(RegressionConfig::default());
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn regression<T>(&mut self, config: T) -> &mut Self
where
T: Into<internal::InternalRegressionConfig>,
{
self.0.regression_config = Some(config.into());
self
}
/// Add a configuration to run a valgrind [`crate::Tool`] in addition to callgrind
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main, Tool, ValgrindTool};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .tool(Tool::new(ValgrindTool::DHAT));
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn tool<T>(&mut self, tool: T) -> &mut Self
where
T: Into<internal::InternalTool>,
{
self.0.tools.update(tool.into());
self
}
/// Add multiple configurations to run valgrind [`crate::Tool`]s in addition to callgrind
///
/// # Examples
///
/// ```rust
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(name = some_group; benchmarks = some_func);
/// use iai_callgrind::{LibraryBenchmarkConfig, main, Tool, ValgrindTool};
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .tools(
/// [
/// Tool::new(ValgrindTool::DHAT),
/// Tool::new(ValgrindTool::Massif)
/// ]
/// );
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn tools<I, T>(&mut self, tools: T) -> &mut Self
where
I: Into<internal::InternalTool>,
T: IntoIterator<Item = I>,
{
self.0.tools.update_all(tools.into_iter().map(Into::into));
self
}
/// Override previously defined configurations of valgrind [`crate::Tool`]s
///
/// Usually, if specifying [`crate::Tool`] configurations with [`LibraryBenchmarkConfig::tool`]
/// these tools are appended to the configuration of a [`LibraryBenchmarkConfig`] of
/// higher-levels. Specifying a [`crate::Tool`] with this method overrides previously defined
/// configurations.
///
/// Note that [`crate::Tool`]s specified with [`LibraryBenchmarkConfig::tool`] will be ignored,
/// if in the very same `LibraryBenchmarkConfig`, [`crate::Tool`]s are specified by this method
/// (or [`LibraryBenchmarkConfig::tools_override`]).
///
/// # Examples
///
/// The following will run `DHAT` and `Massif` (and the default callgrind) for all benchmarks in
/// `main!` besides for `some_func` which will just run `Memcheck` (and callgrind).
///
/// ```rust
/// use iai_callgrind::{
/// main, library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, Tool, ValgrindTool
/// };
///
/// #[library_benchmark(config = LibraryBenchmarkConfig::default()
/// .tool_override(
/// Tool::new(ValgrindTool::Memcheck)
/// )
/// )]
/// fn some_func() {}
///
/// library_benchmark_group!(
/// name = some_group;
/// benchmarks = some_func
/// );
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .tools(
/// [
/// Tool::new(ValgrindTool::DHAT),
/// Tool::new(ValgrindTool::Massif)
/// ]
/// );
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn tool_override<T>(&mut self, tool: T) -> &mut Self
where
T: Into<internal::InternalTool>,
{
self.0
.tools_override
.get_or_insert(internal::InternalTools::default())
.update(tool.into());
self
}
/// Override previously defined configurations of valgrind [`crate::Tool`]s
///
/// See also [`LibraryBenchmarkConfig::tool_override`].
///
/// # Examples
///
/// The following will run `DHAT` (and the default callgrind) for all benchmarks in
/// `main!` besides for `some_func` which will run `Massif` and `Memcheck` (and callgrind).
///
/// ```rust
/// use iai_callgrind::{
/// main, library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, Tool, ValgrindTool
/// };
///
/// #[library_benchmark(config = LibraryBenchmarkConfig::default()
/// .tools_override([
/// Tool::new(ValgrindTool::Massif),
/// Tool::new(ValgrindTool::Memcheck)
/// ])
/// )]
/// fn some_func() {}
///
/// library_benchmark_group!(
/// name = some_group;
/// benchmarks = some_func
/// );
///
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .tool(
/// Tool::new(ValgrindTool::DHAT),
/// );
/// library_benchmark_groups = some_group
/// );
/// # }
/// ```
pub fn tools_override<I, T>(&mut self, tools: T) -> &mut Self
where
I: Into<internal::InternalTool>,
T: IntoIterator<Item = I>,
{
self.0
.tools_override
.get_or_insert(internal::InternalTools::default())
.update_all(tools.into_iter().map(Into::into));
self
}
/// Set or unset the entry point for a benchmark
///
/// Iai-Callgrind sets the [`--toggle-collect`] argument of callgrind to the benchmark function
/// which we call [`EntryPoint::Default`]. Specifying a `--toggle-collect` argument, sets
/// automatically `--collect-at-start=no`. This ensures that only the metrics from the benchmark
/// itself are collected and not the `setup` or `teardown` or anything before/after the
/// benchmark function.
///
///
/// However, there are cases when the default toggle is not enough [`EntryPoint::Custom`] or in
/// the way [`EntryPoint::None`].
///
/// Setting [`EntryPoint::Custom`] is convenience for disabling the entry point with
/// [`EntryPoint::None`] and setting `--toggle-collect=CUSTOM_ENTRY_POINT` in
/// [`LibraryBenchmarkConfig::callgrind_args`]. [`EntryPoint::Custom`] can be useful if you
/// want to benchmark a private function and only need the function in the benchmark function as
/// access point. [`EntryPoint::Custom`] accepts glob patterns the same way as
/// [`--toggle-collect`] does.
///
/// # Examples
///
/// If you're using callgrind client requests either in the benchmark function itself or in your
/// library, then using [`EntryPoint::None`] is presumably be required. Consider the following
/// example (`DEFAULT_ENTRY_POINT` marks the default entry point):
#[cfg_attr(not(feature = "client_requests_defs"), doc = "```rust,ignore")]
#[cfg_attr(feature = "client_requests_defs", doc = "```rust")]
/// use iai_callgrind::{
/// main, LibraryBenchmarkConfig,library_benchmark, library_benchmark_group
/// };
/// use std::hint::black_box;
///
/// fn to_be_benchmarked() -> u64 {
/// println!("Some info output");
/// iai_callgrind::client_requests::callgrind::start_instrumentation();
/// let result = {
/// // some heavy calculations
/// # 10
/// };
/// iai_callgrind::client_requests::callgrind::stop_instrumentation();
///
/// result
/// }
///
/// #[library_benchmark]
/// fn some_bench() -> u64 { // <-- DEFAULT ENTRY POINT
/// black_box(to_be_benchmarked())
/// }
///
/// library_benchmark_group!(name = some_group; benchmarks = some_bench);
/// # fn main() {
/// main!(library_benchmark_groups = some_group);
/// # }
/// ```
/// In the example above [`EntryPoint::Default`] is active, so the counting of events starts
/// when the `some_bench` function is entered. In `to_be_benchmarked`, the client request
/// `start_instrumentation` does effectively nothing and `stop_instrumentation` will stop the
/// event counting as requested. This is most likely not what you intended. The event counting
/// should start with `start_instrumentation`. To achieve this, you can set [`EntryPoint::None`]
/// which removes the default toggle, but also `--collect-at-start=no`. So, you need to specify
/// `--collect-at-start=no` in [`LibraryBenchmarkConfig::callgrind_args`]. The example would
/// then look like this:
/// ```rust
/// use std::hint::black_box;
///
/// use iai_callgrind::{library_benchmark, EntryPoint, LibraryBenchmarkConfig};
/// # use iai_callgrind::{library_benchmark_group, main};
/// # fn to_be_benchmarked() -> u64 { 10 }
///
/// // ...
///
/// #[library_benchmark(
/// config = LibraryBenchmarkConfig::default()
/// .callgrind_args(["--collect-at-start=no"])
/// .entry_point(EntryPoint::None)
/// )]
/// fn some_bench() -> u64 {
/// black_box(to_be_benchmarked())
/// }
///
/// // ...
///
/// # library_benchmark_group!(name = some_group; benchmarks = some_bench);
/// # fn main() {
/// # main!(library_benchmark_groups = some_group);
/// # }
/// ```
/// [`--toggle-collect`]: https://valgrind.org/docs/manual/cl-manual.html#cl-manual.options
pub fn entry_point<T>(&mut self, entry_point: T) -> &mut Self
where
T: Into<EntryPoint>,
{
self.0.entry_point = Some(entry_point.into());
self
}
/// Configure the [`crate::OutputFormat`] of the terminal output of Iai-Callgrind
///
/// # Examples
///
/// ```rust
/// use iai_callgrind::{main, LibraryBenchmarkConfig, OutputFormat};
/// # use iai_callgrind::{library_benchmark, library_benchmark_group};
/// # #[library_benchmark]
/// # fn some_func() {}
/// # library_benchmark_group!(
/// # name = some_group;
/// # benchmarks = some_func
/// # );
/// # fn main() {
/// main!(
/// config = LibraryBenchmarkConfig::default()
/// .output_format(OutputFormat::default()
/// .truncate_description(Some(200))
/// );
/// library_benchmark_groups = some_group
/// );
/// # }
pub fn output_format<T>(&mut self, output_format: T) -> &mut Self
where
T: Into<internal::InternalOutputFormat>,
{
self.0.output_format = Some(output_format.into());
self
}
}