Skip to content

Commit ec60a3f

Browse files
Arjan van de VenIngo Molnar
authored andcommitted
perf utils: Use a define for the maximum length of a trace event
As per Ingo's review: use a #define rather than an open coded constant for the maximum length of a trace event for storing in the perf.data file. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Cc: fweisbec@gmail.com Cc: peterz@infradead.org Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <20090919133630.10533d3e@infradead.org> [ add a few comments to nearby functions ] Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 151750c commit ec60a3f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/perf/util/header.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
#include "header.h"
88

99
/*
10-
*
10+
* Create new perf.data header attribute:
1111
*/
12-
1312
struct perf_header_attr *perf_header_attr__new(struct perf_counter_attr *attr)
1413
{
1514
struct perf_header_attr *self = malloc(sizeof(*self));
@@ -43,9 +42,8 @@ void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
4342
}
4443

4544
/*
46-
*
45+
* Create new perf.data header:
4746
*/
48-
4947
struct perf_header *perf_header__new(void)
5048
{
5149
struct perf_header *self = malloc(sizeof(*self));
@@ -86,17 +84,19 @@ void perf_header__add_attr(struct perf_header *self,
8684
self->attr[pos] = attr;
8785
}
8886

87+
#define MAX_EVENT_NAME 64
88+
8989
struct perf_trace_event_type {
9090
u64 event_id;
91-
char name[64];
91+
char name[MAX_EVENT_NAME];
9292
};
9393

9494
static int event_count;
9595
static struct perf_trace_event_type *events;
9696

9797
void perf_header__push_event(u64 id, const char *name)
9898
{
99-
if (strlen(name) > 64)
99+
if (strlen(name) > MAX_EVENT_NAME)
100100
printf("Event %s will be truncated\n", name);
101101

102102
if (!events) {
@@ -110,7 +110,7 @@ void perf_header__push_event(u64 id, const char *name)
110110
}
111111
memset(&events[event_count], 0, sizeof(struct perf_trace_event_type));
112112
events[event_count].event_id = id;
113-
strncpy(events[event_count].name, name, 63);
113+
strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1);
114114
event_count++;
115115
}
116116

0 commit comments

Comments
 (0)