{"id":17311435,"url":"https://github.com/sumerc/pycalltrak","last_synced_at":"2025-03-27T01:26:05.740Z","repository":{"id":66170286,"uuid":"167003662","full_name":"sumerc/pycalltrak","owner":"sumerc","description":"Poor Man's Call Trace Analyzer\u0026Visualizer","archived":false,"fork":false,"pushed_at":"2020-04-11T23:24:03.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T07:16:20.997Z","etag":null,"topics":["algorithms","callgraph","profile","visualizer"],"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/sumerc.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":"2019-01-22T14:00:09.000Z","updated_at":"2023-03-05T07:23:28.000Z","dependencies_parsed_at":"2023-03-17T06:01:02.638Z","dependency_job_id":null,"html_url":"https://github.com/sumerc/pycalltrak","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumerc%2Fpycalltrak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumerc%2Fpycalltrak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumerc%2Fpycalltrak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumerc%2Fpycalltrak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sumerc","download_url":"https://codeload.github.com/sumerc/pycalltrak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245762609,"owners_count":20668110,"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":["algorithms","callgraph","profile","visualizer"],"created_at":"2024-10-15T12:40:36.208Z","updated_at":"2025-03-27T01:26:05.723Z","avatar_url":"https://github.com/sumerc.png","language":"Python","readme":"# pycalltrak\nPoor Man's Call Trace Analyzer\u0026amp;Visualizer\n\nIt is a bit different than normal callgraph outputs. PyCalltrak will output every function call with different arguments. This means if a function is called multiple times with different arguments, then all of those calls will be visible in the callgraph as distinct nodes.\n\nThis project is a *toy project* and used specifically while developing/trying out/playing with different algorithms on various subjects. I used calltrak summary and visualizer(it still outputs ASCII, a GUI backend can be easily written) to find repetitive calls happening throughout the execution flow. It might help on various situations like these where you would have a complex algorithm(possibly recursive) that is called multiple times. pycalltrak might shine in those kind of situations since you can visualize/get summary on what has happened in runtime. \n\nAn example is worth thousand words.\n\nFollowing is a Travelling Salesman Problem Solver using Top-Down Dynamic Programming algorithm:\n```python\nimport sys\nfrom functools import lru_cache\n\nA = [[11, 10, 15, 20, 3, 7, 16, 21], [10, 1, 35, 25, 3, 7, 16, 21],\n     [15, 35, 1, 30, 3, 7, 16, 21], [20, 25, 30, 1, 3, 7, 16, 21],\n     [20, 25, 30, 3, 7, 7, 16, 21], [20, 25, 30, 45, 3, 1, 16, 21],\n     [20, 25, 30, 5, 3, 7, 3, 21], [20, 25, 30, 66, 3, 7, 16, 1]]\nS = frozenset([x for x in range(len(A))]) # use frozenset to make Set hashable for lru_cache\n\n#@lru_cache(maxsize=None)\ndef tsp(x, S):\n    if not len(S):\n        return A[x][0]\n    r = sys.maxsize\n    for y in S:\n        r = min(r, A[x][y] + tsp(y, S - {y}))\n    return r\n\nimport calltrak\ncalltrak.start()\nr = tsp(0, S - {0})\ncalltrak.stop()\nstats = calltrak.get_stats()\nprint(stats.summary())\n#print(stats.to_json())\n```\nIt will output following:\n\n```\n13700 call(s) in total. 13650(99%) recurring call(s).\n```\n\nIf you enable lru_cache decorator which enables memoization on the function and re-run the example:\n```\n449 call(s) in total. 0(0%) recurring call(s).\n```\n\nIf you would like to visualize the call graph at this point, pycalltrak already have outlined the x,y coords needed to print out the stats. If you want to do it in your own way, then you need to traverse the callgraph and decide the topology of the graph yourself. A simple example using a single coordinate to print out a Left-Aligned call graph:\n\n```python\nfor stat in stats:\n    print((f'{\".\" * (stat.y-1)} {stat}'))\n```\n\nThe output will be as following: (used different input than the example above)\n\n```\n16 call(s) in total. 6(37%) recurring call(s).\n tsp(x=0, S=frozenset({1, 2, 3})) -\u003e 80 [0.00s]\n. tsp(x=1, S=frozenset({2, 3})) -\u003e 70 [0.00s]\n. tsp(x=2, S=frozenset({1, 3})) -\u003e 65 [0.00s]\n. tsp(x=3, S=frozenset({1, 2})) -\u003e 75 [0.00s]\n.. tsp(x=2, S=frozenset({3})) -\u003e 50 [0.00s]\n.. tsp(x=3, S=frozenset({2})) -\u003e 45 [0.00s]\n.. tsp(x=1, S=frozenset({3})) -\u003e 45 [0.00s]\n.. tsp(x=3, S=frozenset({1})) -\u003e 35 [0.00s]\n.. tsp(x=1, S=frozenset({2})) -\u003e 50 [0.00s]\n.. tsp(x=2, S=frozenset({1})) -\u003e 45 [0.00s]\n... tsp(x=3, S=frozenset()) -\u003e 20 [0.00s]\n... tsp(x=2, S=frozenset()) -\u003e 15 [0.00s]\n... tsp(x=3, S=frozenset()) -\u003e 20 [0.00s]\n... tsp(x=1, S=frozenset()) -\u003e 10 [0.00s]\n... tsp(x=2, S=frozenset()) -\u003e 15 [0.00s]\n... tsp(x=1, S=frozenset()) -\u003e 10 [0.00s]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumerc%2Fpycalltrak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumerc%2Fpycalltrak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumerc%2Fpycalltrak/lists"}