Skip to contentSkip to conversation

perf smapling

DISCUSSION sahil aggarwal 3 participants 17 messages Mar 29, 2015 – Apr 8, 2015 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hi all

I am beginner to the perf API. Can someone direct me to the example of reading ring buffer using mmap.?

Thank you
Regards

#1 lore raw

Hi,

While not ready to prime time yet, I attach a tar.gz of a program that does just that.

I hope to make it an official project soon, but in the mean time, I think it can help you understand how to read the ring buffer.

Quoted 12 lines · sahil aggarwal

Hi all

I am beginner to the perf API. Can someone direct me to the example of reading ring buffer using mmap.?

Thank you
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to a message not in the archive

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

#7 lore raw

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 36 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

#8 lore raw

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type" field in perf_event_header.? And, the the record struct will be same as given in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 44 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 36 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

#9 lore raw

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) {
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 56 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type" field in perf_event_header.? And, the the record struct will be same as given in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 44 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 36 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 125 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) {
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 56 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type" field in perf_event_header.? And, the the record struct will be same as given in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 44 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 36 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

Quoted 146 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 125 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}
{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) {
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 56 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type" field in perf_event_header.? And, the the record struct will be same as given in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 44 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 36 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
In reply to a message not in the archive

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

** it gives me some ID when i print stream_id

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw
In reply to sahil aggarwal

You can't && event ids in config, it'll simply give a different event. You need to open a stream per tracing event.

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw

Yeah you are right. And, there seem to be problem when i declare 'struct perf_event_attr'
at run time. Is it know issue.?
It gives me -EINVAL(Invalid Argument).

Run Time:
perf_event_open(0x22a20b8, 0, 0xffffffff, 0xffffffff, 0) = -1 EINVAL (Invalid argument)

Compile Time:
perf_event_open(0x7fffa242ee50, 0xffffffff, 0x1, 0xffffffff, 0) = 6

Quoted 197 lines · Elazar Leibovich

You can't && event ids in config, it'll simply give a different event. You need to open a stream per tracing event.

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

Sorry for that dumb ques. Problem was somewhere else.

Quoted 211 lines · sahil aggarwal

Yeah you are right. And, there seem to be problem when i declare 'struct perf_event_attr'
at run time. Is it know issue.?
It gives me -EINVAL(Invalid Argument).

Run Time:
perf_event_open(0x22a20b8, 0, 0xffffffff, 0xffffffff, 0) = -1 EINVAL (Invalid argument)

Compile Time:
perf_event_open(0x7fffa242ee50, 0xffffffff, 0x1, 0xffffffff, 0) = 6

Quoted 197 lines · Elazar Leibovich

You can't && event ids in config, it'll simply give a different event. You need to open a stream per tracing event.

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#19 lore raw

Hey Elazar,

In the example you sent me, if i set :
attr->inherit=1

Then,

 mmap(mmap_pages->wrap_base + page_size,             \
            mmap_len - page_size, PROT_READ |               \
            PROT_WRITE, MAP_FIXED | MAP_SHARED,   \
             fd, 0);

call fails with "Invalid argument".

Happens only if inherit is set. Do i need to set any other flag too.?

Thanks
Regards

Quoted 214 lines · sahil aggarwal

Sorry for that dumb ques. Problem was somewhere else.

Quoted 211 lines · sahil aggarwal

Yeah you are right. And, there seem to be problem when i declare 'struct perf_event_attr'
at run time. Is it know issue.?
It gives me -EINVAL(Invalid Argument).

Run Time:
perf_event_open(0x22a20b8, 0, 0xffffffff, 0xffffffff, 0) = -1 EINVAL (Invalid argument)

Compile Time:
perf_event_open(0x7fffa242ee50, 0xffffffff, 0x1, 0xffffffff, 0) = 6

Quoted 197 lines · Elazar Leibovich

You can't && event ids in config, it'll simply give a different event. You need to open a stream per tracing event.

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used mmap_pages->wrap_base.? And, instead of allocating (2^n)+1 pages you allocate (2^n)+2 pages, why so.? wrap_base points to (2^n)+2 pages and base points to (2^n)+1 pages, what is use of wrap_base.? I tried reading perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#20 lore raw

Digging a bit deep i found that if

pid > 0 && cpu == -1

then only mmap during attr->inherit=1 fails. what i could be missing.?

Quoted 234 lines · sahil aggarwal

Hey Elazar,

In the example you sent me, if i set :
attr->inherit=1

Then,

 mmap(mmap_pages->wrap_base + page_size,             \
            mmap_len - page_size, PROT_READ |               \
            PROT_WRITE, MAP_FIXED | MAP_SHARED,   \
             fd, 0);

call fails with "Invalid argument".

Happens only if inherit is set. Do i need to set any other flag too.?

Thanks
Regards

Quoted 214 lines · sahil aggarwal

Sorry for that dumb ques. Problem was somewhere else.

Quoted 211 lines · sahil aggarwal

Yeah you are right. And, there seem to be problem when i declare 'struct perf_event_attr'
at run time. Is it know issue.?
It gives me -EINVAL(Invalid Argument).

Run Time:
perf_event_open(0x22a20b8, 0, 0xffffffff, 0xffffffff, 0) = -1 EINVAL (Invalid argument)

Compile Time:
perf_event_open(0x7fffa242ee50, 0xffffffff, 0x1, 0xffffffff, 0) = 6

Quoted 197 lines · Elazar Leibovich

You can't && event ids in config, it'll simply give a different event. You need to open a stream per tracing event.

Quoted 193 lines · sahil aggarwal

If i enable multiple tracepoints, say:

type = PERF_TYPE_TRACEPOINT
config = 87 | 402 (sched/sched_switch && syscalls/sys_enter_open)
sample_type = PERF_SAMPLE_TIME |

                         PERF_SAMPLE_RAW       |
                         PERF_SAMPLE_TID          |
                         PERF_SAMPLE_STREAM_ID ;

It gives me some ID when i print sample_id(i thought it will print config value). But how i can connect this ID with my type of event (sched_switch or sys_enter_open). .?

Quoted 179 lines · sahil aggarwal

No i didn't give it a shot yet but code was very helpful. And, the raw data form was same as struct defined for event in format file(syscalls/sys_enter_open/format).

Quoted 172 lines · Elazar Leibovich

Yes, this is correct, as far as I can tell, when you create a perf_event for every tracepoint event.

I personally created a separate thread for each trace point, since I found this approach simpler, but it is certainly possible to use a single thread + select from all perf_event_open file descriptor.

BTW, did you manage to experiment with perf using the tool I attached?

Quoted 159 lines · sahil aggarwal

Hi Elazar

Finally i am able to make small prototype to enable tracepoints. :)

