Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Jul 31, 2024. It is now read-only.
/timemoryPublic archive

Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.

License

NotificationsYou must be signed in to change notification settings

NERSC/timemory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is now archived and read-only

Timing + Memory + Hardware Counter Utilities for C / C++ / CUDA / Python

Build StatusBuild statuscodecov

timemory on GitHub (Source code)

timemory General Documentation (ReadTheDocs)

timemory Source Code Documentation (Doxygen)

timemory Testing Dashboard (CDash)

timemory Tutorials

timemory Wiki

GitHubgit clone https://github.com/NERSC/timemory.git
PyPipip install timemory
Spackspack install timemory
conda-forgeconda install -c conda-forge timemory
Conda RecipeConda DownloadsConda VersionConda Platforms

Purpose

The goal of timemory is to create an open-source performance measurement and analyis packagewith modular and reusable components which can be used to adapt to any existing C/C++performance measurement and analysis API and is arbitrarily extendable by users within theirapplication.Timemory is not just another profiling tool, it is a proflingtoolkit which streamlines building customprofiling tools through modularity and then utilizes the toolkit to provides several pre-built tools.

In other words, timemory provides many pre-built tools, libraries, and interfaces but, due to it's modularity,codes can re-use only individual pieces -- such as the classes for measuring different timing intervals, memory usage,and hardware counters -- without the timemory "runtime management".

Building and Installing

Timemory uses a standard CMake installation.Several installation examples can be found in theWiki. See theinstallation documentation for detailed information on the CMake options.

Documentation

The full documentation is available attimemory.readthedocs.io.Detailed source documentation is provided in thedoygensection of the full documentation.Tutorials are available in thegithub.com/NERSC/timemory-tutorials.

Overview

The primary objective of the timemory is the development of a common framework for binding together softwaremonitoring code (i.e. performance analysis, debugging, logging) into a compact and highly-efficient interface.

Timemory arose out of the need for a universal adapator kit for the various APIs provided several existing toolsand a straight-forward and intuitive method for creating new tools. Timemory makes it possible to bundletogether deterministic performance measurements, statistical performancemeasurements (i.e. sampling), debug messages, data logging, and data validation into the same interface forcustom application-specific software monitoring interfaces, easily building tools liketime,netstat, instrumentation profilers, sampling profilers, and writing implementations for MPI-P, MPI-T, OMPT,KokkosP, etc. Furthermore, timemory can forward its markers to several third-party profilers such asLIKWID,Caliper,TAU,gperftools,Perfetto, VTune, Allinea-MAP, CrayPAT, Nsight-Systems, Nsight-Compute, and NVProf.

Timemory provides a front-endC/C++/Fortran APIandPython API which allows arbitrary selectionof 50+ different components from timers to hardware counters to interfaces with third-party tools. This is allbuilt generically from the toolkit API with type-safe bundles of tools such as:component_tuple<wall_clock, papi_vector, nvtx_marker, user_bundle>wherewall_clock is a wall-clock timer,papi_vector is a handle for hardware counters,nvxt_marker creates notations in the NVIDIA CUDA profilers, anduser_bundle is a generic component which downstream users can insert more components into at runtime.

Performance measurement components written with timemory are arbitrarily scalable up to any number of threads andprocesses and fully support intermixing different measurements at different locations within the program -- thisuniquely enables timemory to be deployed to collect performance data at scale in HPC because highly detailed collection canoccur at specific locations within the program where ubiquitous collection would simulatenously degrade performancesignificantly and require a prohibitive amount of memory.

Timemory can be used as a backend to bundle instrumentation and sampling tools together, support serialization to JSON/XML,and provide statistics among other uses. It can also be utilized as a front-end to invokecustom instrumentation and sampling tools. Timemory uses the abstract term "component" for a structurewhich encapsulates some performance analysis operation. The structure might encapsulate functioncalls to another tool, record timestamps for timing, log values provided by the application,provide a operator for replacing a function in the code dynamically, audit the incoming argumentsand/or outgoing return value from function, or just provide stubs which can be overloaded by the linker.

Visualization and Analysis

