How about:Thanks, but I think the following one is more suitable.
CONFIG_TRACER_MAX_TRACE makes a generic snapshot feature available to
all tracers. (Some tracers, such as "irqsoff" or "wakeup", use their own
internal snapshot implementation.)
(Some tracers, such as "irqsoff" or "wakeup", already use the snapshot
implementation internally)
This implies that setting flag is a NOP for them, rather than "if you
take a snapshot, they'll stomp all over the buffer".
(Query: do you have to free the buffer after taking a snapshot below?)No, we don't always need to free the buffer, although we can free it
when the snapshot becomes unnecessary. We can also reuse the buffer if
we'd like to take the next snapshot.
(I'll add this description.)
Actually I was worried about the lifetime rules for the buffer (when
does it need to be disposed of, and who is responsible for doing so?)
but it looks like ftrace only allows one trace to be going on in the
entire system at any given time, so all this context is kernel global
anyway...
Buffer allocation is a separate action because taking a snapshot is a
low-latency operation that should never fail. Got it.
But again, why couldn't open() do one and read() (from position 0) do
the other? And then if you wanted to take another snapshot you could
lseek() back to 0...
*shrug* I suppose the way you have it works. Just curious.
Why is there only _one_ snapshot buffer?Because of easy reviewing, I've decided to implement step by step. So
this patch just provide "only one" spare buffer. However, I got some
feedback for multiple snapshot at LinuxCon Japan 2012. So I may extend
this feature.
The implementation can change all you like after the code goes in, but
you really have to get the API right because you're going to be stuck
supporting it <pinkypie>FOREVER</pinkypie>.
If the current_tracer is a special tracer such as irqsoff,Is the order significant here?+Here is an example of using the snapshot feature.
+
+ # echo nop > current_tracer
+ # echo 1 > snapshot_enabled
+ # echo 1 > events/sched/enable
+ [...]
+ # echo 1 > snapshot_pipe
snapshot_enabled can't be set to 1. So current_tracer has to be
configured to appropriate tracer in the first place.
But they aren't compatible anyway? (So presumably this call failing is
part of the enforcement mechanism by which the incompatible combination
is disallowed?)
What happens if you do it the other way around? (echo 1 >
snapshot_enabled and then echo irqsoff > current_tracer)?
I'm guessing the reason buffer switching was described above is toYes. Actually, this snapshot feature only swaps the current buffer and
explain that taking a snapshot blanks the current trace history since
you switch to an empty buffer?
the spare buffer. Now I'm considering to call it "swap" instead of
"snapshot"...
I'm all for clarifying what it does, but we already have a subsystem
called "swap" (swap partitions, swapon/swapoff) so that name isn't
necessarily less confusing.
The size of two buffers is same because this is swap.
So the new one is also buffer_size_kb?
Out of curiosity, what happens if you go:
echo nop > current_tracer
echo 1 > snapshot_enabled
echo 64 > buffer_size_kb
(Techncially current_tracer is still nop...)
The reason of the separated operations is to swap two buffers
immediately without fail. if opening snapshot_pipe allocates a buffer,
we need a special userspace command to realize that.
Um, cat can open a file? I don't understand.
If you need a delay between open and read, you can do that from the
command line with something like:
(read -n 1 < /dev/tty; cat > ~/walrus.txt) < /path/to/thingy
I dunno if that's a good idea, I'm just trying to understand the design
here...