[RFC,1/7] perf jevents: Add support for an extra directory level
diff mbox series

Message ID 1579876505-113251-2-git-send-email-john.garry@huawei.com
State New
Headers show
Series
  • perf pmu-events: Support event aliasing for system PMUs
Related show

Commit Message

John Garry Jan. 24, 2020, 2:34 p.m. UTC
Currently we support upto a level 2 directory, and level 2 would be in the
form vendor/platform.

Add support for a further level, to hold specific categories of events for
when we want to segregate them for matching purposes.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 tools/perf/pmu-events/jevents.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Jiri Olsa Feb. 10, 2020, 12:07 p.m. UTC | #1
On Fri, Jan 24, 2020 at 10:34:59PM +0800, John Garry wrote:
> Currently we support upto a level 2 directory, and level 2 would be in the
> form vendor/platform.
> 
> Add support for a further level, to hold specific categories of events for
> when we want to segregate them for matching purposes.
> 
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
>  tools/perf/pmu-events/jevents.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
> index 079c77b6a2fd..8af05b94a37d 100644
> --- a/tools/perf/pmu-events/jevents.c
> +++ b/tools/perf/pmu-events/jevents.c
> @@ -960,15 +960,20 @@ static int process_one_file(const char *fpath, const struct stat *sb,
>  	int level   = ftwbuf->level;
>  	int err = 0;
>  
> -	if (level == 2 && is_dir) {
> +	if (level >= 2 && is_dir) {
> +		int count = 0;
>  		/*
>  		 * For level 2 directory, bname will include parent name,
>  		 * like vendor/platform. So search back from platform dir
>  		 * to find this.
> +		 * Something similar for level 3 directory, but we're a PMU
> +		 * category folder, like vendor/platform/cpu.
>  		 */
>  		bname = (char *) fpath + ftwbuf->base - 2;
>  		for (;;) {
>  			if (*bname == '/')
> +				count++;
> +			if (count == level - 1)
>  				break;
>  			bname--;

I was wondering why we just don't use different filename for that,
but it's true that the code transforms directory chain to the table
name.. so I guess another directory level is justified ;-)

jirka


>  		}
> @@ -981,13 +986,13 @@ static int process_one_file(const char *fpath, const struct stat *sb,
>  		 level, sb->st_size, bname, fpath);
>  
>  	/* base dir or too deep */
> -	if (level == 0 || level > 3)
> +	if (level == 0 || level > 4)
>  		return 0;
>  
>  
>  	/* model directory, reset topic */
>  	if ((level == 1 && is_dir && is_leaf_dir(fpath)) ||
> -	    (level == 2 && is_dir)) {
> +	    (level >= 2 && is_dir && is_leaf_dir(fpath))) {
>  		if (close_table)
>  			print_events_table_suffix(eventsfp);
>  
> -- 
> 2.17.1
>
John Garry Feb. 10, 2020, 3:47 p.m. UTC | #2
On 10/02/2020 12:07, Jiri Olsa wrote:
> On Fri, Jan 24, 2020 at 10:34:59PM +0800, John Garry wrote:
>> Currently we support upto a level 2 directory, and level 2 would be in the
>> form vendor/platform.
>>
>> Add support for a further level, to hold specific categories of events for
>> when we want to segregate them for matching purposes.
>>
>> Signed-off-by: John Garry <john.garry@huawei.com>
>> ---
>>   tools/perf/pmu-events/jevents.c | 11 ++++++++---
>>   1 file changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
>> index 079c77b6a2fd..8af05b94a37d 100644
>> --- a/tools/perf/pmu-events/jevents.c
>> +++ b/tools/perf/pmu-events/jevents.c
>> @@ -960,15 +960,20 @@ static int process_one_file(const char *fpath, const struct stat *sb,
>>   	int level   = ftwbuf->level;
>>   	int err = 0;
>>   
>> -	if (level == 2 && is_dir) {
>> +	if (level >= 2 && is_dir) {
>> +		int count = 0;
>>   		/*
>>   		 * For level 2 directory, bname will include parent name,
>>   		 * like vendor/platform. So search back from platform dir
>>   		 * to find this.
>> +		 * Something similar for level 3 directory, but we're a PMU
>> +		 * category folder, like vendor/platform/cpu.
>>   		 */
>>   		bname = (char *) fpath + ftwbuf->base - 2;
>>   		for (;;) {
>>   			if (*bname == '/')
>> +				count++;
>> +			if (count == level - 1)
>>   				break;
>>   			bname--;
> 

Hi Jirka,

> I was wondering why we just don't use different filename for that,
> but it's true that the code transforms directory chain to the table
> name.. so I guess another directory level is justified ;-)

Yes, and we need to have separate tables for system and CPU/uncore PMU 
aliases.

Thanks,
John

> 
> jirka
> 
> 
>>   		}
>> @@ -981,13 +986,13 @@ static int process_one_file(const char *fpath, const struct stat *sb,
>>   		 level, sb->st_size, bname, fpath);
>>   
>>   	/* base dir or too deep */
>> -	if (level == 0 || level > 3)
>> +	if (level == 0 || level > 4)
>>   		return 0;
>>   
>>   
>>   	/* model directory, reset topic */
>>   	if ((level == 1 && is_dir && is_leaf_dir(fpath)) ||
>> -	    (level == 2 && is_dir)) {
>> +	    (level >= 2 && is_dir && is_leaf_dir(fpath))) {
>>   		if (close_table)
>>   			print_events_table_suffix(eventsfp);
>>   
>> -- 
>> 2.17.1
>>
> 
> .
>

Patch
diff mbox series

diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index 079c77b6a2fd..8af05b94a37d 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -960,15 +960,20 @@  static int process_one_file(const char *fpath, const struct stat *sb,
 	int level   = ftwbuf->level;
 	int err = 0;
 
-	if (level == 2 && is_dir) {
+	if (level >= 2 && is_dir) {
+		int count = 0;
 		/*
 		 * For level 2 directory, bname will include parent name,
 		 * like vendor/platform. So search back from platform dir
 		 * to find this.
+		 * Something similar for level 3 directory, but we're a PMU
+		 * category folder, like vendor/platform/cpu.
 		 */
 		bname = (char *) fpath + ftwbuf->base - 2;
 		for (;;) {
 			if (*bname == '/')
+				count++;
+			if (count == level - 1)
 				break;
 			bname--;
 		}
@@ -981,13 +986,13 @@  static int process_one_file(const char *fpath, const struct stat *sb,
 		 level, sb->st_size, bname, fpath);
 
 	/* base dir or too deep */
-	if (level == 0 || level > 3)
+	if (level == 0 || level > 4)
 		return 0;
 
 
 	/* model directory, reset topic */
 	if ((level == 1 && is_dir && is_leaf_dir(fpath)) ||
-	    (level == 2 && is_dir)) {
+	    (level >= 2 && is_dir && is_leaf_dir(fpath))) {
 		if (close_table)
 			print_events_table_suffix(eventsfp);