{"id":26967329,"url":"https://github.com/andrehora/spotflow","last_synced_at":"2025-04-03T08:50:44.041Z","repository":{"id":61819348,"uuid":"555480545","full_name":"andrehora/spotflow","owner":"andrehora","description":"Runtime analysis for Python programs","archived":false,"fork":false,"pushed_at":"2024-05-22T20:26:45.000Z","size":513,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T14:46:58.501Z","etag":null,"topics":["dynamic-analysis","msr","python","software-engineering","testing"],"latest_commit_sha":null,"homepage":"","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/andrehora.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-21T17:03:29.000Z","updated_at":"2025-01-23T01:26:31.000Z","dependencies_parsed_at":"2024-04-25T19:58:11.837Z","dependency_job_id":null,"html_url":"https://github.com/andrehora/spotflow","commit_stats":{"total_commits":393,"total_committers":3,"mean_commits":131.0,"dds":"0.012722646310432517","last_synced_commit":"d4001b970619328ad26bca15029a29c8339bd0d8"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehora%2Fspotflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehora%2Fspotflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehora%2Fspotflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehora%2Fspotflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrehora","download_url":"https://codeload.github.com/andrehora/spotflow/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246670834,"owners_count":20815047,"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":["dynamic-analysis","msr","python","software-engineering","testing"],"created_at":"2025-04-03T08:50:43.491Z","updated_at":"2025-04-03T08:50:44.022Z","avatar_url":"https://github.com/andrehora.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/andrehora/spotflow/actions/workflows/tests.yml/badge.svg)](https://github.com/andrehora/spotflow/actions/workflows/tests.yml)\n\n# SpotFlow\n\nSpotFlow is a tool to ease the runtime analysis of Python programs.\nWith SpotFlow, you can extract information about executed methods, run lines, argument values, return values, variable states, and thrown exceptions.\n\n## Install\n\n```\npip install spotflow\n```\n\n## Quick examples\n\n### Monitoring a program\n\nA simple code to be monitored in `sample.py`:\n\n```python\n# content of sample.py\ndef absolute(x):\n    if x \u003c 0:\n        x = -x\n    return x\n\nabsolute(-10) # 10\n```\n\nTo run and monitor function `absolute` in `sample.py`:\n```\n$ python -m spotflow -t absolute sample\n```\n\nThe result:\n```\nRunning and monitoring: sample\n====================== Result ======================\nMonitoredProgram\n- methods: 1\n- calls: 1\nMonitoredMethod\n- name: absolute\n- calls: 1\nMethodCall\n- distinct_run_lines: [2, 3, 4]\n- run_lines: [2, 3, 4]\nArgState\n- x: -10\nVarStateHistory\n- x: -10, 10\nReturnState: 10\n```\n\n---\n\nAnother code to be monitored in `sample.py`, with two calls:\n\n```python\n# content of sample.py\ndef sum(iter, start=0):\n    count = start\n    for i in iter:\n        count += i\n    return count\n\nsum([1, 2]) # 3\nsum([1, 2, 3], 1) # 7\n```\n\nTo run and monitor function `sum` in `sample.py`:\n```\n$ python -m spotflow -t sum sample\n```\n\nThe result:\n```\nRunning and monitoring: sample\n====================== Result ======================\nMonitoredProgram\n- methods: 1\n- calls: 2\nMonitoredMethod\n- name: sum\n- calls: 2\nMethodCall\n- distinct_run_lines: [2, 3, 4, 5]\n- run_lines: [2, 3, 4, 3, 4, 3, 5]\nArgState\n- iter: [1, 2]\n- start: 0\nVarStateHistory\n- iter: [1, 2]\n- start: 0\n- count: 0, 1, 3\n- i: 1, 2\nReturnState: 3\nMethodCall\n- distinct_run_lines: [2, 3, 4, 5]\n- run_lines: [2, 3, 4, 3, 4, 3, 4, 3, 5]\nArgState\n- iter: [1, 2, 3]\n- start: 1\nVarStateHistory\n- iter: [1, 2, 3]\n- start: 1\n- count: 1, 2, 4, 7\n- i: 1, 2, 3\nReturnState: 7\n```\n\n### Monitoring a test suite\n\nYou can also monitor tests.\nFor example, to monitor the test suite [`test_gzip`](https://github.com/python/cpython/blob/main/Lib/test/test_gzip.py) of the Python Standard Library:\n\n```\n$ python -m spotflow -t gzip unittest test.test_gzip\n```\n\nMonitoring other tests of the Python Standard Library:\n```\n$ python -m spotflow -t ast unittest test.test_ast\n$ python -m spotflow -t urllib unittest test.test_urlparse\n$ python -m spotflow -t json unittest test.test_json\n$ python -m spotflow -t calendar unittest test.test_calendar\n```\n\n## Usage\n\nSpotFlow can be run from the command-line.\nWe can use SpotFlow to collect data from the execution of Python programs.\nFor example, to run `my_program.py`, we could originally use the following command-line:\n\n```\n# Running a Python program\n$ python -m my_program\n```\n\nThe same program can be run (and monitored) under SpotFlow with following command-line:\n```\n# Running a Python program + SpotFlow\n$ python -m spotflow -t \u003ctarget\u003e my_program\n```\n\nThe argument `-t` represents the target entity to be monitored.\nWe can pass the full name of the target method (in the format `module.Class.method`) or a prefix to monitor multiple methods.\nFor example, we can pass the prefix \n`parser` (to monitor all methods of a specific module), \n`parser.StringParser` (to monitor all methods of a specific class),\nor the full method name (to monitor a single method).\nThe final mandatory argument is the original command-line, which is in this case `my_program`.\n\nIn a similar way, we can use SpotFlow to monitor the execution of test suites.\nFor example, to run a test `testX.py` under SpotFlow, the following change would be needed with the unittest framework:\n\n```\n# Running unittest\n$ python -m unittest testX\n\n# Running unittest + SpotFlow\n$ python -m spotflow -t \u003ctarget\u003e unittest testX\n```\n\n## Monitored entities\n\n- `MonitoredProgram`: This class is a repository of monitored methods, which can be used to access all collected data.\n\n- `MonitoredMethod`: It represents a monitored method (or function). It has method calls and contains static information about the method/function, like name, full name, class name (for methods), file name, LOC, source code, etc.\n\n- `MethodCall`: This class represents a method call that happens at runtime. It includes data about the caller, call stack, and executed lines. A method call also has a call state, which records information like variable and argument states.\n\n- `CallState`: This class holds the state of a method call, with information about argument states (`ArgState`), return states (`ReturnState`), thrown exceptions (`ExceptionState`), and local variable states (`VarStateHistory`).\n\n- `State`: It represents a state at runtime, such as a variable, argument, return, or exception state.\nAll states have information about its runtime value, runtime type, and line number in code.\nIn addition, `VarState` and `ArgState` have information about its name.\n\n- `VarStateHistory`: This class holds all the states of a local variable in a method call. Notice that it is composed of variable states, representing the fact that a variable may change its value and therefore can have multiple states over time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrehora%2Fspotflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrehora%2Fspotflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrehora%2Fspotflow/lists"}