Hi

I'm trying to use dtrace speculation in order to avoid interleaving
trace messages by different threads.  I know that this is not what the
speculation mechanism was intended for, so I wanted to ask whether what
I'm doing is safe, and whether there is a better way to achieve the same
result.

In particular, suppose that I have two different function calls that I'm
monitoring, say foo() and bar().  Each thread is executing a sequence of
foo() calls followed by a single bar() call, and may execute multiple
such sequences.  In the dtrace script, we print each sequence with a
message for each invocation of foo() or bar(), e.g.:

pid$target::foo:entry
{
 printf("in sequence, params: %d %d", arg0, arg1);
}

pid$target::bar:entry
{
 printf("End sequence, param: %d", arg0);
}


My goal is to avoid intermixing printouts that correspond to different
sequences by different threads.  That is, I would like all printouts
of a sequence of foo() and bar() calls by a thread to be printed
together.  (I'm using the Java DTrace API to analyze these printouts,
and the java program is much simpler if it doesn't need to deal with
multiple on-going sequences.)

My solution is to allocate a speculation buffer for each such sequence
(storing it in a thread local variable), execute the above printouts
speculatively into the buffer, and only commit the buffer when bar is
called.

My questions:

- Is it safe to assume that when two threads are concurrently committing
 two speculation buffers, then each commit operation is atomic with
 respect to the other? That is, print messages in one buffer will not
 be intermixed with messages in the other buffer?

- Do you know of a better way to achieve the same result?
 It would be trivial to achieve this goal by building a thread-local
 string concatenating all messages that needed to be printed out for a
 sequence, and print it out when bar is called, but AFAIK DTrace does
 not have an sprintf function, and I do need the messages to be
 formatted in a certain way identified by the java front-end...

Thanks,
Yossi



_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

Reply via email to