Skip to content

Commit

Permalink
altrace: Bulk of the work on tracking state changes.
Browse files Browse the repository at this point in the history
Recording now wraps buffers and sources, too, and tracks most things through
this mechanism. State changes in OpenAL are pretty minimal and lack a lot
of side effects. The only things we don't track right now are things that
change outside of an entry point: ALC_CONNECTED and ALC_CAPTURE_SAMPLES, plus
the things that might be happening to playing sources (offsets, play state,
buffers queued/processed) when the app hasn't referenced a specific source
recently.

Those things will take more elbow grease in the recorder, but I think they
can function within the new bits added to the file format without further
changes.
  • Loading branch information
icculus committed Jul 16, 2019
1 parent 992649b commit 96b02d8
Show file tree
Hide file tree
Showing 3 changed files with 1,028 additions and 65 deletions.
10 changes: 10 additions & 0 deletions altrace/altrace_common.h
Expand Up @@ -95,6 +95,16 @@ typedef enum
ALEE_ALERROR_TRIGGERED,
ALEE_ALCERROR_TRIGGERED,
ALEE_NEW_CALLSTACK_SYMS,
ALEE_CONTEXT_STATE_CHANGED_ENUM,
ALEE_CONTEXT_STATE_CHANGED_FLOAT,
ALEE_LISTENER_STATE_CHANGED_FLOATV,
ALEE_SOURCE_STATE_CHANGED_BOOL,
ALEE_SOURCE_STATE_CHANGED_ENUM,
ALEE_SOURCE_STATE_CHANGED_INT,
ALEE_SOURCE_STATE_CHANGED_UINT,
ALEE_SOURCE_STATE_CHANGED_FLOAT,
ALEE_SOURCE_STATE_CHANGED_FLOAT3,
ALEE_BUFFER_STATE_CHANGED_INT,
#define ENTRYPOINT(ret,name,params,args) ALEE_##name,
#include "altrace_entrypoints.h"
ALEE_MAX
Expand Down
188 changes: 186 additions & 2 deletions altrace/altrace_playback.c
Expand Up @@ -11,6 +11,8 @@

static int dump_log = 1;
static int dump_callers = 0;
static int dump_state_changes = 0;
static int dump_errors = 0;
static int run_log = 0;

static int trace_scope = 0;
Expand Down Expand Up @@ -575,8 +577,17 @@ static void dump_alcCaptureOpenDevice(void)
const ALCenum format = IO_ALCENUM();
const ALCsizei buffersize = IO_ALSIZEI();
ALCdevice *retval = (ALCdevice *) IO_PTR();
const ALint major_version = retval ? IO_INT32() : 0;
const ALint minor_version = retval ? IO_INT32() : 0;
const ALCchar *devspec = (const ALCchar *) (retval ? IO_STRING() : NULL);
const ALCchar *extensions = (const ALCchar *) (retval ? IO_STRING() : NULL);

if (dump_log) { printf("(%s, %u, %s, %u) => %p\n", litString(devicename), (uint) frequency, alcenumString(format), (uint) buffersize, retval); }

if (dump_state_changes) {
printf("<<< CAPTURE DEVICE STATE: alc_version=%d.%d device_specifier=%s extensions=%s >>>\n", (int) major_version, (int) minor_version, litString(devspec), litString(extensions));
}

