{"id":15056414,"url":"https://github.com/gootik/metronome","last_synced_at":"2025-04-10T04:10:20.775Z","repository":{"id":57525702,"uuid":"102130069","full_name":"gootik/metronome","owner":"gootik","description":"Erlang timing library","archived":false,"fork":false,"pushed_at":"2017-09-05T11:01:53.000Z","size":15,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T05:25:50.974Z","etag":null,"topics":["erlang","instrumentation","metronome","stats","statsd","stopwatch","timer"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","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/gootik.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}},"created_at":"2017-09-01T16:02:00.000Z","updated_at":"2019-01-09T17:45:27.000Z","dependencies_parsed_at":"2022-08-28T17:52:45.256Z","dependency_job_id":null,"html_url":"https://github.com/gootik/metronome","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/gootik%2Fmetronome","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gootik%2Fmetronome/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gootik%2Fmetronome/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gootik%2Fmetronome/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gootik","download_url":"https://codeload.github.com/gootik/metronome/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247707606,"owners_count":20982815,"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":["erlang","instrumentation","metronome","stats","statsd","stopwatch","timer"],"created_at":"2024-09-24T21:51:06.254Z","updated_at":"2025-04-10T04:10:20.744Z","avatar_url":"https://github.com/gootik.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"Metronome [![Hex.pm](https://img.shields.io/hexpm/v/metronome.svg)](https://hex.pm/packages/metronome)\n=====\n\nA simple library to add instrumentation to your Erlang code. This is a more\ndynamic way of doing `timer:tc/3` or even a lazier version of it.\n\nMetronome will measure runtime of parts of your code and calls a method on your\npredefined module with the results. For example, if you compile your code with\n`{d, 'metronome_callback_mod', 'sample_callback'}` and run the following:\n\n```erlang\n-include_lib(\"metronome/include/metronome.hrl\").\n\n?timed(total_sum,\n  begin\n    ?timed(sum_1, First = lists:sum(lists:seq(0, 100))),\n    ?timed(sum_2, Second = lists:sum(lists:seq(0, 100))),\n    _ = First + Second\n  end).\n```\n\nYou will see 3 calls to `sample_callback` module:\n```erlang\nsample_callback:tick(sum_1, Microseconds).\nsample_callback:tick(sum_2, Microseconds).\nsample_callback:tick(total_sum, Microseconds).\n```\nIf you don't want to use the macros or if they are giving you trouble, you can\nalso explicitly add the start/stop points. The above code can be written like below\nwith no difference in execution:\n\n```erlang\n{stopwatch_start, total_sum},\n\n{stopwatch_start, sum_1},\nFirst = lists:sum(lists:seq(0, 100)),\n{stopwatch_stop},\n\n{stopwatch_start, sum_2},\nSecond = lists:sum(lists:seq(0, 100)),\n{stopwatch_stop},\n\n_ = First + Second,\n\n{stopwatch_stop}.\n```\n\n### Usage\n1. Add the package to your rebar.config\n   ```erlang\n   {deps, [\n      {metronome, \"0.0.2\"}\n   ]}.\n   ```\n\n2. Add the parse transform to your rebar.config\n   ```erlang\n   {erl_opts, [\n     {parse_transform, metronome_transform}\n   ]}.\n   ```\n\n3. [Optional] Configure a custom callback module by using overrides:\n   ```erlang\n   {overrides, [\n     {override, metronome, [\n       {erl_opts, [\n         {d, 'metronome_callback_mod', 'my_sample_mod'\n       }]\n     }]}\n   ]}.\n   ```\n\n4. Instrument your code:\n   ```erlang\n   {stopwatch_start, some_name},\n     --- Intensive amount of work ---\n   {stopwatch_stop}.\n   ```\n   or use the included macro:\n\n   ```erlang\n   -include_lib(\"metronome/include/metronome.hrl\").\n\n   ?timed(some_name,\n     --- Intensive amount of work ---\n    ).\n   ```\n### Why\nI really wanted to learn more about parse transforms and also make my own life\neasier. I usually mix this library with [statsderl](https://github.com/lpgauth/statsderl)\nto make things really easy to report timing of different parts of my code.\n\n### Custom callback\nIf you want a customized callback versus the provided one, you have to create a\nmodule that implements the `metronome_callback` behavior. An example using `statsderl`\nwould look like this:\n\n```erlang\n-module(metronome_statsderl).\n\n-behavior(metronome_callback).\n\n-export([\n  tick/2\n]).\n\ntick(Name, Microseconds) -\u003e\n  statsderl:timing(atom_to_list(Name), Microseconds, 1).\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgootik%2Fmetronome","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgootik%2Fmetronome","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgootik%2Fmetronome/lists"}