aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-05-23 03:13:40 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-05-23 17:22:47 -0400
commit09fa4f401296f555afb6f2f4282717644d94722e (patch)
tree1221a34bf153698a5a97a9f8fc40d7bbc9909249 /tools/perf
parent2d11c65071d489e20b3a811167507939dd8c2eac (diff)
perf record: Rename variable to make code clear
record__mmap_read() writes data from ring buffer into perf.data. 'head' is maintained by the kernel, points to the last written record. 'old' is maintained by perf, points to the record read in previous round. record__mmap_read() saves data from 'old' to 'head' to perf.data. The names of these variables are not very intutive. In addition, when dealing with backward writing ring buffer, the md->prev pointer should point to 'head' instead of the last byte it got. Add 'start' and 'end' pointer to make code clear and set md->prev to 'head' instead of the moved 'old' pointer. This patch doesn't change behavior since: buf = &data[old & md->mask]; size = head - old; old += size; <--- Here, old == head Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1463987628-163563-4-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang <hekuang@huawei.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-record.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f302cc937ca5..73ce651c84f6 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -88,17 +88,18 @@ static int record__mmap_read(struct record *rec, int idx)
88 struct perf_mmap *md = &rec->evlist->mmap[idx]; 88 struct perf_mmap *md = &rec->evlist->mmap[idx];
89 u64 head = perf_mmap__read_head(md); 89 u64 head = perf_mmap__read_head(md);
90 u64 old = md->prev; 90 u64 old = md->prev;
91 u64 end = head, start = old;
91 unsigned char *data = md->base + page_size; 92 unsigned char *data = md->base + page_size;
92 unsigned long size; 93 unsigned long size;
93 void *buf; 94 void *buf;
94 int rc = 0; 95 int rc = 0;
95 96
96 if (old == head) 97 if (start == end)
97 return 0; 98 return 0;
98 99
99 rec->samples++; 100 rec->samples++;
100 101
101 size = head - old; 102 size = end - start;
102 if (size > (unsigned long)(md->mask) + 1) { 103 if (size > (unsigned long)(md->mask) + 1) {
103 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); 104 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
104 105
@@ -107,10 +108,10 @@ static int record__mmap_read(struct record *rec, int idx)
107 return 0; 108 return 0;
108 } 109 }
109 110
110 if ((old & md->mask) + size != (head & md->mask)) { 111 if ((start & md->mask) + size != (end & md->mask)) {
111 buf = &data[old & md->mask]; 112 buf = &data[start & md->mask];
112 size = md->mask + 1 - (old & md->mask); 113 size = md->mask + 1 - (start & md->mask);
113 old += size; 114 start += size;
114 115
115 if (record__write(rec, buf, size) < 0) { 116 if (record__write(rec, buf, size) < 0) {
116 rc = -1; 117 rc = -1;
@@ -118,16 +119,16 @@ static int record__mmap_read(struct record *rec, int idx)
118 } 119 }
119 } 120 }
120 121
121 buf = &data[old & md->mask]; 122 buf = &data[start & md->mask];
122 size = head - old; 123 size = end - start;
123 old += size; 124 start += size;
124 125
125 if (record__write(rec, buf, size) < 0) { 126 if (record__write(rec, buf, size) < 0) {
126 rc = -1; 127 rc = -1;
127 goto out; 128 goto out;
128 } 129 }
129 130
130 md->prev = old; 131 md->prev = head;
131 perf_evlist__mmap_consume(rec->evlist, idx); 132 perf_evlist__mmap_consume(rec->evlist, idx);
132out: 133out:
133 return rc; 134 return rc;