if (run_log) {
ALCdevice *dev = REAL_alcCaptureOpenDevice(devicename, frequency, format, buffersize);
if (!dev && retval) {
Expand Down Expand Up @@ -614,8 +625,17 @@ static void dump_alcOpenDevice(void)
IO_START(alcOpenDevice);
const ALCchar *devicename = IO_STRING();
ALCdevice *retval = (ALCdevice *) IO_PTR();
const ALint major_version = retval ? IO_INT32() : 0;
const ALint minor_version = retval ? IO_INT32() : 0;
const ALCchar *devspec = (const ALCchar *) (retval ? IO_STRING() : NULL);
const ALCchar *extensions = (const ALCchar *) (retval ? IO_STRING() : NULL);

if (dump_log) { printf("(%s) => %p\n", litString(devicename), retval); }

if (dump_state_changes) {
printf("<<< PLAYBACK DEVICE STATE: alc_version=%d.%d device_specifier=%s extensions=%s >>>\n", (int) major_version, (int) minor_version, litString(devspec), litString(extensions));
}

if (run_log) {
ALCdevice *dev = REAL_alcOpenDevice(devicename);
if (!dev && retval) {
Expand Down Expand Up @@ -2204,7 +2224,7 @@ static void dump_alcTraceContextLabel(void)
static void dump_al_error_event(void)
{
const ALenum err = IO_ENUM();
if (dump_log) {
if (dump_errors) {
printf("<<< AL ERROR SET HERE: %s >>>\n", alenumString(err));
}
}
Expand All @@ -2213,7 +2233,7 @@ static void dump_alc_error_event(void)
{
ALCdevice *device = (ALCdevice *) IO_PTR();
const ALCenum err = IO_ALCENUM();
if (dump_log) {
if (dump_errors) {
printf("<<< ALC ERROR SET HERE: device=%p %s >>>\n", device, alcenumString(err));
}
}
Expand All @@ -2234,6 +2254,122 @@ static void dump_callstack_syms_event(void)
}
}

static void dump_context_state_changed_enum(void)
{
void *ctx = IO_PTR();
const ALenum param = IO_ENUM();
const ALenum newval = IO_ENUM();
if (dump_state_changes) {
printf("<<< CONTEXT STATE CHANGE: ctx=%p param=%s value=%s >>>\n", ctx, alenumString(param), alenumString(newval));
}
}

static void dump_context_state_changed_float(void)
{
void *ctx = IO_PTR();
const ALenum param = IO_ENUM();
const ALfloat newval = IO_FLOAT();
if (dump_state_changes) {
printf("<<< CONTEXT STATE CHANGE: ctx=%p param=%s value=%f >>>\n", ctx, alenumString(param), newval);
}
}

static void dump_listener_state_changed_floatv(void)
{
void *ctx = IO_PTR();
const ALenum param = IO_ENUM();
const int32 numfloats = IO_INT32();
int32 i;

if (dump_state_changes) {
printf("<<< LISTENER STATE CHANGE: ctx=%p param=%s values={", ctx, alenumString(param));
}

for (i = 0; i < numfloats; i++) {
const ALfloat newval = IO_FLOAT();
if (dump_state_changes) {
printf("%s %f", i > 0 ? "," : "", newval);
}
}

if (dump_state_changes) {
printf("%s} >>>\n", numfloats > 0 ? " " : "");
}
}

static void dump_source_state_changed_bool(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALboolean newval = IO_BOOLEAN();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value=%s >>>\n", (uint) name, alenumString(param), alboolString(newval));
}
}

static void dump_source_state_changed_enum(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALenum newval = IO_ENUM();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value=%s >>>\n", (uint) name, alenumString(param), alenumString(newval));
}
}

static void dump_source_state_changed_int(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALint newval = IO_INT32();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value=%d >>>\n", (uint) name, alenumString(param), (int) newval);
}
}

static void dump_source_state_changed_uint(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALuint newval = IO_UINT32();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value=%u >>>\n", (uint) name, alenumString(param), (uint) newval);
}
}

static void dump_source_state_changed_float(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALfloat newval = IO_FLOAT();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value=%f >>>\n", (uint) name, alenumString(param), newval);
}
}

static void dump_source_state_changed_float3(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALfloat newval1 = IO_FLOAT();
const ALfloat newval2 = IO_FLOAT();
const ALfloat newval3 = IO_FLOAT();
if (dump_state_changes) {
printf("<<< SOURCE STATE CHANGE: name=%u param=%s value={ %f, %f, %f } >>>\n", (uint) name, alenumString(param), newval1, newval2, newval3);
}
}

static void dump_buffer_state_changed_int(void)
{
const ALuint name = IO_UINT32();
const ALenum param = IO_ENUM();
const ALint newval = IO_INT32();
if (dump_state_changes) {
printf("<<< BUFFER STATE CHANGE: name=%u param=%s value=%d >>>\n", (uint) name, alenumString(param), (int) newval);
}
}


static void process_log(void)
{
int eos = 0;
Expand Down Expand Up @@ -2261,6 +2397,46 @@ static void process_log(void)
dump_alc_error_event();
break;

case ALEE_CONTEXT_STATE_CHANGED_ENUM:
dump_context_state_changed_enum();
break;

case ALEE_CONTEXT_STATE_CHANGED_FLOAT:
dump_context_state_changed_float();
break;

case ALEE_LISTENER_STATE_CHANGED_FLOATV:
dump_listener_state_changed_floatv();
break;

case ALEE_SOURCE_STATE_CHANGED_BOOL:
dump_source_state_changed_bool();
break;

case ALEE_SOURCE_STATE_CHANGED_ENUM:
dump_source_state_changed_enum();
break;

case ALEE_SOURCE_STATE_CHANGED_INT:
dump_source_state_changed_int();
break;

case ALEE_SOURCE_STATE_CHANGED_UINT:
dump_source_state_changed_uint();
break;

case ALEE_SOURCE_STATE_CHANGED_FLOAT:
dump_source_state_changed_float();
break;

case ALEE_SOURCE_STATE_CHANGED_FLOAT3:
dump_source_state_changed_float3();
break;

case ALEE_BUFFER_STATE_CHANGED_INT:
dump_buffer_state_changed_int();
break;

case ALEE_EOS:
if (dump_log) { printf("\n<<< END OF LOG FILE >>>\n"); }
eos = 1;
Expand Down Expand Up @@ -2290,6 +2466,14 @@ int main(int argc, char **argv)
dump_callers = 1;
} else if (strcmp(arg, "--no-dump-callers") == 0) {
dump_callers = 0;
} else if (strcmp(arg, "--dump-errors") == 0) {
dump_errors = 1;
} else if (strcmp(arg, "--no-dump-errors") == 0) {
dump_errors = 0;
} else if (strcmp(arg, "--dump-state-changes") == 0) {
dump_state_changes = 1;
} else if (strcmp(arg, "--no-dump-state-changes") == 0) {
dump_state_changes = 0;
} else if (strcmp(arg, "--run") == 0) {
run_log = 1;
} else if (strcmp(arg, "--no-run") == 0) {
Expand Down

0 comments on commit 96b02d8

Please sign in to comment.