|
|
|
Adding trace points to NPTL functions
|
PTT must run inside the NPTL,
that is to say,
PTT used an instrumented NPTL,
generated from the original one by adding trace points
in strategic places.
A trace point is made of one or several
events.
Gathering events allows to reduce
the number of calls to the trace mechanim,
and so not to interrupt the traced program too much.
Here is an example, written in pseudo-code,
of the pthread_barrier_wait NPTL routine
with associated trace points:
PTHREAD_BARRIER_WAIT (pthread_barrier_t *barrier) {
result = 0
BARRIER_WAIT_IN, BARRIER_LOCK_REQUIRE, THREAD_STATE_WAIT
TRACE (TR_BARRIER_8, barrier->lock)
wait for barrier to become free and take it
THREAD_STATE_WAKE, BARRIER_LOCK_TAKEN
TRACE (TR_BARRIER_2, barrier->lock)
decrement the number of waited threads
BARRIER_LEFT_DEC
TRACE (TR_BARRIER_9, barrier->left)
if all threads already entered the barrier
wake up all sleeping threads
result = PTHREAD_BARRIER_SERIAL_THREAD (everything all right)
else
BARRIER_LOCK_FREE
TRACE (TR_BARRIER_3, barrier->lock)
free barrier
THREAD_STATE_WAIT_BARRIER
TRACE (TR_BARRIER_14)
put the thread which has just arrived in blocked state
THREAD_STATE_WAKE_BARRIER
TRACE (TR_BARRIER_15)
endif
increment left
if all threads left the barrier
BARRIER_LEFT_INC, BARRIER_LOCK_FREE
TRACE (TR_BARRIER_10, barrier->left)
free barrier
else
BARRIER_LEFT_INC
TRACE (TR_BARRIER_11, barrier->left)
endif
BARRIER_WAIT_OUT
TRACE (TR_BARRIER_12, result)
return result
}
|
We see that some trace points
correspond to one event
(TR_BARRIER_9 -> BARRIER_LEFT_DEC ),
and others gather several events
(TR_BARRIER_8 -> BARRIER_WAIT_IN, BARRIER_LOCK_REQUIRE, THREAD_STATE_WAIT ).
Trace point names are made of 3 parts:
the TR prefix,
the name of the object (from the routine name)
and an ID. We obtain TR_OBJECT_ID .
In the pseudo code,
TRACE (...) represents the call
to the trace function with its arguments.
The first argument is the trace point name.
Other arguments are values like address or id
which describe events with the most useful information.
|
Trace points list
|
Here is the list of all trace points defined by PTT
with the associated events:
TR_INIT
|
START_USER_FUNC
|
TR_FINI
|
END_USER_FUNC
|
TR_BARRIER_1
|
BARRIER_DESTROY_IN, BARRIER_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_BARRIER_2
|
THREAD_STATE_WAKE, BARRIER_LOCK_TAKEN
|
TR_BARRIER_3
|
BARRIER_LOCK_FREE
|
TR_BARRIER_4
|
BARRIER_DESTROY_OUT
|
TR_BARRIER_5
|
BARRIER_INIT_IN
|
TR_BARRIER_6
|
BARRIER_INIT_OUT
|
TR_BARRIER_7
|
BARRIER_INIT, BARRIER_INIT_OUT
|
TR_BARRIER_8
|
BARRIER_WAIT_IN, BARRIER_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_BARRIER_9
|
BARRIER_LEFT_DEC
|
TR_BARRIER_10
|
BARRIER_LEFT_INC, BARRIER_LOCK_FREE
|
TR_BARRIER_11
|
BARRIER_LEFT_INC
|
TR_BARRIER_12
|
BARRIER_WAIT_OUT
|
TR_BARRIER_13
|
BARRIER_DESTROY
|
TR_BARRIER_14
|
THREAD_STATE_WAIT_BARRIER
|
TR_BARRIER_15
|
THREAD_STATE_WAKE_BARRIER
|
TR_COND_1
|
COND_DESTROY_IN, COND_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_COND_2
|
THREAD_STATE_WAKE, COND_LOCK_TAKEN
|
TR_COND_3
|
COND_LOCK_FREE
|
TR_COND_4
|
COND_DESTROY_OUT
|
TR_COND_5
|
COND_TOTAL_SEQ_SET
|
TR_COND_6
|
THREAD_STATE_WAKE, COND_LOCK_REQUIRE
|
TR_COND_7
|
COND_LOCK_TAKEN
|
TR_COND_8
|
COND_DESTROY, COND_DESTROY_OUT
|
TR_COND_9
|
COND_INIT_IN
|
TR_COND_10
|
COND_INIT, COND_INIT_OUT
|
TR_COND_11
|
COND_WAIT_IN, COND_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_COND_12
|
COND_WAIT_OUT
|
TR_COND_13
|
COND_MUTEX_FREE
|
TR_COND_14
|
COND_TOTAL_SEQ_INC
|
TR_COND_15
|
COND_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_COND_16
|
COND_MUTEX_REQUIRE
|
TR_COND_17
|
COND_MUTEX_TAKEN, COND_WAIT_OUT
|
TR_COND_18
|
COND_BROAD_IN, COND_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_COND_19
|
COND_BROAD_SEQ_INC, COND_LOCK_FREE
|
TR_COND_20
|
COND_BROAD_OUT
|
TR_COND_21
|
COND_SIGNAL_IN, COND_LOCK_REQUIRE, THREAD_STATE_WAIT
|
TR_COND_22
|
COND_SIGNAL_OUT
|
TR_COND_23
|
THREAD_STATE_WAIT_COND
|
TR_COND_24
|
THREAD_STATE_WAIT_WAIT
|
TR_MUTEX_1
|
MUTEX_DESTROY_IN
|
TR_MUTEX_2
|
MUTEX_DESTROY_OUT
|
TR_MUTEX_3
|
MUTEX_DESTROY, MUTEX_DESTROY_OUT
|
TR_MUTEX_4
|
MUTEX_INIT_IN
|
TR_MUTEX_5
|
MUTEX_INIT_OUT
|
TR_MUTEX_6
|
MUTEX_INIT, MUTEX_INIT_OUT
|
TR_MUTEX_7
|
MUTEX_LOCK_IN
|
TR_MUTEX_8
|
MUTEX_LOCK_OUT
|
TR_MUTEX_9
|
MUTEX_COUNT_INC, MUTEX_LOCK_OUT
|
TR_MUTEX_10
|
MUTEX_STATE_REQUIRE, THREAD_STATE_WAIT_MUTEX
|
TR_MUTEX_11
|
THREAD_STATE_WAKE_MUTEX
|
TR_MUTEX_12
|
MUTEX_COUNT_INC
|
TR_MUTEX_13
|
MUTEX_OWNER_CHANGE, MUTEX_LOCK_OUT
|
TR_MUTEX_14
|
MUTEX_UNLOCK_IN
|
TR_MUTEX_15
|
MUTEX_UNLOCK_OUT
|
TR_MUTEX_16
|
MUTEX_COUNT_DEC, MUTEX_UNLOCK_OUT
|
TR_MUTEX_17
|
MUTEX_OWNER_CHANGE
|
TR_MUTEX_18
|
MUTEX_STATE_FREE
|
TR_THREAD_1
|
THREAD_STATE_DEAD
|
TR_THREAD_2
|
THREAD_STATE_WAIT
|
TR_THREAD_3
|
THREAD_STATE_WAKE
|
TR_THREAD_4
|
THREAD_CANCEL_IN
|
TR_THREAD_5
|
THREAD_CANCEL_OUT
|
TR_THREAD_6
|
THREAD_CANCEL_PROG
|
TR_THREAD_7
|
THREAD_STATE_CANCEL, THREAD_CANCEL_OUT
|
TR_THREAD_8
|
THREAD_CREATE_IN
|
TR_THREAD_9
|
THREAD_CREATE_OUT
|
TR_THREAD_10
|
THREAD_SET_PD
|
TR_THREAD_11
|
THREAD_INIT, THREAD_DETACH, THREAD_CREATE_OUT
|
TR_THREAD_12
|
THREAD_INIT, THREAD_CREATE_OUT
|
TR_THREAD_13
|
THREAD_JOIN_IN
|
TR_THREAD_14
|
THREAD_JOIN_OUT
|
TR_THREAD_15
|
THREAD_STATE_WAKE, THREAD_JOIN
|
TR_FORK
|
PROG_FORK
|
TR_SEM_1
|
SEM_INIT_IN
|
TR_SEM_2
|
SEM_INIT_OUT
|
TR_SEM_3
|
SEM_INIT, SEM_INIT_OUT
|
TR_SEM_4
|
SEM_DESTROY_IN, SEM_DESTROY, SEM_DESTROY_OUT
|
TR_SEM_5
|
SEM_POST_IN, SEM_COUNT_INC
|
TR_SEM_6
|
SEM_POST_OUT
|
TR_SEM_7
|
SEM_WAIT_IN
|
TR_SEM_8
|
SEM_COUNT_DEC, SEM_WAIT_OUT
|
TR_SEM_9
|
SEM_WAIT_OUT
|
TR_SEM_10
|
SEM_COUNT_DEC, SEM_TRYWAIT_OUT
|
TR_SEM_11
|
SEM_TRYWAIT_OUT
|
TR_SEM_12
|
SEM_TRYWAIT_IN
|
TR_SEM_13
|
SEM_CLOSE_IN, SEM_MAPPINGSLOCK_REQUIRE
|
TR_SEM_14
|
SEM_MAPPINGSLOCK_TAKEN
|
TR_SEM_15
|
SEM_MAPPINGSLOCK_FREE, SEM_CLOSE_OUT
|
TR_SEM_16
|
SEM_REFCOUNT_DEC
|
TR_SEM_17
|
SEM_DESTROY
|
TR_SEM_18
|
SEM_MAPPINGSLOCK_REQUIRE
|
TR_SEM_19
|
SEM_MAPPINGSLOCK_FREE
|
TR_SEM_20
|
SEM_REFCOUNT_INC
|
TR_SEM_21
|
SEM_INIT
|
TR_SEM_22
|
SEM_OPEN_IN
|
TR_SEM_23
|
SEM_OPEN_OUT
|
TR_SEM_24
|
SEM_UNLINK_IN
|
TR_SEM_25
|
SEM_UNLINK_OUT
|
TR_SEM_26
|
SEM_OPEN_CREATE
|
TR_SEM_27
|
THREAD_STATE_WAIT_SEM
|
TR_SEM_28
|
THREAD_STATE_WAKE_SEM
|
|
|
|
|