The native output format of timemory is JSON and text; other output formats such as XML are also supported.The text format is intended to be human readable. The JSON datais intended for analysis and comes in two flavors: hierarchical and flat. Basic plotting capabilities areavailable viatimemory-plotting but users are highly encouraged to usehatchetfor analyzing the heirarchical JSON data in pandas dataframes.Hatchet supportsfiltering, unions, addition, subtractions, output todot and flamegraph formats, and an interactive Jupyter notebook.At present, timemory supports 45+ metric types for analysis in Hatchet.

Categories

There are 4 primary categories in timemory: components, operations, bundlers, and storage. Components providethe specifics of how to perform a particular behavior, operations provide the scaffold for requesting thata component perform an operation in complex scenarios, bundlers group components into a single generic handle,and storage manages data collection over the lifetime of the application. When all four categories are combined,timemory effectively resembles a standard performance analysis tool which passively collects data and providesreports and analysis at the termination of the application. Timemory, however, makes itvery easy to subtractstorage from the equation and, in doing so, transforms timemory into a toolkit for customized data collection.

  1. Components
    • Individual classes which encapsulate one or more measurement, analysis, logging, or third-party library action(s)
    • Any data specific to one instance of performing the action is stored within the instance of the class
    • Any configuration data specific to that type is typically stored within static member functions which return a reference to the configuration data
    • These classes are designed to support direct usage within other tools, libraries, etc.
    • Examples include:
      • tim::component::wall_clock : a simple wall-clock timer
      • tim::component::vtune_profiler : a simple component which turns the VTune Profiler on and off (when VTune is actively profiling application)
      • tim::component::data_tracker_integer : associates an integer values with a label as the application executes (e.g. number of loop iterations used somewhere)
      • tim::component::papi_vector : uses the PAPI library to collect hardware-counters values
      • tim::component::user_bundle : encapsulates an array of components which the user can dynamically manipulate during runtime
  2. Operations
    • Templated classes whose primary purpose is to provide the implementation for performing some action on a component, e.g.tim::operation::start<wall_clock> will attempt to call thestart() member function on awall_clock component instance
    • Default implementations generally have one or two public functions: a constructor and/or a function call operator
      • These generally accept any/all arguments and use SFINAE to determine whether the operation can be performed with or without the given arguments (i.e. doeswall_clock have astore(int) function?store()?)
    • Operations are (generally) not directly utilized by the user and are typically optimized out of the binary
    • Examples include:
      • tim::operation::start : instruct a component to start collection
      • tim::operation::sample : instruct a component to take individual measurement
      • tim::operation::derive : extra data from other components if it is available
  3. Bundlers
    • Provide a generic handle for multiple components
    • Member functions generally accept any/all arguments and use operations classes to correctly to handle differences between different capabilities of the components it is bundling
    • Examples include:
      • tim::auto_tuple
      • tim::component_tuple
      • tim::component_list
      • tim::lightweight_tuple
    • Various flavors provide different implicit behaviors and allocate memory differently
      • auto_tuple starts all components when constructed and stops all components when destructed whereascomponent_tuple requires an explicit start
      • component_tuple allocates all components on the stack and components are "always on" whereascomponent_list allocates components on the heap and thus components can be activated/deactivated at runtime
      • lightweight_tuple does not implicitly perform any expensive actions, such as call-stack tracking in "Storage"
  4. Storage
    • Provides persistent storage for multiple instances of components over the lifetime of a thread in the application
    • Responsible for maintaining the hierarchy and order of component measurements, i.e. call-stack tracking
    • Responsible for combining component data from multiple threads and/or processes and outputting the results

NOTE:tim::lightweight_tuple is the recommended bundle for those seeking to use timemory as a toolkit for implementing custom tools and interfaces

