diff options
Diffstat (limited to 'tools/perf/builtin-timechart.c')
| -rw-r--r-- | tools/perf/builtin-timechart.c | 70 | 
1 files changed, 30 insertions, 40 deletions
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 3b75b2e21ea..b1a8a3b841c 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -168,9 +168,8 @@ static struct per_pid *find_create_pid(int pid)  			return cursor;  		cursor = cursor->next;  	} -	cursor = malloc(sizeof(struct per_pid)); +	cursor = zalloc(sizeof(*cursor));  	assert(cursor != NULL); -	memset(cursor, 0, sizeof(struct per_pid));  	cursor->pid = pid;  	cursor->next = all_data;  	all_data = cursor; @@ -195,9 +194,8 @@ static void pid_set_comm(int pid, char *comm)  		}  		c = c->next;  	} -	c = malloc(sizeof(struct per_pidcomm)); +	c = zalloc(sizeof(*c));  	assert(c != NULL); -	memset(c, 0, sizeof(struct per_pidcomm));  	c->comm = strdup(comm);  	p->current = c;  	c->next = p->all; @@ -239,17 +237,15 @@ pid_put_sample(int pid, int type, unsigned int cpu, u64 start, u64 end)  	p = find_create_pid(pid);  	c = p->current;  	if (!c) { -		c = malloc(sizeof(struct per_pidcomm)); +		c = zalloc(sizeof(*c));  		assert(c != NULL); -		memset(c, 0, sizeof(struct per_pidcomm));  		p->current = c;  		c->next = p->all;  		p->all = c;  	} -	sample = malloc(sizeof(struct cpu_sample)); +	sample = zalloc(sizeof(*sample));  	assert(sample != NULL); -	memset(sample, 0, sizeof(struct cpu_sample));  	sample->start_time = start;  	sample->end_time = end;  	sample->type = type; @@ -275,28 +271,28 @@ static int cpus_cstate_state[MAX_CPUS];  static u64 cpus_pstate_start_times[MAX_CPUS];  static u64 cpus_pstate_state[MAX_CPUS]; -static int process_comm_event(struct perf_tool *tool __used, +static int process_comm_event(struct perf_tool *tool __maybe_unused,  			      union perf_event *event, -			      struct perf_sample *sample __used, -			      struct machine *machine __used) +			      struct perf_sample *sample __maybe_unused, +			      struct machine *machine __maybe_unused)  {  	pid_set_comm(event->comm.tid, event->comm.comm);  	return 0;  } -static int process_fork_event(struct perf_tool *tool __used, +static int process_fork_event(struct perf_tool *tool __maybe_unused,  			      union perf_event *event, -			      struct perf_sample *sample __used, -			      struct machine *machine __used) +			      struct perf_sample *sample __maybe_unused, +			      struct machine *machine __maybe_unused)  {  	pid_fork(event->fork.pid, event->fork.ppid, event->fork.time);  	return 0;  } -static int process_exit_event(struct perf_tool *tool __used, +static int process_exit_event(struct perf_tool *tool __maybe_unused,  			      union perf_event *event, -			      struct perf_sample *sample __used, -			      struct machine *machine __used) +			      struct perf_sample *sample __maybe_unused, +			      struct machine *machine __maybe_unused)  {  	pid_exit(event->fork.pid, event->fork.time);  	return 0; @@ -373,11 +369,10 @@ static void c_state_start(int cpu, u64 timestamp, int state)  static void c_state_end(int cpu, u64 timestamp)  { -	struct power_event *pwr; -	pwr = malloc(sizeof(struct power_event)); +	struct power_event *pwr = zalloc(sizeof(*pwr)); +  	if (!pwr)  		return; -	memset(pwr, 0, sizeof(struct power_event));  	pwr->state = cpus_cstate_state[cpu];  	pwr->start_time = cpus_cstate_start_times[cpu]; @@ -392,14 +387,13 @@ static void c_state_end(int cpu, u64 timestamp)  static void p_state_change(int cpu, u64 timestamp, u64 new_freq)  {  	struct power_event *pwr; -	pwr = malloc(sizeof(struct power_event));  	if (new_freq > 8000000) /* detect invalid data */  		return; +	pwr = zalloc(sizeof(*pwr));  	if (!pwr)  		return; -	memset(pwr, 0, sizeof(struct power_event));  	pwr->state = cpus_pstate_state[cpu];  	pwr->start_time = cpus_pstate_start_times[cpu]; @@ -429,15 +423,13 @@ static void p_state_change(int cpu, u64 timestamp, u64 new_freq)  static void  sched_wakeup(int cpu, u64 timestamp, int pid, struct trace_entry *te)  { -	struct wake_event *we;  	struct per_pid *p;  	struct wakeup_entry *wake = (void *)te; +	struct wake_event *we = zalloc(sizeof(*we)); -	we = malloc(sizeof(struct wake_event));  	if (!we)  		return; -	memset(we, 0, sizeof(struct wake_event));  	we->time = timestamp;  	we->waker = pid; @@ -491,11 +483,11 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)  } -static int process_sample_event(struct perf_tool *tool __used, -				union perf_event *event __used, +static int process_sample_event(struct perf_tool *tool __maybe_unused, +				union perf_event *event __maybe_unused,  				struct perf_sample *sample,  				struct perf_evsel *evsel, -				struct machine *machine __used) +				struct machine *machine __maybe_unused)  {  	struct trace_entry *te; @@ -579,13 +571,12 @@ static void end_sample_processing(void)  	struct power_event *pwr;  	for (cpu = 0; cpu <= numcpus; cpu++) { -		pwr = malloc(sizeof(struct power_event)); +		/* C state */ +#if 0 +		pwr = zalloc(sizeof(*pwr));  		if (!pwr)  			return; -		memset(pwr, 0, sizeof(struct power_event)); -		/* C state */ -#if 0  		pwr->state = cpus_cstate_state[cpu];  		pwr->start_time = cpus_cstate_start_times[cpu];  		pwr->end_time = last_time; @@ -597,10 +588,9 @@ static void end_sample_processing(void)  #endif  		/* P state */ -		pwr = malloc(sizeof(struct power_event)); +		pwr = zalloc(sizeof(*pwr));  		if (!pwr)  			return; -		memset(pwr, 0, sizeof(struct power_event));  		pwr->state = cpus_pstate_state[cpu];  		pwr->start_time = cpus_pstate_start_times[cpu]; @@ -830,11 +820,9 @@ static void draw_process_bars(void)  static void add_process_filter(const char *string)  { -	struct process_filter *filt; -	int pid; +	int pid = strtoull(string, NULL, 10); +	struct process_filter *filt = malloc(sizeof(*filt)); -	pid = strtoull(string, NULL, 10); -	filt = malloc(sizeof(struct process_filter));  	if (!filt)  		return; @@ -1081,7 +1069,8 @@ static int __cmd_record(int argc, const char **argv)  }  static int -parse_process(const struct option *opt __used, const char *arg, int __used unset) +parse_process(const struct option *opt __maybe_unused, const char *arg, +	      int __maybe_unused unset)  {  	if (arg)  		add_process_filter(arg); @@ -1106,7 +1095,8 @@ static const struct option options[] = {  }; -int cmd_timechart(int argc, const char **argv, const char *prefix __used) +int cmd_timechart(int argc, const char **argv, +		  const char *prefix __maybe_unused)  {  	argc = parse_options(argc, argv, options, timechart_usage,  			PARSE_OPT_STOP_AT_NON_OPTION);  |