{"action":"created","comment":{"url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/comments/34360028","id":34360028,"diff_hunk":"@@ -2,11 +2,16 @@ module(...,package.seeall)\n \n local debug = _G.developer_debug\n \n+local shm = require(\"core.shm\")\n local ffi = require(\"ffi\")\n local C = ffi.C\n \n local packet = require(\"core.packet\")\n require(\"core.packet_h\")\n+\n+local counter = require(\"core.counter\")\n+require(\"core.counter_h\")","path":"src/core/link.lua","position":12,"original_position":12,"commit_id":"f43eb8bb578b09e14774dabcd2e753d17488ff45","original_commit_id":"8d0c256f93ffd869a533b4366c6c4df3b403e382","user":{"login":"eugeneia","id":4933566,"avatar_url":"https://avatars.githubusercontent.com/u/4933566?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneia","html_url":"https://github.com/eugeneia","followers_url":"https://api.github.com/users/eugeneia/followers","following_url":"https://api.github.com/users/eugeneia/following{/other_user}","gists_url":"https://api.github.com/users/eugeneia/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneia/subscriptions","organizations_url":"https://api.github.com/users/eugeneia/orgs","repos_url":"https://api.github.com/users/eugeneia/repos","events_url":"https://api.github.com/users/eugeneia/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneia/received_events","type":"User","site_admin":false},"body":"I copied the pattern from the `core.packet_h` require just above. Indeed the requires of both `packet_h` and `counter_h` are redundant. I suggest we fix this in a separate \"style branch\", since we have a **lot** of unnecessary `require` calls (especially to core packages) in most modules.","created_at":"2015-07-10T14:38:28Z","updated_at":"2015-07-10T14:38:28Z","html_url":"https://github.com/SnabbCo/snabbswitch/pull/558#discussion_r34360028","pull_request_url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558","_links":{"self":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/comments/34360028"},"html":{"href":"https://github.com/SnabbCo/snabbswitch/pull/558#discussion_r34360028"},"pull_request":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558"}}},"pull_request":{"url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558","id":39685607,"html_url":"https://github.com/SnabbCo/snabbswitch/pull/558","diff_url":"https://github.com/SnabbCo/snabbswitch/pull/558.diff","patch_url":"https://github.com/SnabbCo/snabbswitch/pull/558.patch","issue_url":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/558","number":558,"state":"open","locked":false,"title":"Add new programs 'top' and 'gc'","user":{"login":"eugeneia","id":4933566,"avatar_url":"https://avatars.githubusercontent.com/u/4933566?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneia","html_url":"https://github.com/eugeneia","followers_url":"https://api.github.com/users/eugeneia/followers","following_url":"https://api.github.com/users/eugeneia/following{/other_user}","gists_url":"https://api.github.com/users/eugeneia/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneia/subscriptions","organizations_url":"https://api.github.com/users/eugeneia/orgs","repos_url":"https://api.github.com/users/eugeneia/repos","events_url":"https://api.github.com/users/eugeneia/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneia/received_events","type":"User","site_admin":false},"body":"This is a clean-slate rebase of the #472 PR. It moves links and statistics counters into the `core.shm` framework and introduces the programs `top` to monitor live statistics and `gc` to clean up Snabb runtime files.\r\n\r\nSummary of changes:\r\n\r\nb2cc0fa\r\n\r\n* Extract `struct counter` to its own header file so it can be easily embedded in other structs.\r\n\r\na3ffff3 9977f24\r\n\r\n* Some minor extensions to `core.counter` and `core.shm`.\r\n\r\n490eae6 874e48b 1c9c26a b351682 6d66741 099d0cf\r\n\r\n* `core.app` implements its statistics counters using `core.counter` and maps them to `/engine/...`. It also has a new `configs` counter that is incremented for every call to `configure`.\r\n\r\n* The counters in`struct link` are now pointers to shm counters. `link.new` now accepts a mandatory `name` argument. When a link is created, it is mapped to `/llinks/<name>` and its counters are created and mapped to `/counters/<name>/<counter>`.\r\n\r\n* The new function `link.free` unmaps and unlinks the link and its counters.\r\n\r\n* The function `link.stats` now returns a fresh table containing the names and values of the link's counters. The counter values are converted to Lua numbers using `tonumber`. All code (mostly tests) that was accessing the `stats` field of links directly now uses `link.stat`. This has the advantage of not having to worry about type conversions, or how to access the counter. A common pitfall of mine was wrong math due to unconverted ulongs, e.g. `100ULL * 0.45 = 0`.\r\n\r\nb38d609\r\n\r\n* Added `gc` program.\r\n\r\n8d0c256\r\n\r\n* Added `top` program.","created_at":"2015-07-10T13:53:00Z","updated_at":"2015-07-10T14:38:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"351dff2ef802c27393d3475cc4bee96dd71ba830","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558/commits","review_comments_url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558/comments","review_comment_url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/558/comments","statuses_url":"https://api.github.com/repos/SnabbCo/snabbswitch/statuses/f43eb8bb578b09e14774dabcd2e753d17488ff45","head":{"label":"eugeneia:snabbtop2","ref":"snabbtop2","sha":"f43eb8bb578b09e14774dabcd2e753d17488ff45","user":{"login":"eugeneia","id":4933566,"avatar_url":"https://avatars.githubusercontent.com/u/4933566?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneia","html_url":"https://github.com/eugeneia","followers_url":"https://api.github.com/users/eugeneia/followers","following_url":"https://api.github.com/users/eugeneia/following{/other_user}","gists_url":"https://api.github.com/users/eugeneia/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneia/subscriptions","organizations_url":"https://api.github.com/users/eugeneia/orgs","repos_url":"https://api.github.com/users/eugeneia/repos","events_url":"https://api.github.com/users/eugeneia/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneia/received_events","type":"User","site_admin":false},"repo":{"id":20404812,"name":"snabbswitch","full_name":"eugeneia/snabbswitch","owner":{"login":"eugeneia","id":4933566,"avatar_url":"https://avatars.githubusercontent.com/u/4933566?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneia","html_url":"https://github.com/eugeneia","followers_url":"https://api.github.com/users/eugeneia/followers","following_url":"https://api.github.com/users/eugeneia/following{/other_user}","gists_url":"https://api.github.com/users/eugeneia/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneia/subscriptions","organizations_url":"https://api.github.com/users/eugeneia/orgs","repos_url":"https://api.github.com/users/eugeneia/repos","events_url":"https://api.github.com/users/eugeneia/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eugeneia/snabbswitch","description":"Snabb Switch: Open source packet processing for ISPs","fork":true,"url":"https://api.github.com/repos/eugeneia/snabbswitch","forks_url":"https://api.github.com/repos/eugeneia/snabbswitch/forks","keys_url":"https://api.github.com/repos/eugeneia/snabbswitch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eugeneia/snabbswitch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eugeneia/snabbswitch/teams","hooks_url":"https://api.github.com/repos/eugeneia/snabbswitch/hooks","issue_events_url":"https://api.github.com/repos/eugeneia/snabbswitch/issues/events{/number}","events_url":"https://api.github.com/repos/eugeneia/snabbswitch/events","assignees_url":"https://api.github.com/repos/eugeneia/snabbswitch/assignees{/user}","branches_url":"https://api.github.com/repos/eugeneia/snabbswitch/branches{/branch}","tags_url":"https://api.github.com/repos/eugeneia/snabbswitch/tags","blobs_url":"https://api.github.com/repos/eugeneia/snabbswitch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eugeneia/snabbswitch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eugeneia/snabbswitch/git/refs{/sha}","trees_url":"https://api.github.com/repos/eugeneia/snabbswitch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eugeneia/snabbswitch/statuses/{sha}","languages_url":"https://api.github.com/repos/eugeneia/snabbswitch/languages","stargazers_url":"https://api.github.com/repos/eugeneia/snabbswitch/stargazers","contributors_url":"https://api.github.com/repos/eugeneia/snabbswitch/contributors","subscribers_url":"https://api.github.com/repos/eugeneia/snabbswitch/subscribers","subscription_url":"https://api.github.com/repos/eugeneia/snabbswitch/subscription","commits_url":"https://api.github.com/repos/eugeneia/snabbswitch/commits{/sha}","git_commits_url":"https://api.github.com/repos/eugeneia/snabbswitch/git/commits{/sha}","comments_url":"https://api.github.com/repos/eugeneia/snabbswitch/comments{/number}","issue_comment_url":"https://api.github.com/repos/eugeneia/snabbswitch/issues/comments{/number}","contents_url":"https://api.github.com/repos/eugeneia/snabbswitch/contents/{+path}","compare_url":"https://api.github.com/repos/eugeneia/snabbswitch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eugeneia/snabbswitch/merges","archive_url":"https://api.github.com/repos/eugeneia/snabbswitch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eugeneia/snabbswitch/downloads","issues_url":"https://api.github.com/repos/eugeneia/snabbswitch/issues{/number}","pulls_url":"https://api.github.com/repos/eugeneia/snabbswitch/pulls{/number}","milestones_url":"https://api.github.com/repos/eugeneia/snabbswitch/milestones{/number}","notifications_url":"https://api.github.com/repos/eugeneia/snabbswitch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eugeneia/snabbswitch/labels{/name}","releases_url":"https://api.github.com/repos/eugeneia/snabbswitch/releases{/id}","created_at":"2014-06-02T13:29:12Z","updated_at":"2015-05-06T12:25:41Z","pushed_at":"2015-07-10T14:27:41Z","git_url":"git://github.com/eugeneia/snabbswitch.git","ssh_url":"git@github.com:eugeneia/snabbswitch.git","clone_url":"https://github.com/eugeneia/snabbswitch.git","svn_url":"https://github.com/eugeneia/snabbswitch","homepage":"","size":5934,"stargazers_count":1,"watchers_count":1,"language":"Lua","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"SnabbCo:next","ref":"next","sha":"95c9eeea9ced1e6e88a926243697db05a1d6097e","user":{"login":"SnabbCo","id":1913310,"avatar_url":"https://avatars.githubusercontent.com/u/1913310?v=3","gravatar_id":"","url":"https://api.github.com/users/SnabbCo","html_url":"https://github.com/SnabbCo","followers_url":"https://api.github.com/users/SnabbCo/followers","following_url":"https://api.github.com/users/SnabbCo/following{/other_user}","gists_url":"https://api.github.com/users/SnabbCo/gists{/gist_id}","starred_url":"https://api.github.com/users/SnabbCo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SnabbCo/subscriptions","organizations_url":"https://api.github.com/users/SnabbCo/orgs","repos_url":"https://api.github.com/users/SnabbCo/repos","events_url":"https://api.github.com/users/SnabbCo/events{/privacy}","received_events_url":"https://api.github.com/users/SnabbCo/received_events","type":"Organization","site_admin":false},"repo":{"id":4857740,"name":"snabbswitch","full_name":"SnabbCo/snabbswitch","owner":{"login":"SnabbCo","id":1913310,"avatar_url":"https://avatars.githubusercontent.com/u/1913310?v=3","gravatar_id":"","url":"https://api.github.com/users/SnabbCo","html_url":"https://github.com/SnabbCo","followers_url":"https://api.github.com/users/SnabbCo/followers","following_url":"https://api.github.com/users/SnabbCo/following{/other_user}","gists_url":"https://api.github.com/users/SnabbCo/gists{/gist_id}","starred_url":"https://api.github.com/users/SnabbCo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SnabbCo/subscriptions","organizations_url":"https://api.github.com/users/SnabbCo/orgs","repos_url":"https://api.github.com/users/SnabbCo/repos","events_url":"https://api.github.com/users/SnabbCo/events{/privacy}","received_events_url":"https://api.github.com/users/SnabbCo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SnabbCo/snabbswitch","description":"Snabb Switch: Simple and fast packet networking","fork":false,"url":"https://api.github.com/repos/SnabbCo/snabbswitch","forks_url":"https://api.github.com/repos/SnabbCo/snabbswitch/forks","keys_url":"https://api.github.com/repos/SnabbCo/snabbswitch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SnabbCo/snabbswitch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SnabbCo/snabbswitch/teams","hooks_url":"https://api.github.com/repos/SnabbCo/snabbswitch/hooks","issue_events_url":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/events{/number}","events_url":"https://api.github.com/repos/SnabbCo/snabbswitch/events","assignees_url":"https://api.github.com/repos/SnabbCo/snabbswitch/assignees{/user}","branches_url":"https://api.github.com/repos/SnabbCo/snabbswitch/branches{/branch}","tags_url":"https://api.github.com/repos/SnabbCo/snabbswitch/tags","blobs_url":"https://api.github.com/repos/SnabbCo/snabbswitch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SnabbCo/snabbswitch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SnabbCo/snabbswitch/git/refs{/sha}","trees_url":"https://api.github.com/repos/SnabbCo/snabbswitch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SnabbCo/snabbswitch/statuses/{sha}","languages_url":"https://api.github.com/repos/SnabbCo/snabbswitch/languages","stargazers_url":"https://api.github.com/repos/SnabbCo/snabbswitch/stargazers","contributors_url":"https://api.github.com/repos/SnabbCo/snabbswitch/contributors","subscribers_url":"https://api.github.com/repos/SnabbCo/snabbswitch/subscribers","subscription_url":"https://api.github.com/repos/SnabbCo/snabbswitch/subscription","commits_url":"https://api.github.com/repos/SnabbCo/snabbswitch/commits{/sha}","git_commits_url":"https://api.github.com/repos/SnabbCo/snabbswitch/git/commits{/sha}","comments_url":"https://api.github.com/repos/SnabbCo/snabbswitch/comments{/number}","issue_comment_url":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/comments{/number}","contents_url":"https://api.github.com/repos/SnabbCo/snabbswitch/contents/{+path}","compare_url":"https://api.github.com/repos/SnabbCo/snabbswitch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SnabbCo/snabbswitch/merges","archive_url":"https://api.github.com/repos/SnabbCo/snabbswitch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SnabbCo/snabbswitch/downloads","issues_url":"https://api.github.com/repos/SnabbCo/snabbswitch/issues{/number}","pulls_url":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls{/number}","milestones_url":"https://api.github.com/repos/SnabbCo/snabbswitch/milestones{/number}","notifications_url":"https://api.github.com/repos/SnabbCo/snabbswitch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SnabbCo/snabbswitch/labels{/name}","releases_url":"https://api.github.com/repos/SnabbCo/snabbswitch/releases{/id}","created_at":"2012-07-02T09:06:38Z","updated_at":"2015-07-09T12:25:37Z","pushed_at":"2015-07-10T14:27:41Z","git_url":"git://github.com/SnabbCo/snabbswitch.git","ssh_url":"git@github.com:SnabbCo/snabbswitch.git","clone_url":"https://github.com/SnabbCo/snabbswitch.git","svn_url":"https://github.com/SnabbCo/snabbswitch","homepage":"","size":8411,"stargazers_count":1012,"watchers_count":1012,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":120,"mirror_url":null,"open_issues_count":21,"forks":120,"open_issues":21,"watchers":1012,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558"},"html":{"href":"https://github.com/SnabbCo/snabbswitch/pull/558"},"issue":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/558"},"comments":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/issues/558/comments"},"review_comments":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558/comments"},"review_comment":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/pulls/558/commits"},"statuses":{"href":"https://api.github.com/repos/SnabbCo/snabbswitch/statuses/f43eb8bb578b09e14774dabcd2e753d17488ff45"}}}}