Features

  • C++ Template API
    • Modular and fully-customizable
    • Adheres to C++ standard template library paradigm of "you don't pay for what you don't use"
    • Simplifies and facilitates creation and implementation of performance measurement tools
      • Create your own instrumentation profiler
      • Create your own instrumentation library
      • Create your own sampling profiler
      • Create your own sampling library
      • Create your own execution wrappers
      • Supplement timemory-provided tools with your own custom component(s)
      • Thread-safe data aggregation
      • Aggregate collection over multiple processes (MPI and UPC++ support)
      • Serialization to text, JSON, XML
    • Components are composable with other components
    • Variadic component bundlers which maintain complete type-safety
      • Components can be bundled together into a single handle without abstractions
    • Components can store data in any valid C++ data type
    • Components can return data in any valid C++ data type
  • C / C++ / CUDA / Fortran Library API
    • Straight-forward collection of functions and macros for creating built-in performance analysis to your code
    • Component collection can be arbitrarily inter-mixed
      • E.g. collect "A" and "B" in one region, "A" and "C" in another region
    • Component collection can be dynamically manipulated at runtime
      • E.g. add/remove "A" at any point, on any thread, on any process
  • Python API
    • Decorators and context-managers for functions or regions in code
    • Python function profiling
    • Python line-by-line profiling
    • Every component intimemory-avail is provided as a stand-alone Python class
      • Provide low-overhead measurements for building your own Python profiling tools
  • Python Analysis viapandas
  • Command-line Tools
    • timemory-avail
      • Provides available components, settings, and hardware counters
      • Quick API reference tool
    • timem (UNIX)
      • Extended version of UNIXtime command-line tool that includes additional information on memory usage, context switches, and hardware counters
      • Support collecting hardware counters (Linux-only, requires PAPI)
    • timemory-run (Linux)
      • Dynamic instrumentation profiling tool
      • Supports runtime instrumentation and binary re-writing
    • timemory-nvml
      • Data collection similar tonvidia-smi
    • timemory-python-profiler
      • Python function profiler supporting all timemory components
      • from timemory.profiler import Profile
    • timemory-python-trace
      • Python line-by-line profiler supporting all timemory components
      • from timemory.trace import Trace
    • timemory-python-line-profiler
      • Python line-by-line profiler based online-profiler package
      • Extended to use components: cpu-clock, memory-usage, context-switches, etc. (all components which collect scalar values)
      • from timemory.line_profiler import LineProfiler
  • Instrumentation Libraries

Samples

Various macros are defined for C insource/timemory/compat/timemory_c.handsource/timemory/variadic/macros.hpp. Numerous samples oftheir usage can be found in the examples.

Sample C++ Template API

#include"timemory/timemory.hpp"namespacecomp= tim::component;usingnamespacetim;// specific set of componentsusingspecific_t = component_tuple<comp::wall_clock, comp::cpu_clock>;usinggeneric_t  = component_tuple<comp::user_global_bundle>;intmain(int argc,char** argv){// configure default settingssettings::flat_profile() =true;settings::timing_units() ="msec";// initialize with cmd-linetimemory_init(argc, argv);// add argparse supporttimemory_argparse(&argc, &argv);// create a region "main"specific_t m{"main" };    m.start();    m.stop();// pause and resume collection globallysettings::enabled() =false;specific_t h{"hidden" };    h.start().stop();settings::enabled() =true;// Add peak_rss component to specific_t    mpl::push_back_t<specific_t, comp::peak_rss> wprss{"with peak_rss" };// create region collecting only peak_rss    component_tuple<comp::peak_rss> oprss{"only peak_rss" };// convert component_tuple to a type that starts/stops upon construction/destruction    {        scope::config _scope{};if(true)  _scope += scope::flat{};if(false) _scope += scope::timeline{};convert_t<specific_t, auto_tuple<>> scoped{"scoped start/stop + flat", _scope };// will yield auto_tuple<comp::wall_clock, comp::cpu_clock>    }// configure the generic bundle via set of strings    runtime::configure<comp::user_global_bundle>({"wall_clock","peak_rss" });// configure the generic bundle via set of enumeration ids    runtime::configure<comp::user_global_bundle>({ TIMEMORY_WALL_CLOCK, TIMEMORY_CPU_CLOCK });// configure the generic bundle via component instances    comp::user_global_bundle::configure<comp::page_rss, comp::papi_vector>();generic_t g{"generic", quirk::config<quirk::auto_start>{} };    g.stop();// Output the resultstimemory_finalize();return0;}

Sample C / C++ Library API

