From: Andi Kleen <ak@linux.intel.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH 06/23] perf doc: Add perf data file documentation
Date: Fri, 19 Jul 2013 08:46:37 -0700 [thread overview]
Message-ID: <20130719154637.GY5643@tassilo.jf.intel.com> (raw)
In-Reply-To: <1374083403-14591-7-git-send-email-jolsa@redhat.com>
On Wed, Jul 17, 2013 at 07:49:46PM +0200, Jiri Olsa wrote:
> Adding perf data file documentation.
FWIW I wrote the following python "construct" description of the data format
some time ago. It's more formal than yours. There were still a few things
missing though and one mysterious bug.
# A description of the perf.data file format in "construct"
#
from construct import *
def fork_exit(name):
return Struct(name,
SNInt32("pid"),
SNInt32("ppid"),
SNInt32("tid"),
SNInt32("ptid"),
UNInt64("time"))
def throttle(name):
return Struct(name,
UNInt64("time"),
UNInt64("id"),
UNInt64("stream_id"))
def event(sample_type, read_format):
return Embedded(
Struct("event",
If(lambda ctx: sample_type.ip,
UNInt64("ip")),
If(lambda ctx: sample_type.tid,
Struct("tid",
SNInt64("pid"),
SNInt64("tid"))),
If(lambda ctx: sample_type.time,
UNInt64("time")),
If(lambda ctx: sample_type.addr,
UNInt64("addr")),
If(lambda ctx: sample_type.stream_id,
UNInt64("stream_id")),
If(lambda ctx: sample_type.cpu,
Struct("cpu",
UNInt32("cpu"),
UNInt32("res"))),
If(lambda ctx: sample_type.period,
UNInt64("period")),
# XXX
#If(lambda ctx: sample_type.read,
# read_format(rformat)),
If(lambda ctx: sample_type.callchain,
Struct("callchain",
UNInt64("nr"),
Array(lambda ctx: ctx.nr,
UNInt64("addr")))),
If(lambda ctx: sample_type.raw,
Struct("raw",
UNInt32("size"),
Bytes("raw", lambda ctx: ctx.size))),
If(lambda ctx: sample_type.branch_stack,
Struct("branch_stack",
UNInt64("nr"),
Array(lambda ctx: ctx.nr,
Struct(None,
UNInt64("from"),
UNInt64("to"),
UNInt64("flags"))))), # XXX split
# both need parameters passed in
# sample reg
# stack user
If(lambda ctx: sample_type.weight,
UNInt64("weight")),
If(lambda ctx: sample_type.data_src,
UNInt64("data_src")),
Anchor("end_event"),
Padding(lambda ctx: max(0, ctx.size - ctx.end_event))))
# XXX need to make OnDemand for large files
def perf_event(sample_type, read_format):
return Struct("perf_event",
Anchor("start"),
Enum(UNInt32("type"),
MMAP = 1,
LOST = 2,
COMM = 3,
EXIT = 4,
THROTTLE = 5,
UNTHROTTLE = 6,
FORK = 7,
READ = 8,
SAMPLE = 9),
UNInt16("misc"),
UNInt16("size"),
Switch("data",
lambda ctx: ctx.type,
{
"MMAP": Struct("mmap",
SNInt32("pid"),
SNInt32("tid"),
UNInt64("addr"),
UNInt64("len"),
UNInt64("pgoff"),
CString("filename")),
"LOST": Struct("lost",
UNInt64("id"),
UNInt64("lost")),
"COMM": Struct("comm",
SNInt32("pid"),
SNInt32("tid"),
CString("comm")),
"EXIT": fork_exit("exit"),
"THROTTLE": throttle("thottle"),
"UNTHROTTLE": throttle("unthottle"),
"FORK": fork_exit("fork"),
#"READ": read_format(read_format),
"SAMPLE": event(sample_type, read_format),
}),
Anchor("end"),
Padding(lambda ctx: ctx.size - (ctx.end - ctx.start))
)
def perf_event_seq(sample_type, read_format):
return GreedyRange(perf_event(sample_type, read_format))
perf_event_attr_sizes = (64, 72, 80, 96)
perf_event_attr = Struct("perf_event_attr",
Anchor("start"),
Enum(UNInt32("type"),
HARDWARE = 0,
SOFTWARE = 1,
TRACEPOINT = 2,
HW_CACHE = 3,
RAW = 4,
BREAKPOINT = 5),
UNInt32("size"),
UNInt64("config"),
UNInt64("sample_period_freq"),
BitStruct("sample_type",
Flag("ip"),
Flag("tid"),
Flag("time"),
Flag("addr"),
Flag("read"),
Flag("callchain"),
Flag("id"),
Flag("cpu"),
Flag("period"),
Flag("stream_id"),
Flag("raw"),
Flag("branch_stack"),
Flag("regs_user"),
Flag("stack_user"),
Flag("weight"),
Flag("data_src"),
Padding(64 - 16)),
BitStruct("read_format",
Flag("total_time_enabled"),
Flag("total_time_running"),
Flag("id"),
Flag("group"),
Padding(64 - 4)),
Embedded(BitStruct(None,
Flag("disabled"),
Flag("inherit"),
Flag("pinned"),
Flag("exclusive"),
Flag("exclude_user"),
Flag("exclude_kernel"),
Flag("exclude_hv"),
Flag("exclude_idle"),
Flag("mmap"),
Flag("comm"),
Flag("freq"),
Flag("inherit_stat"),
Flag("enable_on_exec"),
Flag("task"),
Flag("watermark"),
BitField("precise_ip", 2),
Flag("mmap_data"),
Flag("sample_id_all"),
Flag("exclude_host"),
Flag("exclude_guest"),
Flag("exclude_callchain_kernel"),
Flag("exclude_callchain_user"),
Padding(41))),
UNInt32("wakeup_events"),
UNInt32("bp_type"),
UNInt64("config1"),
If(lambda ctx: ctx.size >= perf_event_attr_sizes[1],
UNInt64("config2")),
If(lambda ctx: ctx.size >= perf_event_attr_sizes[2],
UNInt64("branch_sample_type")),
If(lambda ctx: ctx.size >= perf_event_attr_sizes[3],
Embedded(Struct(None,
UNInt64("sample_regs_user"),
UNInt32("sample_stack_user")))),
Anchor("end"),
Value("perf_event_attr_size", lambda ctx: ctx.end - ctx.start),
Padding(lambda ctx: ctx.size - ctx.perf_event_attr_size))
# assumes all attributes are the same size
perf_file_attr = Struct("perf_file_attr",
Peek(Embedded(Struct(None, UNInt32("type"), UNInt32("size")))),
Array(lambda ctx: ctx._.size / ctx.size, perf_event_attr))
perf_event_types = Struct("perf_file_attr",
Anchor("here"),
Padding(lambda ctx: ctx._.size))
perf_data = OnDemand(Bytes("perf_data", lambda ctx: ctx.size))
def perf_file_section(name, target):
return Struct(name,
UNInt64("offset"),
UNInt64("size"),
Pointer(lambda ctx: ctx.offset, target))
perf_file = Struct("perf_file_header",
UNInt64("magic"), # XXX
UNInt64("size"),
UNInt64("attr_size"),
perf_file_section("attrs", perf_file_attr),
perf_file_section("data", perf_data),
perf_file_section("event_types", perf_event_types),
BitStruct("adds_features",
Flag("tracing_data"),
Flag("build_id"),
Flag("hostname"),
Flag("osrelease"),
Flag("version"),
Flag("arch"),
Flag("nrcpus"),
Flag("cpudesc"),
Flag("cpuid"),
Flag("total_mem"),
Flag("cmdline"),
Flag("event_desc"),
Flag("cpu_topology"),
Flag("numa_topology"),
Flag("branch_stack"),
Flag("pmu_mappings"),
Flag("group_desc"),
Padding(64 - 17)),
Padding(3 * 8))
def get_events(h):
data = h.data.perf_data.value
# assumes event 0 attributes applies to all samples?
# XXX
ev0 = h.attrs.perf_file_attr.perf_event_attr[0]
assert ev0.size in perf_event_attr_sizes
return perf_event_seq(ev0.sample_type, ev0.read_format).parse(data)
if __name__ == '__main__':
import sys
with open(sys.argv[1], "rb") as f:
h = perf_file.parse_stream(f)
print h
print get_events(h)
next prev parent reply other threads:[~2013-07-19 15:46 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 17:49 [RFC 0/23] perf tool: Add support for multiple data file storage Jiri Olsa
2013-07-17 17:49 ` [PATCH 01/23] perf tools: Use session->fd instead of passing fd as argument Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf session: Use session-> fd " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 02/23] perf tools: Remove data_offset seek as it's not needed Jiri Olsa
2013-07-18 7:27 ` Namhyung Kim
2013-07-18 12:46 ` Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: Remove data_offset seek as it' s " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 03/23] perf tools: Remove attr_offset from perf_header Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 04/23] perf tools: Introduce feat_offset into perf_header Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 05/23] perf tests: Add simple session read/write test Jiri Olsa
2013-07-18 7:46 ` Namhyung Kim
2013-07-18 12:52 ` Jiri Olsa
[not found] ` <20130717193313.GA5127@infradead.org>
2013-07-18 12:52 ` Jiri Olsa
2013-07-18 14:26 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 06/23] perf doc: Add perf data file documentation Jiri Olsa
2013-07-17 19:59 ` Arnaldo Carvalho de Melo
2013-07-18 12:40 ` Jiri Olsa
2013-07-19 15:46 ` Andi Kleen [this message]
2013-07-17 17:49 ` [PATCH 07/23] perf tools: Recognize version number for perf data file Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 08/23] perf tools: Introduce perf data file version CHECK macro Jiri Olsa
[not found] ` <20130717194250.GB5127@infradead.org>
2013-07-18 12:39 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 09/23] perf tools: Introduce swap_features function Jiri Olsa
2013-07-17 17:49 ` [PATCH 10/23] perf tools: Introduce swap_header function Jiri Olsa
2013-07-19 11:33 ` Namhyung Kim
2013-07-22 13:44 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 11/23] perf tools: Separate version 2 specific perf data header bits Jiri Olsa
2013-07-17 17:49 ` [PATCH 12/23] perf tools: Using evlist as a holder for event_desc feature Jiri Olsa
2013-07-17 17:49 ` [PATCH 13/23] perf tools: Introduce perf.data version 3 format Jiri Olsa
2013-07-19 12:06 ` Namhyung Kim
2013-07-22 10:00 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 14/23] perf tools: Add perf data version 3 header swap Jiri Olsa
2013-07-17 17:49 ` [PATCH 15/23] perf tools: Add perf data version 3 header read Jiri Olsa
2013-07-19 12:11 ` Namhyung Kim
2013-07-22 10:02 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 16/23] perf tools: Add perf.data version 3 header write Jiri Olsa
2013-07-17 17:49 ` [PATCH 17/23] perf tools: Get rid of post_processing_offset in record command Jiri Olsa
2013-07-17 17:49 ` [PATCH 18/23] perf tools: Move synthetizing into single function Jiri Olsa
2013-07-19 12:30 ` Namhyung Kim
2013-07-22 10:15 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 19/23] perf tools: Add data object to handle perf data file Jiri Olsa
2013-07-17 17:50 ` [PATCH 20/23] perf tools: Add perf_data_file__open interface to data object Jiri Olsa
2013-07-17 17:50 ` [PATCH 21/23] perf tools: Separating data file properties from session Jiri Olsa
2013-07-17 17:50 ` [PATCH 22/23] perf tools: Add multi file '-M' option for record command Jiri Olsa
2013-07-19 13:02 ` Namhyung Kim
2013-07-22 10:17 ` Jiri Olsa
2013-07-17 17:50 ` [PATCH 23/23] perf tools: Have the process properly sythesized in subsequent data files Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130719154637.GY5643@tassilo.jf.intel.com \
--to=ak@linux.intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome