2019-05-31 11:09:51 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2009-08-17 18:18:06 +04:00
/*
* Copyright ( C ) 2009 , Steven Rostedt < srostedt @ redhat . com >
*/
# include <dirent.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <stdarg.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/wait.h>
# include <sys/mman.h>
perf build: Use libtraceevent from the system
Remove the LIBTRACEEVENT_DYNAMIC and LIBTRACEFS_DYNAMIC make command
line variables.
If libtraceevent isn't installed or NO_LIBTRACEEVENT=1 is passed to the
build, don't compile in libtraceevent and libtracefs support.
This also disables CONFIG_TRACE that controls "perf trace".
CONFIG_LIBTRACEEVENT is used to control enablement in Build/Makefiles,
HAVE_LIBTRACEEVENT is used in C code.
Without HAVE_LIBTRACEEVENT tracepoints are disabled and as such the
commands kmem, kwork, lock, sched and timechart are removed. The
majority of commands continue to work including "perf test".
Committer notes:
Fixed up a tools/perf/util/Build reject and added:
#include <traceevent/event-parse.h>
to tools/perf/util/scripting-engines/trace-event-perl.c.
Committer testing:
$ rpm -qi libtraceevent-devel
Name : libtraceevent-devel
Version : 1.5.3
Release : 2.fc36
Architecture: x86_64
Install Date: Mon 25 Jul 2022 03:20:19 PM -03
Group : Unspecified
Size : 27728
License : LGPLv2+ and GPLv2+
Signature : RSA/SHA256, Fri 15 Apr 2022 02:11:58 PM -03, Key ID 999f7cbf38ab71f4
Source RPM : libtraceevent-1.5.3-2.fc36.src.rpm
Build Date : Fri 15 Apr 2022 10:57:01 AM -03
Build Host : buildvm-x86-05.iad2.fedoraproject.org
Packager : Fedora Project
Vendor : Fedora Project
URL : https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
Bug URL : https://bugz.fedoraproject.org/libtraceevent
Summary : Development headers of libtraceevent
Description :
Development headers of libtraceevent-libs
$
Default build:
$ ldd ~/bin/perf | grep tracee
libtraceevent.so.1 => /lib64/libtraceevent.so.1 (0x00007f1dcaf8f000)
$
# perf trace -e sched:* --max-events 10
0.000 migration/0/17 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, dest_cpu: 1)
0.005 migration/0/17 sched:sched_wake_idle_without_ipi(cpu: 1)
0.011 migration/0/17 sched:sched_switch(prev_comm: "", prev_pid: 17 (migration/0), prev_state: 1, next_comm: "", next_prio: 120)
1.173 :0/0 sched:sched_wakeup(comm: "", pid: 3138 (gnome-terminal-), prio: 120)
1.180 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 3138 (gnome-terminal-), next_prio: 120)
0.156 migration/1/21 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, orig_cpu: 1, dest_cpu: 2)
0.160 migration/1/21 sched:sched_wake_idle_without_ipi(cpu: 2)
0.166 migration/1/21 sched:sched_switch(prev_comm: "", prev_pid: 21 (migration/1), prev_state: 1, next_comm: "", next_prio: 120)
1.183 :0/0 sched:sched_wakeup(comm: "", pid: 1602985 (kworker/u16:0-f), prio: 120, target_cpu: 1)
1.186 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 1602985 (kworker/u16:0-f), next_prio: 120)
#
Had to tweak tools/perf/util/setup.py to make sure the python binding
shared object links with libtraceevent if -DHAVE_LIBTRACEEVENT is
present in CFLAGS.
Building with NO_LIBTRACEEVENT=1 uncovered some more build failures:
- Make building of data-convert-bt.c to CONFIG_LIBTRACEEVENT=y
- perf-$(CONFIG_LIBTRACEEVENT) += scripts/
- bpf_kwork.o needs also to be dependent on CONFIG_LIBTRACEEVENT=y
- The python binding needed some fixups and util/trace-event.c can't be
built and linked with the python binding shared object, so remove it
in tools/perf/util/setup.py and exclude it from the list of
dependencies in the python/perf.so Makefile.perf target.
Building without libtraceevent-devel installed uncovered more build
failures:
- The python binding tools/perf/util/python.c was assuming that
traceevent/parse-events.h was always available, which was the case
when we defaulted to using the in-kernel tools/lib/traceevent/ files,
now we need to enclose it under ifdef HAVE_LIBTRACEEVENT, just like
the other parts of it that deal with tracepoints.
- We have to ifdef the rules in the Build files with
CONFIG_LIBTRACEEVENT=y to build builtin-trace.c and
tools/perf/trace/beauty/ as we only ifdef setting CONFIG_TRACE=y when
setting NO_LIBTRACEEVENT=1 in the make command line, not when we don't
detect libtraceevent-devel installed in the system. Simplification here
to avoid these two ways of disabling builtin-trace.c and not having
CONFIG_TRACE=y when libtraceevent-devel isn't installed is the clean
way.
From Athira:
<quote>
tools/perf/arch/powerpc/util/Build
-perf-y += kvm-stat.o
+perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
</quote>
Then, ditto for arm64 and s390, detected by container cross build tests.
- s/390 uses test__checkevent_tracepoint() that is now only available if
HAVE_LIBTRACEEVENT is defined, enclose the callsite with ifder HAVE_LIBTRACEEVENT.
Also from Athira:
<quote>
With this change, I could successfully compile in these environment:
- Without libtraceevent-devel installed
- With libtraceevent-devel installed
- With “make NO_LIBTRACEEVENT=1”
</quote>
Then, finally rename CONFIG_TRACEEVENT to CONFIG_LIBTRACEEVENT for
consistency with other libraries detected in tools/perf/.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: bpf@vger.kernel.org
Link: http://lore.kernel.org/lkml/20221205225940.3079667-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-06 01:59:39 +03:00
# include <traceevent/event-parse.h>
2009-08-17 18:18:06 +04:00
# include <fcntl.h>
# include <unistd.h>
# include <errno.h>
# include "trace-event.h"
2014-07-15 01:46:48 +04:00
# include "debug.h"
2022-11-30 09:29:33 +03:00
# include "util.h"
2009-08-17 18:18:06 +04:00
static int input_fd ;
2013-03-21 11:18:52 +04:00
static ssize_t trace_data_size ;
2010-05-01 10:41:20 +04:00
static bool repipe ;
2010-04-02 08:59:21 +04:00
2013-03-21 11:18:50 +04:00
static int __do_read ( int fd , void * buf , int size )
2010-04-02 08:59:21 +04:00
{
int rsize = size ;
while ( size ) {
int ret = read ( fd , buf , size ) ;
if ( ret < = 0 )
return - 1 ;
2010-05-01 10:41:20 +04:00
if ( repipe ) {
int retw = write ( STDOUT_FILENO , buf , ret ) ;
2013-03-21 11:18:50 +04:00
if ( retw < = 0 | | retw ! = ret ) {
pr_debug ( " repiping input file " ) ;
return - 1 ;
}
2010-05-01 10:41:20 +04:00
}
2010-04-02 08:59:21 +04:00
size - = ret ;
buf + = ret ;
}
return rsize ;
}
2013-03-21 11:18:50 +04:00
static int do_read ( void * data , int size )
2009-08-17 18:18:06 +04:00
{
int r ;
2013-03-21 11:18:50 +04:00
r = __do_read ( input_fd , data , size ) ;
if ( r < = 0 ) {
pr_debug ( " reading input file (size expected=%d received=%d) " ,
size , r ) ;
return - 1 ;
}
2010-04-02 08:59:21 +04:00
2013-03-21 11:18:52 +04:00
trace_data_size + = r ;
2010-04-02 08:59:21 +04:00
2009-08-17 18:18:06 +04:00
return r ;
}
2010-05-05 08:02:10 +04:00
/* If it fails, the next read will report it */
static void skip ( int size )
{
char buf [ BUFSIZ ] ;
int r ;
while ( size ) {
r = size > BUFSIZ ? BUFSIZ : size ;
2013-03-21 11:18:50 +04:00
do_read ( buf , r ) ;
2010-05-05 08:02:10 +04:00
size - = r ;
2020-04-28 12:18:43 +03:00
}
2010-05-05 08:02:10 +04:00
}
2018-08-08 21:02:46 +03:00
static unsigned int read4 ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned int data ;
2013-03-21 11:18:50 +04:00
if ( do_read ( & data , 4 ) < 0 )
return 0 ;
2018-11-30 18:44:09 +03:00
return tep_read_number ( pevent , & data , 4 ) ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static unsigned long long read8 ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned long long data ;
2013-03-21 11:18:50 +04:00
if ( do_read ( & data , 8 ) < 0 )
return 0 ;
2018-11-30 18:44:09 +03:00
return tep_read_number ( pevent , & data , 8 ) ;
2009-08-17 18:18:06 +04:00
}
static char * read_string ( void )
{
char buf [ BUFSIZ ] ;
char * str = NULL ;
int size = 0 ;
2010-02-04 11:46:42 +03:00
off_t r ;
2010-04-02 08:59:21 +04:00
char c ;
2009-08-17 18:18:06 +04:00
for ( ; ; ) {
2010-04-02 08:59:21 +04:00
r = read ( input_fd , & c , 1 ) ;
2013-03-21 11:18:51 +04:00
if ( r < 0 ) {
pr_debug ( " reading input file " ) ;
goto out ;
}
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:51 +04:00
if ( ! r ) {
pr_debug ( " no data " ) ;
goto out ;
}
2009-08-17 18:18:06 +04:00
2010-05-01 10:41:20 +04:00
if ( repipe ) {
int retw = write ( STDOUT_FILENO , & c , 1 ) ;
2013-03-21 11:18:51 +04:00
if ( retw < = 0 | | retw ! = r ) {
pr_debug ( " repiping input file string " ) ;
goto out ;
}
2010-05-01 10:41:20 +04:00
}
2010-04-02 08:59:21 +04:00
buf [ size + + ] = c ;
2009-08-17 18:18:06 +04:00
2010-04-02 08:59:21 +04:00
if ( ! c )
break ;
2009-08-17 18:18:06 +04:00
}
2013-03-21 11:18:52 +04:00
trace_data_size + = size ;
2010-04-02 08:59:21 +04:00
2013-03-21 11:18:49 +04:00
str = malloc ( size ) ;
if ( str )
memcpy ( str , buf , size ) ;
2013-03-21 11:18:51 +04:00
out :
2009-08-17 18:18:06 +04:00
return str ;
}
2018-08-08 21:02:46 +03:00
static int read_proc_kallsyms ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned int size ;
2012-06-27 20:08:42 +04:00
size = read4 ( pevent ) ;
2009-08-17 18:18:06 +04:00
if ( ! size )
2013-03-21 11:18:49 +04:00
return 0 ;
2015-07-22 22:48:16 +03:00
/*
* Just skip it , now that we configure libtraceevent to use the
* tools / perf / symbol resolver .
*
* We need to skip it so that we can continue parsing old perf . data
* files , that contains this / proc / kallsyms payload .
*
* Newer perf . data files will have just the 4 - bytes zeros " kallsyms
* payload " , so that older tools can continue reading it and interpret
* it as " no kallsyms payload is present " .
*/
lseek ( input_fd , size , SEEK_CUR ) ;
trace_data_size + = size ;
2013-03-21 11:18:49 +04:00
return 0 ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_ftrace_printk ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned int size ;
char * buf ;
2013-03-21 11:18:50 +04:00
/* it can have 0 size */
2012-06-27 20:08:42 +04:00
size = read4 ( pevent ) ;
2009-08-17 18:18:06 +04:00
if ( ! size )
2013-03-21 11:18:49 +04:00
return 0 ;
2017-03-22 16:06:23 +03:00
buf = malloc ( size + 1 ) ;
2013-03-21 11:18:49 +04:00
if ( buf = = NULL )
return - 1 ;
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , size ) < 0 ) {
free ( buf ) ;
return - 1 ;
}
2009-08-17 18:18:06 +04:00
2017-03-22 16:06:23 +03:00
buf [ size ] = ' \0 ' ;
2012-06-27 20:08:42 +04:00
parse_ftrace_printk ( pevent , buf , size ) ;
2009-08-17 18:18:06 +04:00
free ( buf ) ;
2013-03-21 11:18:49 +04:00
return 0 ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_header_files ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned long long size ;
2013-06-04 09:20:26 +04:00
char * header_page ;
2009-08-17 18:18:06 +04:00
char buf [ BUFSIZ ] ;
2013-03-21 11:18:50 +04:00
int ret = 0 ;
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , 12 ) < 0 )
return - 1 ;
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:51 +04:00
if ( memcmp ( buf , " header_page " , 12 ) ! = 0 ) {
pr_debug ( " did not read header page " ) ;
return - 1 ;
}
2009-08-17 18:18:06 +04:00
2012-06-27 20:08:42 +04:00
size = read8 ( pevent ) ;
2013-06-04 09:20:26 +04:00
header_page = malloc ( size ) ;
if ( header_page = = NULL )
return - 1 ;
if ( do_read ( header_page , size ) < 0 ) {
pr_debug ( " did not read header page " ) ;
free ( header_page ) ;
return - 1 ;
}
2018-08-08 21:02:51 +03:00
if ( ! tep_parse_header_page ( pevent , header_page , size ,
2018-08-08 21:02:55 +03:00
tep_get_long_size ( pevent ) ) ) {
2013-06-04 09:20:26 +04:00
/*
* The commit field in the page is of type long ,
* use that instead , since it represents the kernel .
*/
2018-10-05 19:22:25 +03:00
tep_set_long_size ( pevent , tep_get_header_page_size ( pevent ) ) ;
2013-06-04 09:20:26 +04:00
}
free ( header_page ) ;
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , 13 ) < 0 )
return - 1 ;
2013-03-21 11:18:51 +04:00
if ( memcmp ( buf , " header_event " , 13 ) ! = 0 ) {
pr_debug ( " did not read header event " ) ;
return - 1 ;
}
2009-08-17 18:18:06 +04:00
2012-06-27 20:08:42 +04:00
size = read8 ( pevent ) ;
2013-06-04 09:20:25 +04:00
skip ( size ) ;
2013-03-21 11:18:50 +04:00
return ret ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_ftrace_file ( struct tep_handle * pevent , unsigned long long size )
2009-08-17 18:18:06 +04:00
{
2013-04-18 16:24:16 +04:00
int ret ;
2009-08-17 18:18:06 +04:00
char * buf ;
2013-03-21 11:18:49 +04:00
buf = malloc ( size ) ;
2013-04-18 16:24:16 +04:00
if ( buf = = NULL ) {
pr_debug ( " memory allocation failure \n " ) ;
2013-03-21 11:18:49 +04:00
return - 1 ;
2013-04-18 16:24:16 +04:00
}
2013-03-21 11:18:49 +04:00
2013-04-18 16:24:16 +04:00
ret = do_read ( buf , size ) ;
if ( ret < 0 ) {
pr_debug ( " error reading ftrace file. \n " ) ;
goto out ;
2013-03-21 11:18:50 +04:00
}
2013-04-18 16:24:16 +04:00
ret = parse_ftrace_file ( pevent , buf , size ) ;
if ( ret < 0 )
pr_debug ( " error parsing ftrace file. \n " ) ;
out :
2009-08-17 18:18:06 +04:00
free ( buf ) ;
2013-04-18 16:24:16 +04:00
return ret ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_event_file ( struct tep_handle * pevent , char * sys ,
unsigned long long size )
2009-08-17 18:18:06 +04:00
{
2013-04-18 16:24:16 +04:00
int ret ;
2009-08-17 18:18:06 +04:00
char * buf ;
2013-03-21 11:18:49 +04:00
buf = malloc ( size ) ;
2013-04-18 16:24:16 +04:00
if ( buf = = NULL ) {
pr_debug ( " memory allocation failure \n " ) ;
2013-03-21 11:18:49 +04:00
return - 1 ;
2013-04-18 16:24:16 +04:00
}
2013-03-21 11:18:49 +04:00
2013-04-18 16:24:16 +04:00
ret = do_read ( buf , size ) ;
2018-10-02 17:29:13 +03:00
if ( ret < 0 )
2013-04-18 16:24:16 +04:00
goto out ;
2013-03-21 11:18:50 +04:00
2013-04-18 16:24:16 +04:00
ret = parse_event_file ( pevent , buf , size , sys ) ;
if ( ret < 0 )
pr_debug ( " error parsing event file. \n " ) ;
out :
2009-08-17 18:18:06 +04:00
free ( buf ) ;
2013-04-18 16:24:16 +04:00
return ret ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_ftrace_files ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned long long size ;
int count ;
int i ;
2013-03-21 11:18:49 +04:00
int ret ;
2009-08-17 18:18:06 +04:00
2012-06-27 20:08:42 +04:00
count = read4 ( pevent ) ;
2009-08-17 18:18:06 +04:00
for ( i = 0 ; i < count ; i + + ) {
2012-06-27 20:08:42 +04:00
size = read8 ( pevent ) ;
2013-03-21 11:18:49 +04:00
ret = read_ftrace_file ( pevent , size ) ;
if ( ret )
return ret ;
2009-08-17 18:18:06 +04:00
}
2013-03-21 11:18:49 +04:00
return 0 ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_event_files ( struct tep_handle * pevent )
2009-08-17 18:18:06 +04:00
{
unsigned long long size ;
char * sys ;
int systems ;
int count ;
int i , x ;
2013-03-21 11:18:49 +04:00
int ret ;
2009-08-17 18:18:06 +04:00
2012-06-27 20:08:42 +04:00
systems = read4 ( pevent ) ;
2009-08-17 18:18:06 +04:00
for ( i = 0 ; i < systems ; i + + ) {
sys = read_string ( ) ;
2013-03-21 11:18:49 +04:00
if ( sys = = NULL )
return - 1 ;
2009-08-17 18:18:06 +04:00
2012-06-27 20:08:42 +04:00
count = read4 ( pevent ) ;
2013-03-21 11:18:50 +04:00
2009-08-17 18:18:06 +04:00
for ( x = 0 ; x < count ; x + + ) {
2012-06-27 20:08:42 +04:00
size = read8 ( pevent ) ;
2013-03-21 11:18:49 +04:00
ret = read_event_file ( pevent , sys , size ) ;
2018-10-02 17:29:14 +03:00
if ( ret ) {
free ( sys ) ;
2013-03-21 11:18:49 +04:00
return ret ;
2018-10-02 17:29:14 +03:00
}
2009-08-17 18:18:06 +04:00
}
2018-10-02 17:29:14 +03:00
free ( sys ) ;
2009-08-17 18:18:06 +04:00
}
2013-03-21 11:18:49 +04:00
return 0 ;
2009-08-17 18:18:06 +04:00
}
2018-08-08 21:02:46 +03:00
static int read_saved_cmdline ( struct tep_handle * pevent )
2013-04-11 12:25:04 +04:00
{
unsigned long long size ;
char * buf ;
2013-04-18 16:24:16 +04:00
int ret ;
2013-04-11 12:25:04 +04:00
/* it can have 0 size */
size = read8 ( pevent ) ;
if ( ! size )
return 0 ;
buf = malloc ( size + 1 ) ;
2013-04-18 16:24:16 +04:00
if ( buf = = NULL ) {
pr_debug ( " memory allocation failure \n " ) ;
2013-04-11 12:25:04 +04:00
return - 1 ;
2013-04-18 16:24:16 +04:00
}
2013-04-11 12:25:04 +04:00
2013-04-18 16:24:16 +04:00
ret = do_read ( buf , size ) ;
if ( ret < 0 ) {
pr_debug ( " error reading saved cmdlines \n " ) ;
goto out ;
2013-04-11 12:25:04 +04:00
}
2021-02-27 01:14:31 +03:00
buf [ ret ] = ' \0 ' ;
2013-04-11 12:25:04 +04:00
parse_saved_cmdline ( pevent , buf , size ) ;
2013-04-18 16:24:16 +04:00
ret = 0 ;
out :
2013-04-11 12:25:04 +04:00
free ( buf ) ;
2013-04-18 16:24:16 +04:00
return ret ;
2013-04-11 12:25:04 +04:00
}
2013-12-03 17:09:23 +04:00
ssize_t trace_report ( int fd , struct trace_event * tevent , bool __repipe )
2009-08-17 18:18:06 +04:00
{
char buf [ BUFSIZ ] ;
char test [ ] = { 23 , 8 , 68 } ;
char * version ;
2009-09-12 12:08:34 +04:00
int show_version = 0 ;
2009-08-17 18:18:06 +04:00
int show_funcs = 0 ;
int show_printk = 0 ;
2013-03-21 11:18:48 +04:00
ssize_t size = - 1 ;
2013-06-04 09:20:24 +04:00
int file_bigendian ;
int host_bigendian ;
2013-06-04 09:20:23 +04:00
int file_long_size ;
2013-06-04 09:20:22 +04:00
int file_page_size ;
2018-08-08 21:02:46 +03:00
struct tep_handle * pevent = NULL ;
2013-03-21 11:18:49 +04:00
int err ;
2013-03-21 11:18:48 +04:00
2010-05-01 10:41:20 +04:00
repipe = __repipe ;
2009-10-07 01:36:47 +04:00
input_fd = fd ;
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , 3 ) < 0 )
return - 1 ;
2013-03-21 11:18:51 +04:00
if ( memcmp ( buf , test , 3 ) ! = 0 ) {
pr_debug ( " no trace data in the file " ) ;
return - 1 ;
}
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , 7 ) < 0 )
return - 1 ;
2013-03-21 11:18:51 +04:00
if ( memcmp ( buf , " tracing " , 7 ) ! = 0 ) {
pr_debug ( " not a trace file (missing 'tracing' tag) " ) ;
return - 1 ;
}
2009-08-17 18:18:06 +04:00
version = read_string ( ) ;
2013-03-21 11:18:49 +04:00
if ( version = = NULL )
return - 1 ;
2009-09-12 12:08:34 +04:00
if ( show_version )
printf ( " version = %s \n " , version ) ;
2009-08-17 18:18:06 +04:00
2013-04-11 12:25:04 +04:00
if ( do_read ( buf , 1 ) < 0 ) {
free ( version ) ;
2013-03-21 11:18:50 +04:00
return - 1 ;
2013-04-11 12:25:04 +04:00
}
2009-08-17 18:18:06 +04:00
file_bigendian = buf [ 0 ] ;
2022-11-30 09:29:33 +03:00
host_bigendian = host_is_bigendian ( ) ? 1 : 0 ;
2009-08-17 18:18:06 +04:00
2013-12-03 17:09:23 +04:00
if ( trace_event__init ( tevent ) ) {
pr_debug ( " trace_event__init failed " ) ;
2013-03-21 11:18:48 +04:00
goto out ;
}
2012-04-06 02:47:56 +04:00
2013-12-03 17:09:23 +04:00
pevent = tevent - > pevent ;
2018-08-08 21:02:57 +03:00
tep_set_flag ( pevent , TEP_NSEC_OUTPUT ) ;
2018-08-08 21:02:55 +03:00
tep_set_file_bigendian ( pevent , file_bigendian ) ;
2019-04-01 19:43:16 +03:00
tep_set_local_bigendian ( pevent , host_bigendian ) ;
2013-12-03 17:09:23 +04:00
2013-03-21 11:18:50 +04:00
if ( do_read ( buf , 1 ) < 0 )
goto out ;
2013-06-04 09:20:23 +04:00
file_long_size = buf [ 0 ] ;
2009-08-17 18:18:06 +04:00
2013-06-04 09:20:22 +04:00
file_page_size = read4 ( pevent ) ;
if ( ! file_page_size )
2013-03-21 11:18:50 +04:00
goto out ;
2009-08-17 18:18:06 +04:00
2018-08-08 21:02:55 +03:00
tep_set_long_size ( pevent , file_long_size ) ;
tep_set_page_size ( pevent , file_page_size ) ;
2013-06-04 09:20:22 +04:00
2013-03-21 11:18:49 +04:00
err = read_header_files ( pevent ) ;
if ( err )
goto out ;
err = read_ftrace_files ( pevent ) ;
if ( err )
goto out ;
err = read_event_files ( pevent ) ;
if ( err )
goto out ;
err = read_proc_kallsyms ( pevent ) ;
if ( err )
goto out ;
err = read_ftrace_printk ( pevent ) ;
if ( err )
goto out ;
2013-04-11 12:25:04 +04:00
if ( atof ( version ) > = 0.6 ) {
err = read_saved_cmdline ( pevent ) ;
if ( err )
goto out ;
}
2009-08-17 18:18:06 +04:00
2013-03-21 11:18:52 +04:00
size = trace_data_size ;
2010-05-01 10:41:20 +04:00
repipe = false ;
2010-04-02 08:59:21 +04:00
2009-08-17 18:18:06 +04:00
if ( show_funcs ) {
2018-08-08 21:02:52 +03:00
tep_print_funcs ( pevent ) ;
2013-03-21 11:18:48 +04:00
} else if ( show_printk ) {
2018-08-08 21:02:52 +03:00
tep_print_printk ( pevent ) ;
2009-08-17 18:18:06 +04:00
}
2013-03-21 11:18:48 +04:00
pevent = NULL ;
out :
if ( pevent )
2013-12-03 17:09:23 +04:00
trace_event__cleanup ( tevent ) ;
2013-04-11 12:25:04 +04:00
free ( version ) ;
2010-04-02 08:59:21 +04:00
return size ;
2009-08-17 18:18:06 +04:00
}