22#include "perf.h"
33
44#include "util/util.h"
5+ #include "util/evlist.h"
56#include "util/cache.h"
67#include "util/evsel.h"
78#include "util/symbol.h"
@@ -1358,12 +1359,13 @@ static void sort_lat(void)
13581359static struct trace_sched_handler * trace_handler ;
13591360
13601361static void
1361- process_sched_wakeup_event (void * data , struct machine * machine ,
1362+ process_sched_wakeup_event (struct perf_tool * tool __used ,
13621363 struct event * event ,
1363- int cpu __used ,
1364- u64 timestamp __used ,
1365- struct thread * thread __used )
1364+ struct perf_sample * sample ,
1365+ struct machine * machine ,
1366+ struct thread * thread )
13661367{
1368+ void * data = sample -> raw_data ;
13671369 struct trace_wakeup_event wakeup_event ;
13681370
13691371 FILL_COMMON_FIELDS (wakeup_event , event , data );
@@ -1376,7 +1378,7 @@ process_sched_wakeup_event(void *data, struct machine *machine,
13761378
13771379 if (trace_handler -> wakeup_event )
13781380 trace_handler -> wakeup_event (& wakeup_event , machine , event ,
1379- cpu , timestamp , thread );
1381+ sample -> cpu , sample -> time , thread );
13801382}
13811383
13821384/*
@@ -1471,14 +1473,15 @@ map_switch_event(struct trace_switch_event *switch_event,
14711473 }
14721474}
14731475
1474-
14751476static void
1476- process_sched_switch_event (void * data , struct machine * machine ,
1477+ process_sched_switch_event (struct perf_tool * tool __used ,
14771478 struct event * event ,
1478- int this_cpu ,
1479- u64 timestamp __used ,
1480- struct thread * thread __used )
1479+ struct perf_sample * sample ,
1480+ struct machine * machine ,
1481+ struct thread * thread )
14811482{
1483+ int this_cpu = sample -> cpu ;
1484+ void * data = sample -> raw_data ;
14821485 struct trace_switch_event switch_event ;
14831486
14841487 FILL_COMMON_FIELDS (switch_event , event , data );
@@ -1501,18 +1504,19 @@ process_sched_switch_event(void *data, struct machine *machine,
15011504 }
15021505 if (trace_handler -> switch_event )
15031506 trace_handler -> switch_event (& switch_event , machine , event ,
1504- this_cpu , timestamp , thread );
1507+ this_cpu , sample -> time , thread );
15051508
15061509 curr_pid [this_cpu ] = switch_event .next_pid ;
15071510}
15081511
15091512static void
1510- process_sched_runtime_event (void * data , struct machine * machine ,
1511- struct event * event ,
1512- int cpu __used ,
1513- u64 timestamp __used ,
1514- struct thread * thread __used )
1513+ process_sched_runtime_event (struct perf_tool * tool __used ,
1514+ struct event * event ,
1515+ struct perf_sample * sample ,
1516+ struct machine * machine ,
1517+ struct thread * thread )
15151518{
1519+ void * data = sample -> raw_data ;
15161520 struct trace_runtime_event runtime_event ;
15171521
15181522 FILL_ARRAY (runtime_event , comm , event , data );
@@ -1521,16 +1525,18 @@ process_sched_runtime_event(void *data, struct machine *machine,
15211525 FILL_FIELD (runtime_event , vruntime , event , data );
15221526
15231527 if (trace_handler -> runtime_event )
1524- trace_handler -> runtime_event (& runtime_event , machine , event , cpu , timestamp , thread );
1528+ trace_handler -> runtime_event (& runtime_event , machine , event ,
1529+ sample -> cpu , sample -> time , thread );
15251530}
15261531
15271532static void
1528- process_sched_fork_event (void * data ,
1533+ process_sched_fork_event (struct perf_tool * tool __used ,
15291534 struct event * event ,
1530- int cpu __used ,
1531- u64 timestamp __used ,
1532- struct thread * thread __used )
1535+ struct perf_sample * sample ,
1536+ struct machine * machine __used ,
1537+ struct thread * thread )
15331538{
1539+ void * data = sample -> raw_data ;
15341540 struct trace_fork_event fork_event ;
15351541
15361542 FILL_COMMON_FIELDS (fork_event , event , data );
@@ -1542,26 +1548,28 @@ process_sched_fork_event(void *data,
15421548
15431549 if (trace_handler -> fork_event )
15441550 trace_handler -> fork_event (& fork_event , event ,
1545- cpu , timestamp , thread );
1551+ sample -> cpu , sample -> time , thread );
15461552}
15471553
15481554static void
1549- process_sched_exit_event (struct event * event ,
1550- int cpu __used ,
1551- u64 timestamp __used ,
1555+ process_sched_exit_event (struct perf_tool * tool __used ,
1556+ struct event * event ,
1557+ struct perf_sample * sample __used ,
1558+ struct machine * machine __used ,
15521559 struct thread * thread __used )
15531560{
15541561 if (verbose )
15551562 printf ("sched_exit event %p\n" , event );
15561563}
15571564
15581565static void
1559- process_sched_migrate_task_event (void * data , struct machine * machine ,
1560- struct event * event ,
1561- int cpu __used ,
1562- u64 timestamp __used ,
1563- struct thread * thread __used )
1566+ process_sched_migrate_task_event (struct perf_tool * tool __used ,
1567+ struct event * event ,
1568+ struct perf_sample * sample ,
1569+ struct machine * machine ,
1570+ struct thread * thread )
15641571{
1572+ void * data = sample -> raw_data ;
15651573 struct trace_migrate_task_event migrate_task_event ;
15661574
15671575 FILL_COMMON_FIELDS (migrate_task_event , event , data );
@@ -1573,67 +1581,46 @@ process_sched_migrate_task_event(void *data, struct machine *machine,
15731581
15741582 if (trace_handler -> migrate_task_event )
15751583 trace_handler -> migrate_task_event (& migrate_task_event , machine ,
1576- event , cpu , timestamp , thread );
1584+ event , sample -> cpu ,
1585+ sample -> time , thread );
15771586}
15781587
1579- static void process_raw_event (union perf_event * raw_event __used ,
1580- struct machine * machine , void * data , int cpu ,
1581- u64 timestamp , struct thread * thread )
1582- {
1583- struct event * event ;
1584- int type ;
1585-
1586-
1587- type = trace_parse_common_type (data );
1588- event = trace_find_event (type );
1589-
1590- if (!strcmp (event -> name , "sched_switch" ))
1591- process_sched_switch_event (data , machine , event , cpu , timestamp , thread );
1592- if (!strcmp (event -> name , "sched_stat_runtime" ))
1593- process_sched_runtime_event (data , machine , event , cpu , timestamp , thread );
1594- if (!strcmp (event -> name , "sched_wakeup" ))
1595- process_sched_wakeup_event (data , machine , event , cpu , timestamp , thread );
1596- if (!strcmp (event -> name , "sched_wakeup_new" ))
1597- process_sched_wakeup_event (data , machine , event , cpu , timestamp , thread );
1598- if (!strcmp (event -> name , "sched_process_fork" ))
1599- process_sched_fork_event (data , event , cpu , timestamp , thread );
1600- if (!strcmp (event -> name , "sched_process_exit" ))
1601- process_sched_exit_event (event , cpu , timestamp , thread );
1602- if (!strcmp (event -> name , "sched_migrate_task" ))
1603- process_sched_migrate_task_event (data , machine , event , cpu , timestamp , thread );
1604- }
1588+ typedef void (* tracepoint_handler )(struct perf_tool * tool , struct event * event ,
1589+ struct perf_sample * sample ,
1590+ struct machine * machine ,
1591+ struct thread * thread );
16051592
1606- static int process_sample_event (struct perf_tool * tool __used ,
1607- union perf_event * event ,
1608- struct perf_sample * sample ,
1609- struct perf_evsel * evsel ,
1610- struct machine * machine )
1593+ static int perf_sched__process_tracepoint_sample (struct perf_tool * tool ,
1594+ union perf_event * event __used ,
1595+ struct perf_sample * sample ,
1596+ struct perf_evsel * evsel ,
1597+ struct machine * machine )
16111598{
1612- struct thread * thread ;
1613-
1614- if (!(evsel -> attr .sample_type & PERF_SAMPLE_RAW ))
1615- return 0 ;
1599+ struct thread * thread = machine__findnew_thread (machine , sample -> pid );
16161600
1617- thread = machine__findnew_thread (machine , sample -> pid );
16181601 if (thread == NULL ) {
1619- pr_debug ("problem processing %d event, skipping it.\n" ,
1620- event -> header . type );
1602+ pr_debug ("problem processing %s event, skipping it.\n" ,
1603+ evsel -> name );
16211604 return -1 ;
16221605 }
16231606
1624- dump_printf (" ... thread: %s:%d\n" , thread -> comm , thread -> pid );
1607+ evsel -> hists .stats .total_period += sample -> period ;
1608+ hists__inc_nr_events (& evsel -> hists , PERF_RECORD_SAMPLE );
16251609
1626- if (profile_cpu != -1 && profile_cpu != ( int ) sample -> cpu )
1627- return 0 ;
1610+ if (evsel -> handler . func != NULL ) {
1611+ tracepoint_handler f = evsel -> handler . func ;
16281612
1629- process_raw_event (event , machine , sample -> raw_data , sample -> cpu ,
1630- sample -> time , thread );
1613+ if (evsel -> handler .data == NULL )
1614+ evsel -> handler .data = trace_find_event (evsel -> attr .config );
1615+
1616+ f (tool , evsel -> handler .data , sample , machine , thread );
1617+ }
16311618
16321619 return 0 ;
16331620}
16341621
16351622static struct perf_tool perf_sched = {
1636- .sample = process_sample_event ,
1623+ .sample = perf_sched__process_tracepoint_sample ,
16371624 .comm = perf_event__process_comm ,
16381625 .lost = perf_event__process_lost ,
16391626 .fork = perf_event__process_task ,
@@ -1643,11 +1630,23 @@ static struct perf_tool perf_sched = {
16431630static void read_events (bool destroy , struct perf_session * * psession )
16441631{
16451632 int err = - EINVAL ;
1633+ const struct perf_evsel_str_handler handlers [] = {
1634+ { "sched:sched_switch" , process_sched_switch_event , },
1635+ { "sched:sched_stat_runtime" , process_sched_runtime_event , },
1636+ { "sched:sched_wakeup" , process_sched_wakeup_event , },
1637+ { "sched:sched_wakeup_new" , process_sched_wakeup_event , },
1638+ { "sched:sched_process_fork" , process_sched_fork_event , },
1639+ { "sched:sched_process_exit" , process_sched_exit_event , },
1640+ { "sched:sched_migrate_task" , process_sched_migrate_task_event , },
1641+ };
16461642 struct perf_session * session = perf_session__new (input_name , O_RDONLY ,
16471643 0 , false, & perf_sched );
16481644 if (session == NULL )
16491645 die ("No Memory" );
16501646
1647+ err = perf_evlist__set_tracepoints_handlers_array (session -> evlist , handlers );
1648+ assert (err == 0 );
1649+
16511650 if (perf_session__has_traces (session , "record -R" )) {
16521651 err = perf_session__process_events (session , & perf_sched );
16531652 if (err )
0 commit comments