@@ -367,46 +367,45 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
367
367
return -1 ;
368
368
}
369
369
370
- static int
371
- perf_pmu__parse_per_pkg ( struct perf_pmu * pmu , struct perf_pmu_alias * alias )
370
+ static bool perf_pmu__parse_event_source_bool ( const char * pmu_name , const char * event_name ,
371
+ const char * suffix )
372
372
{
373
373
char path [PATH_MAX ];
374
374
size_t len ;
375
375
int fd ;
376
376
377
377
len = perf_pmu__event_source_devices_scnprintf (path , sizeof (path ));
378
378
if (!len )
379
- return 0 ;
380
- scnprintf (path + len , sizeof (path ) - len , "%s/events/%s.per-pkg" , pmu -> name , alias -> name );
379
+ return false;
380
+
381
+ scnprintf (path + len , sizeof (path ) - len , "%s/events/%s.%s" , pmu_name , event_name , suffix );
381
382
382
383
fd = open (path , O_RDONLY );
383
384
if (fd == -1 )
384
- return -1 ;
385
+ return false ;
385
386
386
- close (fd );
387
+ #ifndef NDEBUG
388
+ {
389
+ char buf [8 ];
387
390
388
- alias -> per_pkg = true;
389
- return 0 ;
391
+ len = read (fd , buf , sizeof (buf ));
392
+ assert (len == 1 || len == 2 );
393
+ assert (buf [0 ] == '1' );
394
+ }
395
+ #endif
396
+
397
+ close (fd );
398
+ return true;
390
399
}
391
400
392
- static int perf_pmu__parse_snapshot (struct perf_pmu * pmu , struct perf_pmu_alias * alias )
401
+ static void perf_pmu__parse_per_pkg (struct perf_pmu * pmu , struct perf_pmu_alias * alias )
393
402
{
394
- char path [PATH_MAX ];
395
- size_t len ;
396
- int fd ;
397
-
398
- len = perf_pmu__event_source_devices_scnprintf (path , sizeof (path ));
399
- if (!len )
400
- return 0 ;
401
- scnprintf (path + len , sizeof (path ) - len , "%s/events/%s.snapshot" , pmu -> name , alias -> name );
402
-
403
- fd = open (path , O_RDONLY );
404
- if (fd == -1 )
405
- return -1 ;
403
+ alias -> per_pkg = perf_pmu__parse_event_source_bool (pmu -> name , alias -> name , "per-pkg" );
404
+ }
406
405
407
- alias -> snapshot = true;
408
- close ( fd );
409
- return 0 ;
406
+ static void perf_pmu__parse_snapshot ( struct perf_pmu * pmu , struct perf_pmu_alias * alias )
407
+ {
408
+ alias -> snapshot = perf_pmu__parse_event_source_bool ( pmu -> name , alias -> name , "snapshot" ) ;
410
409
}
411
410
412
411
/* Delete an alias entry. */
0 commit comments