{"id":35031624,"url":"https://github.com/zcobell/smartstack","last_synced_at":"2025-12-27T07:12:17.579Z","repository":{"id":98138118,"uuid":"249118833","full_name":"zcobell/SmartStack","owner":"zcobell","description":"A simple library for timing and tracing","archived":false,"fork":false,"pushed_at":"2023-02-23T23:12:08.000Z","size":142,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-01-29T08:48:11.840Z","etag":null,"topics":["cxx","fortran","stacktrace","timing","timing-function"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zcobell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-22T05:22:03.000Z","updated_at":"2020-09-30T03:39:48.000Z","dependencies_parsed_at":"2023-09-25T00:40:38.821Z","dependency_job_id":null,"html_url":"https://github.com/zcobell/SmartStack","commit_stats":{"total_commits":39,"total_committers":1,"mean_commits":39.0,"dds":0.0,"last_synced_commit":"cb9da21f80218e5fc7ef374a44d0009ecbed5313"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zcobell/SmartStack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcobell%2FSmartStack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcobell%2FSmartStack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcobell%2FSmartStack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcobell%2FSmartStack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zcobell","download_url":"https://codeload.github.com/zcobell/SmartStack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcobell%2FSmartStack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28075232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cxx","fortran","stacktrace","timing","timing-function"],"created_at":"2025-12-27T07:12:16.481Z","updated_at":"2025-12-27T07:12:17.565Z","avatar_url":"https://github.com/zcobell.png","language":"C++","readme":"# SmartStack\nA simple stack tracing and timing library for C++ and Fortran\n\n[![Build Status](https://travis-ci.com/zcobell/SmartStack.svg?branch=master)](https://travis-ci.com/zcobell/SmartStack)\n[![codecov](https://codecov.io/gh/zcobell/SmartStack/branch/master/graph/badge.svg)](https://codecov.io/gh/zcobell/SmartStack)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/51020adea56f4c04876262d6ce1eb5bd)](https://www.codacy.com/manual/zachary.cobell/SmartStack?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=zcobell/SmartStack\u0026amp;utm_campaign=Badge_Grade)\n\n# Usage\nSmartStack is meant to provide an easy way to generate tracing and timing information from C++ and Fortran code bases with minimal overhead.\n\n## Example Report\nExample report that can be generated. Sorted descending by number of function calls. Reports can be sorted by number of calls, duration, or mean duration in either ascending or descending direction by providing arguments to the reporting functions.\n\n\n|   Rank   | Function Name | [-] Calls   |  [v]  Local Duration  (us) | [-]  Mean Local Duration (us) |  [-] Local + Child Duration (us) | [-] Mean Local + Child Duration (us) |\n|----------|---------------|-------------|----------------------------|-------------------------------|----------------------------------|--------------------------------------|\n|        1 |        Smart2 |           3 |                        922 |                           307 |                              922 |                                  307 |\n|        2 |        Smart1 |           2 |                        724 |                           362 |                             1470 |                                  735 |\n|        3 |          MAIN |           1 |                          9 |                             9 |                             1672 |                                 1672 |\n\n\n\n### Example Tracing\nTracing can be done at any point in the code using the tracing function to generate output like below.\n```\n[Stack MySession]: main --\u003e Smart1\n[Stack MySession]: main --\u003e Smart1 --\u003e Smart2\n[Stack MySession]: main --\u003e Smart1 --\u003e Smart2\n[Stack MySession]: main --\u003e Smart1\n[Stack MySession]: main --\u003e Smart1 --\u003e Smart2\n[Stack MySession]: main --\u003e Smart1 --\u003e Smart2\n[Stack MySession]: main --\u003e Smart2\n```\nEntry and exit tracing can be done by specifying the boolean variable to show the stack at object creation for tracing like below. Note that the option is specific to each function.\n```\n[Stack TestSession]: MAIN --\u003e Smart1: Enter\n[Stack TestSession]: MAIN --\u003e Smart1 --\u003e Smart2: Enter\n[Stack TestSession]: MAIN --\u003e Smart1 --\u003e Smart2: Return\n[Stack TestSession]: MAIN --\u003e Smart1: Return\n[Stack TestSession]: MAIN --\u003e Smart1: Enter\n[Stack TestSession]: MAIN --\u003e Smart1 --\u003e Smart2: Enter\n[Stack TestSession]: MAIN --\u003e Smart1 --\u003e Smart2: Return\n[Stack TestSession]: MAIN --\u003e Smart1: Return\n[Stack TestSession]: MAIN --\u003e Smart2: Enter\n[Stack TestSession]: MAIN --\u003e Smart2: Return\n```\n\n## Benchmarking\nBenchmarking is conducted using the Google Benchmark library. The benchmark looks at toggling the timer for a random function that already exists in the stack, the same function continuously that already exists, and a function that is newly created on a stack. It is expected that the former is the most likely case.\n\nThe relevant tests below are `bench_lookupRandomExistingFunction`, `bench_lookupSameExistingFunction` and `bench_lookupNewFunction`. The random lookup is has a performance of approximately 12.6 million/second for a random function and 14.3 million/second for the same function continuously. Creating a new function has a performance off about 1.6 million/second.\n\nThe below tests are conducted using the GNU compiler version 9.2.1 and Abseil tables enabled.\n```\n2020-03-25 13:56:28\nRunning ./smartstack_benchmark\nRun on (6 X 2304 MHz CPU s)\nCPU Caches:\n  L1 Data 32 KiB (x6)\n  L1 Instruction 32 KiB (x6)\n  L2 Unified 256 KiB (x6)\n  L3 Unified 16384 KiB (x1)\nLoad Average: 0.04, 0.17, 0.24\n----------------------------------------------------------------------------------------------\nBenchmark                                   Time             CPU   Iterations items_per_second\n----------------------------------------------------------------------------------------------\nbench_lookupRandomExistingFunction       79.3 ns         79.3 ns      8106327       12.6049M/s\nbench_lookupSameExistingFunction         69.8 ns         69.8 ns      9615968         14.33M/s\nbench_lookupNewFunction                   602 ns          602 ns      1000000       1.65986M/s\n\n```\n\n## C++\nThe C++ library provides a series of macros so that only minimal code is needed to annotate functions. The code is initialized by beginning a session, and then by using the macros `ADD_SMARTSTACK(\"functionName\")`. When the function goes out of scope, the timer will automatically be stopped.\n\n### Example Usage\n```C++\n\n#include \"smartstack.h\"\n\nvoid function1(){\n  ADD_SMARTSTACK(\"function1\");\n}\nvoid function2(){\n  ADD_SMARTSTACK(\"function2\");\n}\n\nint main(){\n\n  SmartStack::startSession(\"MySession\");\n  ADD_SMARTSTACK(\"main\");\n\n\n  END_SMARTSTACK();\n  SmartStack::printTimingReport();\n\n  return 0;\n}\n\n```\n\n## Fortran\nThe FORTRAN library functions are meant to allow the user to specify a function name at the entry point of their code only. The code will automatically stop counting the function when the created variable goes out of scope.\n\n### Example Usage\n\n```Fortran\nMODULE TESTMODULE\n  USE SMARTSTACKMODULE\n  IMPLICIT NONE\n\n  CONTAINS\n\n  SUBROUTINE MYFUNCTION1()\n    IMPLICIT NONE\n    TYPE(SMARTSTACK) :: STK\n    STK = SMARTSTACK(\"MYFUNCITON1\")\n    STK%INITIALIZE = .TRUE.\n    CALL MYFUNCTION2()\n  END SUBROUTINE MYFUNCTION1\n\n  SUBROUTINE MYFUNCTION2()\n    IMPLICIT NONE\n    TYPE(SMARTSTACK) :: STK\n    STK = SMARTSTACK(\"MYFUNCTION2\")\n    STK%INITIALIZE = .TRUE.\n  END SUBROUTINE MYFUNCTION2\n\nEND MODULE TESTMODULE\n\nPROGRAM TEST\n  USE TESTMODULE\n  USE SMARTSTACKMODULE\n  IMPLICIT NONE\n\n  TYPE(SMARTSTACK) :: STK\n\n  CALL SMARTSTACK_StartSession(\"MYSESSION\")\n\n  STK = SMARTSTACK(\"MAIN\")\n  STK%INITIALIZE = .TRUE.\n\n  CALL MYFUNCTION1()\n  CALL MYFUNCTION1()\n\n  CALL SMARTSTACK_EndSession()\n\n  CALL SMARTSTACK_PrintTimingReport()\n\nEND PROGRAM TEST\n\n```\n\n## Python\nPython will eventually be supported via SWIG wrappers\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcobell%2Fsmartstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzcobell%2Fsmartstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcobell%2Fsmartstack/lists"}