2019-08-15 17:00:11 +03:00
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
# include "evswitch.h"
2019-08-15 17:31:29 +03:00
# include "evlist.h"
2019-08-15 17:00:11 +03:00
bool evswitch__discard ( struct evswitch * evswitch , struct evsel * evsel )
{
if ( evswitch - > on & & evswitch - > discarding ) {
if ( evswitch - > on ! = evsel )
return true ;
evswitch - > discarding = false ;
if ( ! evswitch - > show_on_off_events )
return true ;
return false ;
}
if ( evswitch - > off & & ! evswitch - > discarding ) {
if ( evswitch - > off ! = evsel )
return false ;
evswitch - > discarding = true ;
if ( ! evswitch - > show_on_off_events )
return true ;
}
return false ;
}
2019-08-15 17:31:29 +03:00
2019-08-15 17:35:56 +03:00
static int evswitch__fprintf_enoent ( FILE * fp , const char * evtype , const char * evname )
{
2019-08-15 18:02:13 +03:00
int printed = fprintf ( fp , " ERROR: switch-%s event not found (%s) \n " , evtype , evname ) ;
return printed + = fprintf ( fp , " HINT: use 'perf evlist' to see the available event names \n " ) ;
2019-08-15 17:35:56 +03:00
}
2019-08-15 17:31:29 +03:00
int evswitch__init ( struct evswitch * evswitch , struct evlist * evlist , FILE * fp )
{
if ( evswitch - > on_name ) {
2020-11-30 15:48:07 +03:00
evswitch - > on = evlist__find_evsel_by_str ( evlist , evswitch - > on_name ) ;
2019-08-15 17:31:29 +03:00
if ( evswitch - > on = = NULL ) {
2019-08-15 17:35:56 +03:00
evswitch__fprintf_enoent ( fp , " on " , evswitch - > on_name ) ;
2019-08-15 17:31:29 +03:00
return - ENOENT ;
}
evswitch - > discarding = true ;
}
if ( evswitch - > off_name ) {
2020-11-30 15:48:07 +03:00
evswitch - > off = evlist__find_evsel_by_str ( evlist , evswitch - > off_name ) ;
2019-08-15 17:31:29 +03:00
if ( evswitch - > off = = NULL ) {
2019-08-15 17:35:56 +03:00
evswitch__fprintf_enoent ( fp , " off " , evswitch - > off_name ) ;
2019-08-15 17:31:29 +03:00
return - ENOENT ;
}
}
return 0 ;
}