Skip to content

Commit

Permalink
Add STARTTIME and DURATION parameters. They work only in the CLI mode…
Browse files Browse the repository at this point in the history
… and with PROFILE switch, currently
  • Loading branch information
capehill committed Sep 19, 2019
1 parent c7e7efc commit 4ceaf4c
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 67 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ cannot be profiled either.
- GUI: launch the graphical user interface
- PROFILE: disable function tracing in serial logs but keep profiling stats
- FILTER filename: define a subset of patched functions
- STARTTIME time: set a time in seconds for profiler start
- DURATION time: set a profiling time in seconds

Example 1) glSnoop PROFILE STARTTIME 5 DURATION 10
- profile only
- initialize counters 5 seconds after context creation
- profile for 10 seconds

## Tips

Expand All @@ -52,8 +59,10 @@ PUBLIC DOMAIN

## Thanks

- Kas1e for ideas, testing and AmigaGuide document
- kas1e for ideas, testing and AmigaGuide document
- Mason for icons
- samo79 for ideas
- Hans for ideas
- jabirulo for ideas
- Daniel for ideas

14 changes: 10 additions & 4 deletions gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static Object* objects[OID_Count];
static struct Window* window;
static struct MsgPort* port;

static const ULONG seconds = 1;
static const ULONG micros = 0;

TimerContext timer;

static char* getApplicationName()
{
#define maxPathLen 255
Expand Down Expand Up @@ -326,7 +331,7 @@ static void handle_events(void)
uint32 signal = 0;
IIntuition->GetAttr(WINDOW_SigMask, objects[OID_Window], &signal);

const uint32 timerSignal = timer_signal();
const uint32 timerSignal = timer_signal(&timer);

BOOL running = TRUE;

Expand Down Expand Up @@ -365,10 +370,11 @@ static void handle_events(void)
}

if (wait & timerSignal) {
timer_handle_events();
timer_handle_events(&timer);
if (window) {
refresh_errors();
}
timer_start(&timer, seconds, micros);
}
}
}
Expand All @@ -384,13 +390,13 @@ void run_gui(LONG profiling)

if (objects[OID_Window]) {
if ((window = (struct Window *)IIntuition->IDoMethod(objects[OID_Window], WM_OPEN))) {
timer_start();
timer_start(&timer, seconds, micros);
handle_events();
} else {
puts("Failed to open window");
}

timer_stop();
timer_stop(&timer);

IIntuition->DisposeObject(objects[OID_Window]);
} else {
Expand Down
4 changes: 4 additions & 0 deletions gui.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#ifndef GUI_H
#define GUI_H

#include "timer.h"

#include <exec/types.h>

extern TimerContext timer;

void run_gui(LONG profiling);

#endif
Expand Down
81 changes: 75 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/icon.h>

#include <stdio.h>
#include <string.H>
Expand All @@ -18,16 +19,21 @@ struct Params {
LONG nova;
LONG gui;
LONG profiling;
LONG *startTime;
LONG *duration;
char *filter;
};

static const char* const version __attribute__((used)) = "$VER: " VERSION_STRING DATE "\0";
static const char* const portName = "glSnoop port";
static char* filterFile;
static struct Params params = { 0, 0, 0, 0, NULL };
static struct Params params = { 0, 0, 0, 0, NULL, NULL, NULL };

static struct MsgPort* port;

static ULONG startTime;
static ULONG duration;

static BOOL already_running(void)
{
IExec->Forbid();
Expand Down Expand Up @@ -62,7 +68,9 @@ static BOOL parse_args(void)
{
const char* const enabled = "enabled";
const char* const disabled = "disabled";
const char* const pattern = "OGLES2/S,NOVA/S,GUI/S,PROFILE/S,FILTER/K";
const char* const pattern = "OGLES2/S,NOVA/S,GUI/S,PROFILE/S,STARTTIME/N,DURATION/N,FILTER/K";

// how-to handle both tooltypes and args?

struct RDArgs *result = IDOS->ReadArgs(pattern, (int32 *)&params, NULL);

Expand All @@ -71,6 +79,19 @@ static BOOL parse_args(void)
filterFile = strdup(params.filter);
}

if (params.startTime) {
startTime = *params.startTime;
}

if (params.duration) {
duration = *params.duration;
}

if (startTime > 0 && duration < 1) {
puts("Duration should be > 0 seconds. Forcing to 1 second");
duration = 1;
}

IDOS->FreeArgs(result);
} else {
printf("Error when reading command-line arguments. Known parameters are: %s\n", pattern);
Expand All @@ -88,6 +109,8 @@ static BOOL parse_args(void)
printf(" GUI: [%s]\n", params.gui ? enabled : disabled);
printf(" Tracing mode: [%s]\n", params.profiling ? disabled : enabled);
printf(" Filter file name: [%s]\n", filterFile ? filterFile : disabled);
printf(" Start time: [%lu] seconds\n", startTime);
printf(" Duration: [%lu] seconds\n", duration);
puts("---------------------");

return TRUE;
Expand All @@ -100,7 +123,7 @@ static void install_patches(void)
}

if (params.nova) {
warp3dnova_install_patches();
warp3dnova_install_patches(startTime);
}
}

Expand All @@ -127,12 +150,48 @@ static void remove_patches(void)
ogles2_free();
}

typedef enum ESignalType {
ESignalType_Break,
ESignalType_Timer
} ESignalType;

static ESignalType wait_for_signal()
{
const uint32 timerSig = (startTime > 0) ? timer_signal(&triggerTimer) : 0;
const uint32 wait = IExec->Wait(SIGBREAKF_CTRL_C | timerSig);

if (wait & SIGBREAKF_CTRL_C) {
puts("*** Break ***");
return ESignalType_Break;
}

if (wait & timerSig) {
//puts("*** Timer triggered ***");
timer_handle_events(&triggerTimer);
}

return ESignalType_Timer;
}

static void run(void)
{
if (params.gui) {
run_gui(params.profiling);
} else {
IExec->Wait(SIGBREAKF_CTRL_C);
if (wait_for_signal() == ESignalType_Timer) {
puts("First timer signal - start profiling");

ogles2_start_profiling();
warp3dnova_start_profiling();

timer_start(&triggerTimer, duration, 0);

puts("Waiting...");

wait_for_signal();

puts("Second timer signal - stop profiling");
}
}
}

Expand All @@ -149,10 +208,16 @@ int main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
goto out;
}

if (!timer_init()) {
if (!timer_init(&timer)) {
goto out;
}

if (startTime) {
if (!timer_init(&triggerTimer)) {
goto out;
}
}

create_port();

if (!load_filters(filterFile)) {
Expand Down Expand Up @@ -180,7 +245,11 @@ int main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
free_filters();
free(filterFile);

timer_quit();
if (startTime) {
timer_quit(&triggerTimer);
}

timer_quit(&timer);

logLine("glSnoop exiting");

Expand Down
Loading

0 comments on commit 4ceaf4c

Please sign in to comment.