Skip to content

Commit

Permalink
re-introduce cycles for stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 23, 2024
1 parent ea300ff commit 8ae95b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/Flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ void ParseFlags(const WCHAR* cmdLine, Flags& i) {
if (arg == Arg::StressTest) {
// -stress-test <file or dir path> [<file filter>] [<page/file range(s)>] [<cycle
// count>x]
// e.g. -stress-test file.pdf for rendering file.pdf
// e.g. -stress-test file.pdf 25x for rendering file.pdf 25 times
// -stress-test file.pdf 1-3 render only pages 1, 2 and 3 of file.pdf
// -stress-test dir 301- render all files in dir, skipping first 300
// -stress-test dir 301- 2x render all files in dir twice, skipping first 300
// -stress-test dir *.pdf;*.xps render all files in dir that are either PDF or XPS
i.stressTestPath = str::Dup(param);
const char* s = args.AdditionalParam(1);
Expand All @@ -607,6 +607,11 @@ void ParseFlags(const WCHAR* cmdLine, Flags& i) {
i.stressTestRanges = str::Dup(args.EatParam());
s = args.AdditionalParam(1);
}
int num;
if (s && str::Parse(s, "%dx%$", &num) && num > 0) {
i.stressTestCycles = num;
args.EatParam();
}
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct Flags {
// nullptr is equivalent to "*" (i.e. all files)
char* stressTestFilter = nullptr;
char* stressTestRanges = nullptr;
int stressTestCycles = 1;
int stressParallelCount = 1;
bool stressRandomizeFiles = false;
int stressTestMax = 0;
Expand Down
41 changes: 27 additions & 14 deletions src/StressTesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,19 @@ static void MakeRandomSelection(MainWindow* win, int pageNo) {

// encapsulates the logic of getting the next file to test, so
// that we can implement different strategies
class TestFileProvider {
public:
struct TestFileProvider {
virtual ~TestFileProvider() {
}
// returns path of the next file to test or nullptr if done (caller needs to free() the result)
virtual TempStr NextFile() = 0;
virtual void Restart() = 0;
virtual int GetFilesCount() = 0;
};

class FilesProvider : public TestFileProvider {
struct FilesProvider : TestFileProvider {
StrVec files;
int provided = 0;

public:
explicit FilesProvider(const char* path) {
files.Append(path);
provided = 0;
Expand Down Expand Up @@ -334,9 +333,13 @@ class FilesProvider : public TestFileProvider {
TempStr res = files.At(provided++);
return res;
}

void Restart() override {
provided = 0;
}
};

class DirFileProviderAsync : public TestFileProvider {
struct DirFileProviderAsync : TestFileProvider {
StrQueue queue;
AutoFreeStr startDir;
AutoFreeStr fileFilter;
Expand All @@ -347,21 +350,25 @@ class DirFileProviderAsync : public TestFileProvider {

AtomicInt nFiles;

public:
DirFileProviderAsync(const char* path, const char* filter, int max = 0, bool random = false) {
startDir.SetCopy(path);
if (filter && !str::Eq(filter, "*")) {
fileFilter.SetCopy(filter);
}
this->max = max;
this->random = random;
StartDirTraverseAsync(&queue, path, true);
StartDirTraverseAsync(&queue, startDir.CStr(), true);
}
~DirFileProviderAsync() override = default;
TempStr NextFile() override;
int GetFilesCount() override {
return queue.Size();
}

virtual void Restart() override {
nFiles.Set(0);
StartDirTraverseAsync(&queue, startDir.CStr(), true);
}
};

TempStr DirFileProviderAsync::NextFile() {
Expand Down Expand Up @@ -414,7 +421,9 @@ struct StressTest {
int nSlowPages = 0;

SYSTEMTIME stressStartTime{};
int cycles = 1;
Vec<PageRange> pageRanges;
// range of files to render (files get a new index when going through several cycles)
Vec<PageRange> fileRanges;
int fileIndex = 0;
bool gotToc = false;
Expand Down Expand Up @@ -450,10 +459,11 @@ static void TickTimer(StressTest* st) {
SetTimer(st->win->hwndFrame, st->timerId, USER_TIMER_MINIMUM, nullptr);
}

static void Start(StressTest* st, TestFileProvider* fileProvider) {
static void Start(StressTest* st, TestFileProvider* fileProvider, int cycles) {
GetSystemTime(&st->stressStartTime);

st->fileProvider = fileProvider;
st->cycles = cycles;

if (st->pageRanges.size() == 0) {
st->pageRanges.Append(PageRange());
Expand Down Expand Up @@ -484,15 +494,15 @@ static void Finished(StressTest* st, bool success) {
delete st;
}

static void Start(StressTest* st, const char* path, const char* filter, const char* ranges) {
static void Start(StressTest* st, const char* path, const char* filter, const char* ranges, int cycles) {
if (file::Exists(path)) {
FilesProvider* filesProvider = new FilesProvider(path);
ParsePageRanges(ranges, st->pageRanges);
Start(st, filesProvider);
Start(st, filesProvider, cycles);
} else if (dir::Exists(path)) {
auto dirFileProvider = new DirFileProviderAsync(path, filter);
ParsePageRanges(ranges, st->fileRanges);
Start(st, dirFileProvider);
Start(st, dirFileProvider, cycles);
} else {
TempStr s = str::FormatTemp("Path '%s' doesn't exist", path);
NotificationCreateArgs args;
Expand Down Expand Up @@ -686,7 +696,10 @@ static bool GoToNextFile(StressTest* st) {
}
continue;
}
return false;
if (--st->cycles <= 0) {
return false;
}
st->fileProvider->Restart();
}
}

Expand Down Expand Up @@ -877,15 +890,15 @@ void StartStressTest(Flags* i, MainWindow* win) {
win = windows[j];
StressTest* dst = new StressTest(win, i->exitWhenDone);
win->stressTest = dst;
Start(dst, filesProvider);
Start(dst, filesProvider, i->stressTestCycles);
}

free(windows);
} else {
// dst will be deleted when the stress ends
StressTest* st = new StressTest(win, i->exitWhenDone);
win->stressTest = st;
Start(st, i->stressTestPath, i->stressTestFilter, i->stressTestRanges);
Start(st, i->stressTestPath, i->stressTestFilter, i->stressTestRanges, i->stressTestCycles);
}
}

Expand Down

0 comments on commit 8ae95b8

Please sign in to comment.