class_docstr: Top level container for Callgrind results collected by Timer.
  
  Manipulation is generally done using the FunctionCounts class, which is
  obtained by calling `CallgrindStats.stats(...)`. Several convenience
  methods are provided as well; the most significant is
  `CallgrindStats.as_standardized()`.
class_docstr_tok: ["Top","level","container","for","Callgrind","results","collected","by","Timer",".","Manipulation","is","generally","done","using","the","FunctionCounts","class",",","which","is","obtained","by","calling","`","CallgrindStats.stats","(","...",")","`",".","Several","convenience","methods","are","provided","as","well",";","the","most","significant","is","`","CallgrindStats.as_standardized","(",")","`","."]
docstr: Strip library names and some prefixes from function strings.
  
  When comparing two different sets of instruction counts, on stumbling
  block can be path prefixes. Callgrind includes the full filepath
  when reporting a function (as it should). However, this can cause
  issues when diffing profiles. If a key component such as Python
  or PyTorch was built in separate locations in the two profiles, which
  can result in something resembling::
  
      23234231 /tmp/first_build_dir/thing.c:foo(...)
       9823794 /tmp/first_build_dir/thing.c:bar(...)
        ...
         53453 .../aten/src/Aten/...:function_that_actually_changed(...)
        ...
       -9823794 /tmp/second_build_dir/thing.c:bar(...)
      -23234231 /tmp/second_build_dir/thing.c:foo(...)
  
  Stripping prefixes can ameliorate this issue by regularizing the
  strings and causing better cancellation of equivalent call sites
  when diffing.
code: def as_standardized(self) -> "CallgrindStats":
      """Strip library names and some prefixes from function strings.
  
      When comparing two different sets of instruction counts, on stumbling
      block can be path prefixes. Callgrind includes the full filepath
      when reporting a function (as it should). However, this can cause
      issues when diffing profiles. If a key component such as Python
      or PyTorch was built in separate locations in the two profiles, which
      can result in something resembling::
  
          23234231 /tmp/first_build_dir/thing.c:foo(...)
           9823794 /tmp/first_build_dir/thing.c:bar(...)
            ...
             53453 .../aten/src/Aten/...:function_that_actually_changed(...)
            ...
           -9823794 /tmp/second_build_dir/thing.c:bar(...)
          -23234231 /tmp/second_build_dir/thing.c:foo(...)
  
      Stripping prefixes can ameliorate this issue by regularizing the
      strings and causing better cancellation of equivalent call sites
      when diffing.
      """
  
      def strip(stats: FunctionCounts) -> FunctionCounts:
          transforms = (
              # PyTorch may have been built in different locations.
              (r"^.+build/\.\./", "build/../"),
              (r"^.+/" + re.escape("build/aten/"), "build/aten/"),
              # "Python" and "Objects" come from CPython.
              (r"^.+/" + re.escape("Python/"), "Python/"),
              (r"^.+/" + re.escape("Objects/"), "Objects/"),
              # Strip library name. e.g. `libtorch.so`
              (r"\s\[.+\]$", ""),
          )
  
          for before, after in transforms:
              stats = stats.transform(
                  lambda fn: re.sub(before, after, fn)
              )
  
          return stats
  
      return CallgrindStats(
          task_spec=self.task_spec,
          number_per_run=self.number_per_run,
          built_with_debug_symbols=self.built_with_debug_symbols,
          baseline_inclusive_stats=strip(self.baseline_inclusive_stats),
          baseline_exclusive_stats=strip(self.baseline_exclusive_stats),
          stmt_inclusive_stats=strip(self.stmt_inclusive_stats),
          stmt_exclusive_stats=strip(self.stmt_exclusive_stats),
          # `as_standardized` will change symbol names, so the contents will
          # no longer map directly to `callgrind.out`
          stmt_callgrind_out=None,
      )
  
imports: import collections
  import enum
  import dataclasses
  import itertools
  import os
  import pickle
  import re
  import shutil
  import subprocess
  import sys
  import textwrap
  from typing import cast, Any, Callable, DefaultDict, Dict, Iterator, List, NamedTuple, Optional, Tuple, Union, TYPE_CHECKING
  import torch
  from torch.utils.benchmark.utils import common, cpp_jit
  from torch.utils.benchmark.utils._stubs import CallgrindModuleType
  import operator
label_desc: Use image node_id 5 for calling the CallgrindStats obj's underlying member method code with example usage: obj.as_standardized() and returns: CallgrindStats, stats