{"action":"created","comment":{"url":"https://api.github.com/repos/grpc/grpc/pulls/comments/35936528","id":35936528,"diff_hunk":"@@ -0,0 +1,163 @@\n+#include <grpc/support/sync.h>\n+#include <grpc/support/time.h>\n+#include <stdlib.h>\n+\n+#ifndef ENDOSCOPE_BACKEND_H_\n+#define ENDOSCOPE_BACKEND_H_\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/* Data types */\n+\n+#define ENDO_MUTEX_TYPE gpr_mu\n+#define ENDO_INT64 gpr_int64\n+#define ENDO_INDEX unsigned short\n+#define ENDO_EMPTY (ENDO_INDEX)(-1)\n+\n+/* Public Macros */\n+\n+#define ENDOSCOPE_INIT(base) endoscope_init(base)\n+#define ENDOSCOPE_DESTROY(base) endoscope_destroy(base)\n+#define ENDOSCOPE_BEGIN(base, name) \\\n+        do { \\\n+          ENDO_INT64* temp_ = endoscope_begin(base, name, \\\n+              __FILE__, __LINE__, __PRETTY_FUNCTION__); \\\n+          *temp_ = ENDO_CYCLENOW(); \\\n+        } while (0)\n+#define ENDOSCOPE_END(base, name) endoscope_end(base, name, ENDO_CYCLENOW())\n+#define ENDOSCOPE_EVENT(base, name) endoscope_event(base, name, \\\n+            __FILE__, __LINE__, __PRETTY_FUNCTION__, ENDO_CYCLENOW())\n+#define ENDOSCOPE_ERROR(base, name) endoscope_error(base, name, \\\n+            __FILE__, __LINE__, __PRETTY_FUNCTION__, ENDO_CYCLENOW())\n+\n+/* Private macros */\n+\n+#define ENDO_CYCLENOW() endoscope_cyclenow()\n+#define ENDO_SYNCCLOCK(cycle, time) endoscope_syncclock(cycle, time)\n+#define ENDO_GETTID() endoscope_gettid()\n+#define ENDO_MUTEX_INIT(mu) \\\n+        do { \\\n+          mu = (void *)malloc(sizeof(ENDO_MUTEX_TYPE)); \\\n+          gpr_mu_init((ENDO_MUTEX_TYPE*)(mu)); \\\n+        } while (0)\n+#define ENDO_MUTEX_DESTROY(mu) \\\n+        do { \\\n+          gpr_mu_destroy((ENDO_MUTEX_TYPE*)(mu)); \\\n+          free(mu); \\\n+        } while (0)\n+#define ENDO_LOCK(mu) gpr_mu_lock((ENDO_MUTEX_TYPE*)(mu))\n+#define ENDO_UNLOCK(mu) gpr_mu_unlock((ENDO_MUTEX_TYPE*)(mu))\n+\n+/* Constant Parameters (max capacity 65534) */\n+\n+#define hash_size 97\n+#define marker_capacity 10000\n+#define task_capacity 10000\n+#define atom_capacity 50000\n+#define thread_capacity 100\n+\n+/* Types */\n+\n+typedef struct /* EndoMarker */ {  /* 47/48 marker_id as array index */\n+  ENDO_INT64 cycle_created;  /* overflow after 83 years on 3.5GHz CPU */\n+  ENDO_INT64 timestamp;\n+  const char *name;\n+  const char *file;\n+  const char *function_name;\n+  int line;\n+  ENDO_INDEX next_marker;  /* for hash map collision */\n+  unsigned char type;  /* EndoMarkerPB::MarkerType */\n+} EndoMarker;\n+\n+typedef struct /* EndoTask */ {  /* 32/32 */\n+  ENDO_INT64 cycle_begin;\n+  ENDO_INT64 cycle_end;\n+  unsigned int task_id;\n+  ENDO_INDEX marker_id;\n+  ENDO_INDEX thread_index;\n+  ENDO_INDEX log_head;\n+  ENDO_INDEX log_tail;\n+  ENDO_INDEX next_task;\n+  ENDO_INDEX next_taskwithatom;\n+  unsigned short scope_depth;  /* max depth 65535 */\n+} EndoTask;\n+\n+typedef struct /* EndoAtom */ {  /* 13/16 */\n+  ENDO_INT64 cycle;\n+  ENDO_INDEX param;  /* marker_id if ECOPE_BEGIN/EVENT/ERROR */\n+  ENDO_INDEX next_atom;  /* for both task log and available atoms */\n+  unsigned char type;  /* EndoAtomPB::AtomType */\n+} EndoAtom;\n+\n+typedef struct /* EndoThread */ {  /* 22/24 */\n+  ENDO_INT64 cycle_created;\n+  ENDO_INT64 timestamp;\n+  int thread_id;\n+  ENDO_INDEX task_active;\n+} EndoThread;\n+\n+typedef struct /* EndoBase */ {  /* endoscope instance */\n+  EndoMarker marker_pool[marker_capacity + 1];\n+  ENDO_INDEX marker_count;  /* number of used markers */\n+  ENDO_INDEX marker_map[hash_size];  /* lookup table for used markers */\n+\n+  EndoTask task_pool[task_capacity + 1];","path":"src/core/profiling/endoscope_backend.h","position":106,"original_position":106,"commit_id":"01f7608b9022f51adbf9e402e411eac7f40c8206","original_commit_id":"01f7608b9022f51adbf9e402e411eac7f40c8206","user":{"login":"ctiller","id":10120821,"avatar_url":"https://avatars.githubusercontent.com/u/10120821?v=3","gravatar_id":"","url":"https://api.github.com/users/ctiller","html_url":"https://github.com/ctiller","followers_url":"https://api.github.com/users/ctiller/followers","following_url":"https://api.github.com/users/ctiller/following{/other_user}","gists_url":"https://api.github.com/users/ctiller/gists{/gist_id}","starred_url":"https://api.github.com/users/ctiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctiller/subscriptions","organizations_url":"https://api.github.com/users/ctiller/orgs","repos_url":"https://api.github.com/users/ctiller/repos","events_url":"https://api.github.com/users/ctiller/events{/privacy}","received_events_url":"https://api.github.com/users/ctiller/received_events","type":"User","site_admin":false},"body":"why +1?","created_at":"2015-07-31T00:20:20Z","updated_at":"2015-07-31T00:20:20Z","html_url":"https://github.com/grpc/grpc/pull/2680#discussion_r35936528","pull_request_url":"https://api.github.com/repos/grpc/grpc/pulls/2680","_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc/pulls/comments/35936528"},"html":{"href":"https://github.com/grpc/grpc/pull/2680#discussion_r35936528"},"pull_request":{"href":"https://api.github.com/repos/grpc/grpc/pulls/2680"}}},"pull_request":{"url":"https://api.github.com/repos/grpc/grpc/pulls/2680","id":40959411,"html_url":"https://github.com/grpc/grpc/pull/2680","diff_url":"https://github.com/grpc/grpc/pull/2680.diff","patch_url":"https://github.com/grpc/grpc/pull/2680.patch","issue_url":"https://api.github.com/repos/grpc/grpc/issues/2680","number":2680,"state":"open","locked":false,"title":"DO NOT MERGE Experimental Endoscope Profiling","user":{"login":"zayoo","id":7341718,"avatar_url":"https://avatars.githubusercontent.com/u/7341718?v=3","gravatar_id":"","url":"https://api.github.com/users/zayoo","html_url":"https://github.com/zayoo","followers_url":"https://api.github.com/users/zayoo/followers","following_url":"https://api.github.com/users/zayoo/following{/other_user}","gists_url":"https://api.github.com/users/zayoo/gists{/gist_id}","starred_url":"https://api.github.com/users/zayoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zayoo/subscriptions","organizations_url":"https://api.github.com/users/zayoo/orgs","repos_url":"https://api.github.com/users/zayoo/repos","events_url":"https://api.github.com/users/zayoo/events{/privacy}","received_events_url":"https://api.github.com/users/zayoo/received_events","type":"User","site_admin":false},"body":"TL;DR\r\nFor experimental discussion only.","created_at":"2015-07-27T23:01:32Z","updated_at":"2015-07-31T00:20:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49f6e52aca7d8d39efe812ceda5f079e32cd0d77","assignee":{"login":"yang-g","id":10122250,"avatar_url":"https://avatars.githubusercontent.com/u/10122250?v=3","gravatar_id":"","url":"https://api.github.com/users/yang-g","html_url":"https://github.com/yang-g","followers_url":"https://api.github.com/users/yang-g/followers","following_url":"https://api.github.com/users/yang-g/following{/other_user}","gists_url":"https://api.github.com/users/yang-g/gists{/gist_id}","starred_url":"https://api.github.com/users/yang-g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yang-g/subscriptions","organizations_url":"https://api.github.com/users/yang-g/orgs","repos_url":"https://api.github.com/users/yang-g/repos","events_url":"https://api.github.com/users/yang-g/events{/privacy}","received_events_url":"https://api.github.com/users/yang-g/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/grpc/grpc/pulls/2680/commits","review_comments_url":"https://api.github.com/repos/grpc/grpc/pulls/2680/comments","review_comment_url":"https://api.github.com/repos/grpc/grpc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grpc/grpc/issues/2680/comments","statuses_url":"https://api.github.com/repos/grpc/grpc/statuses/01f7608b9022f51adbf9e402e411eac7f40c8206","head":{"label":"zayoo:master","ref":"master","sha":"01f7608b9022f51adbf9e402e411eac7f40c8206","user":{"login":"zayoo","id":7341718,"avatar_url":"https://avatars.githubusercontent.com/u/7341718?v=3","gravatar_id":"","url":"https://api.github.com/users/zayoo","html_url":"https://github.com/zayoo","followers_url":"https://api.github.com/users/zayoo/followers","following_url":"https://api.github.com/users/zayoo/following{/other_user}","gists_url":"https://api.github.com/users/zayoo/gists{/gist_id}","starred_url":"https://api.github.com/users/zayoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zayoo/subscriptions","organizations_url":"https://api.github.com/users/zayoo/orgs","repos_url":"https://api.github.com/users/zayoo/repos","events_url":"https://api.github.com/users/zayoo/events{/privacy}","received_events_url":"https://api.github.com/users/zayoo/received_events","type":"User","site_admin":false},"repo":{"id":39795910,"name":"grpc","full_name":"zayoo/grpc","owner":{"login":"zayoo","id":7341718,"avatar_url":"https://avatars.githubusercontent.com/u/7341718?v=3","gravatar_id":"","url":"https://api.github.com/users/zayoo","html_url":"https://github.com/zayoo","followers_url":"https://api.github.com/users/zayoo/followers","following_url":"https://api.github.com/users/zayoo/following{/other_user}","gists_url":"https://api.github.com/users/zayoo/gists{/gist_id}","starred_url":"https://api.github.com/users/zayoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zayoo/subscriptions","organizations_url":"https://api.github.com/users/zayoo/orgs","repos_url":"https://api.github.com/users/zayoo/repos","events_url":"https://api.github.com/users/zayoo/events{/privacy}","received_events_url":"https://api.github.com/users/zayoo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zayoo/grpc","description":"The C based gRPC (C++, Node.js, Python, Ruby, Objective-C, PHP, C#)","fork":true,"url":"https://api.github.com/repos/zayoo/grpc","forks_url":"https://api.github.com/repos/zayoo/grpc/forks","keys_url":"https://api.github.com/repos/zayoo/grpc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zayoo/grpc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zayoo/grpc/teams","hooks_url":"https://api.github.com/repos/zayoo/grpc/hooks","issue_events_url":"https://api.github.com/repos/zayoo/grpc/issues/events{/number}","events_url":"https://api.github.com/repos/zayoo/grpc/events","assignees_url":"https://api.github.com/repos/zayoo/grpc/assignees{/user}","branches_url":"https://api.github.com/repos/zayoo/grpc/branches{/branch}","tags_url":"https://api.github.com/repos/zayoo/grpc/tags","blobs_url":"https://api.github.com/repos/zayoo/grpc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zayoo/grpc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zayoo/grpc/git/refs{/sha}","trees_url":"https://api.github.com/repos/zayoo/grpc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zayoo/grpc/statuses/{sha}","languages_url":"https://api.github.com/repos/zayoo/grpc/languages","stargazers_url":"https://api.github.com/repos/zayoo/grpc/stargazers","contributors_url":"https://api.github.com/repos/zayoo/grpc/contributors","subscribers_url":"https://api.github.com/repos/zayoo/grpc/subscribers","subscription_url":"https://api.github.com/repos/zayoo/grpc/subscription","commits_url":"https://api.github.com/repos/zayoo/grpc/commits{/sha}","git_commits_url":"https://api.github.com/repos/zayoo/grpc/git/commits{/sha}","comments_url":"https://api.github.com/repos/zayoo/grpc/comments{/number}","issue_comment_url":"https://api.github.com/repos/zayoo/grpc/issues/comments{/number}","contents_url":"https://api.github.com/repos/zayoo/grpc/contents/{+path}","compare_url":"https://api.github.com/repos/zayoo/grpc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zayoo/grpc/merges","archive_url":"https://api.github.com/repos/zayoo/grpc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zayoo/grpc/downloads","issues_url":"https://api.github.com/repos/zayoo/grpc/issues{/number}","pulls_url":"https://api.github.com/repos/zayoo/grpc/pulls{/number}","milestones_url":"https://api.github.com/repos/zayoo/grpc/milestones{/number}","notifications_url":"https://api.github.com/repos/zayoo/grpc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zayoo/grpc/labels{/name}","releases_url":"https://api.github.com/repos/zayoo/grpc/releases{/id}","created_at":"2015-07-27T20:19:26Z","updated_at":"2015-07-27T20:19:30Z","pushed_at":"2015-07-30T22:10:10Z","git_url":"git://github.com/zayoo/grpc.git","ssh_url":"git@github.com:zayoo/grpc.git","clone_url":"https://github.com/zayoo/grpc.git","svn_url":"https://github.com/zayoo/grpc","homepage":"","size":38490,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"grpc:master","ref":"master","sha":"772fb1e9772373f6fa8b815860da222b3e9c8b42","user":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"repo":{"id":27729880,"name":"grpc","full_name":"grpc/grpc","owner":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grpc/grpc","description":"The C based gRPC (C++, Node.js, Python, Ruby, Objective-C, PHP, C#)","fork":false,"url":"https://api.github.com/repos/grpc/grpc","forks_url":"https://api.github.com/repos/grpc/grpc/forks","keys_url":"https://api.github.com/repos/grpc/grpc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grpc/grpc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grpc/grpc/teams","hooks_url":"https://api.github.com/repos/grpc/grpc/hooks","issue_events_url":"https://api.github.com/repos/grpc/grpc/issues/events{/number}","events_url":"https://api.github.com/repos/grpc/grpc/events","assignees_url":"https://api.github.com/repos/grpc/grpc/assignees{/user}","branches_url":"https://api.github.com/repos/grpc/grpc/branches{/branch}","tags_url":"https://api.github.com/repos/grpc/grpc/tags","blobs_url":"https://api.github.com/repos/grpc/grpc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grpc/grpc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grpc/grpc/git/refs{/sha}","trees_url":"https://api.github.com/repos/grpc/grpc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grpc/grpc/statuses/{sha}","languages_url":"https://api.github.com/repos/grpc/grpc/languages","stargazers_url":"https://api.github.com/repos/grpc/grpc/stargazers","contributors_url":"https://api.github.com/repos/grpc/grpc/contributors","subscribers_url":"https://api.github.com/repos/grpc/grpc/subscribers","subscription_url":"https://api.github.com/repos/grpc/grpc/subscription","commits_url":"https://api.github.com/repos/grpc/grpc/commits{/sha}","git_commits_url":"https://api.github.com/repos/grpc/grpc/git/commits{/sha}","comments_url":"https://api.github.com/repos/grpc/grpc/comments{/number}","issue_comment_url":"https://api.github.com/repos/grpc/grpc/issues/comments{/number}","contents_url":"https://api.github.com/repos/grpc/grpc/contents/{+path}","compare_url":"https://api.github.com/repos/grpc/grpc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grpc/grpc/merges","archive_url":"https://api.github.com/repos/grpc/grpc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grpc/grpc/downloads","issues_url":"https://api.github.com/repos/grpc/grpc/issues{/number}","pulls_url":"https://api.github.com/repos/grpc/grpc/pulls{/number}","milestones_url":"https://api.github.com/repos/grpc/grpc/milestones{/number}","notifications_url":"https://api.github.com/repos/grpc/grpc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grpc/grpc/labels{/name}","releases_url":"https://api.github.com/repos/grpc/grpc/releases{/id}","created_at":"2014-12-08T18:58:53Z","updated_at":"2015-07-30T23:14:54Z","pushed_at":"2015-07-31T00:15:51Z","git_url":"git://github.com/grpc/grpc.git","ssh_url":"git@github.com:grpc/grpc.git","clone_url":"https://github.com/grpc/grpc.git","svn_url":"https://github.com/grpc/grpc","homepage":"","size":152132,"stargazers_count":2953,"watchers_count":2953,"language":"C","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":429,"mirror_url":null,"open_issues_count":428,"forks":429,"open_issues":428,"watchers":2953,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc/pulls/2680"},"html":{"href":"https://github.com/grpc/grpc/pull/2680"},"issue":{"href":"https://api.github.com/repos/grpc/grpc/issues/2680"},"comments":{"href":"https://api.github.com/repos/grpc/grpc/issues/2680/comments"},"review_comments":{"href":"https://api.github.com/repos/grpc/grpc/pulls/2680/comments"},"review_comment":{"href":"https://api.github.com/repos/grpc/grpc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grpc/grpc/pulls/2680/commits"},"statuses":{"href":"https://api.github.com/repos/grpc/grpc/statuses/01f7608b9022f51adbf9e402e411eac7f40c8206"}}}}