#include"timemory/library.h"#include"timemory/timemory.h"intmain(int argc,char** argv){// configure settingsint overwrite       =0;int update_settings =1;// default to flat-profiletimemory_set_environ("TIMEMORY_FLAT_PROFILE","ON", overwrite, update_settings);// force timing units    overwrite =1;timemory_set_environ("TIMEMORY_TIMING_UNITS","msec", overwrite, update_settings);// initialize with cmd-linetimemory_init_library(argc, argv);// check if inited, init with nameif(!timemory_library_is_initialized())timemory_named_init_library("ex-c");// define the default set of componentstimemory_set_default("wall_clock, cpu_clock");// create a region "main"timemory_push_region("main");timemory_pop_region("main");// pause and resume collection globallytimemory_pause();timemory_push_region("hidden");timemory_pop_region("hidden");timemory_resume();// Add/remove component(s) to the current set of componentstimemory_add_components("peak_rss");timemory_remove_components("peak_rss");// get an identifier for a region and end ituint64_t idx =timemory_get_begin_record("indexed");timemory_end_record(idx);// assign an existing identifier for a regiontimemory_begin_record("indexed/2", &idx);timemory_end_record(idx);// create region collecting a specific set of datatimemory_begin_record_enum("enum", &idx, TIMEMORY_PEAK_RSS, TIMEMORY_COMPONENTS_END);timemory_end_record(idx);timemory_begin_record_types("types", &idx,"peak_rss");timemory_end_record(idx);// replace current set of components and then restore previous settimemory_push_components("page_rss");timemory_pop_components();timemory_push_components_enum(2, TIMEMORY_WALL_CLOCK, TIMEMORY_CPU_CLOCK);timemory_pop_components();// Output the resultstimemory_finalize_library();return0;}

Sample Fortran API

program fortran_example    use timemory    use iso_c_binding, only : C_INT64_Timplicit noneinteger(C_INT64_T):: idx    ! initialize with explicit namecall timemory_init_library("ex-fortran")    ! initialize with name extracted from get_command_argument(0, ...)    !call timemory_init_library("")    ! define the default set of componentscall timemory_set_default("wall_clock, cpu_clock")    ! Start region"main"call timemory_push_region("main")    ! Add peak_rssto the current set of componentscall timemory_add_components("peak_rss")    ! Nested region"inner" nested under"main"call timemory_push_region("inner")    ! End the"inner" regioncall timemory_pop_region("inner")    ! remove peak_rsscall timemory_remove_components("peak_rss")    ! begin a region and get an identifier    idx= timemory_get_begin_record("indexed")    ! replace current set of componentscall timemory_push_components("page_rss")    ! Nested region"inner" with only page_rss componentscall timemory_push_region("inner (pushed)")    !Stop"inner" region with only page_rss componentscall timemory_pop_region("inner (pushed)")    ! restore previous set of componentscall timemory_pop_components()    ! end the"indexed" regioncall timemory_end_record(idx)    ! End"main"call timemory_pop_region("main")    ! Output the resultscall timemory_finalize_library()end program fortran_example

Sample Python API

Decorator

fromtimemory.bundleimportmarker@marker(["cpu_clock","peak_rss"])deffoo():pass

Context Manager

fromtimemory.profilerimportprofiledefbar():withprofile(["wall_clock","cpu_util"]):foo()

Individual Components

fromtimemory.componentimportWallClockdefspam():wc=WallClock("spam")wc.start()bar()wc.stop()data=wc.get()print(data)

Argparse Support

importargparseparser=argparse.ArgumentParser("example")# ...timemory.add_arguments(parser)args=parser.parse_args()

Component Storage

fromtimemory.storageimportWallClockStorage# data for current rankdata=WallClockStorage.get()# combined data on rank zero but all ranks must call itdmp_data=WallClockStorage.dmp_get()

Versioning

Timemory originated as a very simple tool for recording timing and memory measurements (hence the name) in C, C++, and Python and only supportedthree modes prior to the 3.0.0 release: a fixed set of timers, a pair of memory measurements, and the combination of the two.Prior to the 3.0.0 release, timemory was almost completely rewritten from scratch with the sole exceptions of some C/C++ macro, e.g.TIMEMORY_AUTO_TIMER, and some Python decorators and context-manager, e.g.timemory.util.auto_timer, whose behavior wereable to be fully replicated in the new release. Thus, while it may appear that timemory is a mature project at v3.0+, itis essentially still in it's first major release.

Citing timemory

To reference timemory in a publication, please cite the following paper:

  • Madsen, J.R. et al. (2020) Timemory: Modular Performance Analysis for HPC. In: Sadayappan P., Chamberlain B., Juckeland G., Ltaief H. (eds) High Performance Computing. ISC High Performance 2020. Lecture Notes in Computer Science, vol 12151. Springer, Cham

Additional Information

For more information, refer to thedocumentation.

About

Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp