{"id":15906030,"url":"https://github.com/lucacappelletti94/memory_time_tracker","last_synced_at":"2025-04-02T22:42:52.571Z","repository":{"id":56900011,"uuid":"437257102","full_name":"LucaCappelletti94/memory_time_tracker","owner":"LucaCappelletti94","description":"Python tool to track the memory and time requirements of software.","archived":false,"fork":false,"pushed_at":"2022-06-08T12:21:47.000Z","size":91,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T08:51:53.834Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucaCappelletti94.png","metadata":{"files":{"readme":"README.rst","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}},"created_at":"2021-12-11T10:58:22.000Z","updated_at":"2022-09-23T11:34:51.000Z","dependencies_parsed_at":"2022-08-21T02:20:22.441Z","dependency_job_id":null,"html_url":"https://github.com/LucaCappelletti94/memory_time_tracker","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fmemory_time_tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fmemory_time_tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fmemory_time_tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fmemory_time_tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucaCappelletti94","download_url":"https://codeload.github.com/LucaCappelletti94/memory_time_tracker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246905830,"owners_count":20852818,"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","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":[],"created_at":"2024-10-06T13:20:39.548Z","updated_at":"2025-04-02T22:42:52.538Z","avatar_url":"https://github.com/LucaCappelletti94.png","language":"Python","readme":"Memory Time Tracker\n=================================\n|pip| |downloads|\n\nMemory time tracker is a simple python tool to track the memory and time requirements of software across both very brief (milliseconds) and large (days) time and memory requirements through adaptative log resolution.\n\nThe reports are CSV files with two columns, the first one with the time delta and the second one with the required RAM.\n\nTracking upwards to crash\n------------------------------------\nThis package handles gracefully also use cases where the tracked software\ndies because of OOM or generally crashes by adding a ``0,0`` as the last line of the CSV document\nit produces when the execution finishes nominally while adding a ``-1,-1`` when the execution\nfinishes with a detectable exception. When there are crashes not detectable through exceptions,\nsuch as machine freezes because of OOM, kernel panics or other things, neither ``0,0`` nor ``1,1`` are (inevitably) written at the end of the CSV.\n\nTo help distinguish the different possible completion statuses, we have prepared three methods:\n\n* ``has_completed_successfully`` to detect whether the execution has been completed without hiccups.\n* ``has_crashed_gracefully`` to detect crashes that raised \"normal\" exceptions.\n* ``has_crashed_ungracefully`` to detect crashes that did not raise \"normal\" exceptions, such as OOM and core dumps.\n\nSee more below in the Examples section.\n\nRequirements\n----------------------------\nPlease do note that this package makes use of `proc/meminfo \u003chttps://man7.org/linux/man-pages/man5/proc.5.html\u003e`_,\nso it is strictly compatible only with Linux systems.\n\nLike most tracker systems, this one works best if there is a limited amount of noise in the system.\nDo not run other software while running the benchmark, or your results may be skewed.\n\nInstalling package\n----------------------------\nAs usual, to install this package from Pypi, just run:\n\n.. code:: bash\n\n    pip install memory_time_tracker\n\n\nUsage example\n---------------------------\nYou can use this package to track the execution of a given method as follows:\n\n.. code:: python\n\n    from memory_time_tracker import Tracker, has_completed_successfully, has_crashed_gracefully, has_crashed_ungracefully, plot_reports\n    from time import sleep\n    import numpy as np\n\n    def example_function():\n        \"\"\"Small example of function that takes 2 seconds.\"\"\"\n        arrays = []\n        for _ in range(10):\n            arrays.append(np.zeros((10000, 10000)))\n            sleep(0.2)\n\n    def example_function_which_crashes():\n        \"\"\"Small example of function that takes 2 seconds and crashes.\"\"\"\n        arrays = []\n        for _ in range(20):\n            arrays.append(np.zeros((10000, 5000)))\n            sleep(0.1)\n        raise ValueError(\"Argh! I'm crashig!\")\n\n    # The path where we will store the log\n    path1 = \"/tmp/tracker_example.csv\"\n    # The path where we will store the log with the crash\n    path2 = \"/tmp/tracker_example_with_crash.csv\"\n\n    # Create the tracker context\n    with Tracker(path1):\n        example_function()\n\n    # Wait between tracking to allow for memory to free\n    sleep(20)\n\n    # Create the tracker context to handle crashable libraries\n    try:\n        with Tracker(path2, verbose=True):\n            example_function_which_crashes()\n    except Exception:\n        pass\n\n    print(\n        \"Successful: \", has_completed_successfully(path1),\n        \"Crashed gracefully: \", has_crashed_gracefully(path1),\n        \"Crashed ungracefully: \", has_crashed_ungracefully(path1)\n    )\n    # Successful:  True Crashed gracefully:  False Crashed ungracefully:  False\n\n    print(\n        \"Successful: \", has_completed_successfully(path2),\n        \"Crashed gracefully: \", has_crashed_gracefully(path2),\n        \"Crashed ungracefully: \", has_crashed_ungracefully(path2)\n    )\n    # Successful:  False Crashed gracefully:  True Crashed ungracefully:  False  \n\n    plot_reports([path1, path2])\n\n\nYou can `run it on Colab here \u003chttps://colab.research.google.com/drive/17RhQQyP8gmIb1qprQwOVPwut_mZgA01K?usp=sharing\u003e`_.\n\nThe above example should generate a picture such as this one:\n\n.. image:: example.png\n  :width: 400\n  :alt: Alternative text\n\nNote that there is some noise in the RAM and time measurements as it was executed on COLAB.\n\nAuthors and License\n---------------------------\nThis package was developed by `Luca Cappelletti \u003chttps://github.com/LucaCappelletti94\u003e`_ and `Tommaso Fontana \u003chttps://github.com/zommiommy\u003e`_ and is released under `MIT License \u003chttps://github.com/LucaCappelletti94/memory_time_tracker/blob/main/LICENSE\u003e`_.\n\n\n.. |pip| image:: https://badge.fury.io/py/memory-time-tracker.svg\n    :target: https://badge.fury.io/py/memory-time-tracker\n    :alt: Pypi project\n\n.. |downloads| image:: https://pepy.tech/badge/memory-time-tracker\n    :target: https://pepy.tech/badge/memory-time-tracker\n    :alt: Pypi total project downloads ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fmemory_time_tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucacappelletti94%2Fmemory_time_tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fmemory_time_tracker/lists"}