One more thing, is it possible to enable multiple tracepoints through 1 thread and
while parsing output find out to which tracepoint that raw data belongs.?

Or i would have to create separate thread for each tracepoint. ?

Man page says:
Set config to one of the following:

          .........

So i am assuming i will have to create separate thread for each event.

Thanks a lot.

Quoted 137 lines · Elazar Leibovich

Look at the man page, you should set the type to PERF_TYPE_TRACEPOINT and set the config to the event id.

On my system, sys_enter_open event id is 455

$ sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_open/id
455

Add PERF_SAMPLE_RAW to the sample_type.

BTW
You can compile the tar.gz I sent and echo JSON in the attr format to it, it'll print back perf data in json format. Easier to experiment with perf_event_open API than writing a C program.

For example

$ make
$ sudo ./perf2 <<EOF
{
  "attr": {
    "sample_type": [
      "PERF_SAMPLE_IP",
      "PERF_SAMPLE_RAW"
    ],
    "wakeup_events": 1,
    "config": 455,
    "sample_period": 1,
    "type": "PERF_TYPE_TRACEPOINT"
  }
}
EOF

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,101,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-64,112,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-112,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,-32,70,75,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

{"type":"PERF_RECORD_SAMPLE","misc":"PERF_RECORD_MISC_USER","sample":{"ip":"7f4f3625263d","data":[-57,1,0,0,7,11,0,0,2,0,0,0,0,0,0,0,0,-99,26,-19,-1,127,0,0,0,0,0,0,0,0,0,0,-74,1,0,0,0,0,0,0,0,0,0,0]}}
...

What is the raw data? Depends on the event. For sys_enter/exit it is struct syscall_trace_enter/exit.

http://osxr.org/linux/source/kernel/trace/trace.h#0095

struct trace_entry {
     unsigned short      type;
     unsigned char       flags;
     unsigned char       preempt_count;
     int         pid;
};
struct syscall_trace_enter {
    struct trace_entry  ent;
    int         nr;
    unsigned long       args[];
};

How did I know that? I followed the kernel logic here:

http://osxr.org/linux/source/kernel/trace/trace_syscalls.c#0636
static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{
...
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, ...);
...
}

Note that indeed after short+char+char+int we have 2, the open syscall number in all event's raw data.

Quoted 61 lines · sahil aggarwal

Actually i need most of the sampling around PERF_TYPE_TRACEPOINT, so if i enable tracepoint "syscalls/sys_enter_open/" what will be the "type"
field in perf_event_header.? And, the the record struct will be same as given
in "syscalls/sys_enter_open/format" .?

Thanks

Quoted 45 lines · sahil aggarwal

Yeah that was clear enough.
Thanks a lot. Your code is of great help.

Regards
Sahil

Quoted 37 lines · Elazar Leibovich

I wanted to ensure the user always see contiguous array of data from the ring buffer.

The last piece of data, say "abcde" could wrap around in the ring buffer and appear like:

[de... ...abc]

I wanted the user to see a contigious array of the form [abcde].

So in the case I'm having input that wrap around, I'll simply copy it to the first buffer

[wrap_buffer][de.. ...abc]
would become
[ abc][de... ...abc]

And then I'll the user pointer to the leftmost "a", and he'll see "abcde" without knowing he's handling a ring buffer.

Let me know if I was clear enough.

Quoted 13 lines · sahil aggarwal

Hi Elazar

Can you help me understand why you have used
mmap_pages->wrap_base.? And, instead of allocating
(2^n)+1 pages you allocate (2^n)+2 pages, why so.?
wrap_base points to (2^n)+2 pages and base points to
(2^n)+1 pages, what is use of wrap_base.? I tried reading
perf source too, there it seems they use (2^n)+1 pages only.

Thanks
Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html