Skip to content

Commit

Permalink
Merge 48976ae into e12b0a6
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAwesomeP authored Jun 22, 2023
2 parents e12b0a6 + 48976ae commit 9c5d84d
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ examples/ola_streaming_client
examples/ola_streaming_client.exe
examples/ola_throughput
examples/ola_throughput.exe
examples/ola_throughput_multi
examples/ola_throughput_multi.exe
examples/ola_timecode
examples/ola_timecode.exe
examples/ola_uni_info
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contributors:
Nicolas, for the win32 port of libartnet
Nicolas Bertrand, added ShowJockey DMX-U1 support
Nils Van Zuijlen, typos and python lib small update
Perry Naseck, EPoll delay fix, GitHub Actions CI workflows, Debian pkg fixes
Perry Naseck, EPoll delay fix, GitHub Actions CI workflows, Debian pkg fixes, ola_throughput_multi example
Peter Newman, MilInst Plugin, Scanlime Fadecandy support and numerous fixes
Ravindra Nath Kakarla, RDM Test Server (Google Summer of Code 2012)
Rowan Maclachlan (hippy) for various changes
Expand Down
4 changes: 3 additions & 1 deletion examples/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ examples_ola_dmxmonitor_LDADD = $(EXAMPLE_COMMON_LIBS) -lncurses
endif
endif

noinst_PROGRAMS += examples/ola_throughput examples/ola_latency
noinst_PROGRAMS += examples/ola_throughput examples/ola_throughput_multi examples/ola_latency
examples_ola_throughput_SOURCES = examples/ola-throughput.cpp
examples_ola_throughput_LDADD = $(EXAMPLE_COMMON_LIBS)
examples_ola_throughput_multi_SOURCES = examples/ola-throughput-multi.cpp
examples_ola_throughput_multi_LDADD = $(EXAMPLE_COMMON_LIBS)
examples_ola_latency_SOURCES = examples/ola-latency.cpp
examples_ola_latency_LDADD = $(EXAMPLE_COMMON_LIBS)

Expand Down
177 changes: 177 additions & 0 deletions examples/ola-throughput-multi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ola-throughput-multi.cpp
* Send a bunch of frames quickly on multiple universes to load test the server.
* Copyright (C) 2022 Perry Naseck (git@perrynaseck.com)
*/

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <ola/base/Flags.h>
#include <ola/base/Init.h>
#include <ola/client/ClientWrapper.h>
#include <ola/io/SelectServer.h>
#include <ola/DmxBuffer.h>
#include <ola/Logging.h>
#include <ola/StreamingClient.h>
#include <ola/StringUtils.h>

#include <chrono> // NOLINT(build/c++11)
#include <iostream>
#include <string>
#include <vector>

using std::cout;
using std::endl;
using std::string;
using ola::client::OlaClientWrapper;
using ola::StreamingClient;
using std::chrono::high_resolution_clock;
using std::chrono::microseconds;
using std::chrono::nanoseconds;

const unsigned int MICROSECONDS_PER_MILLISECOND = 1000;

DEFINE_s_uint32(universes, u, 24, "The number of universes to send data on");
DEFINE_s_uint32(sleep, s, 40000, "Time between DMX updates in micro-seconds");
DEFINE_s_default_bool(oscillate_data, d, false,
"Flip all channels in each universe between 0 and 255 "
"for each frame. CAUTION: This will produce rapid "
"strobing on any connected outputs!");
DEFINE_s_default_bool(advanced, a, false, "Use the advanced ClientWrapper API "
"instead of the StreamingClient API");

void oscillateData(std::vector<ola::DmxBuffer> *buffers) {
static bool channelsOnNext = true;
for (size_t i = 0; i < FLAGS_universes; i++) {
if (channelsOnNext) {
for (size_t j = 0; j < 512; j++) {
(*buffers)[i].SetChannel(j, 255);
}
channelsOnNext = false;
} else {
(*buffers)[i].Blackout();
channelsOnNext = true;
}
}
}

void AdvancedConnectionClosed(ola::io::SelectServer *ss) {
std::cerr << "Connection to olad was closed" << endl;
ss->Terminate(); // terminate the program.
}

bool AdvancedSendData(ola::client::OlaClientWrapper *wrapper,
std::vector<ola::DmxBuffer> *buffers,
std::vector<nanoseconds> *sendDmxTimes) {
if (FLAGS_oscillate_data) {
oscillateData(buffers);
}

auto startTime = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < FLAGS_universes; i++) {
auto startTimeSendDmx = high_resolution_clock::now();
wrapper->GetClient()->SendDMX(
i + 1,
(*buffers)[i],
ola::client::SendDMXArgs());
(*sendDmxTimes)[i] = (high_resolution_clock::now() - startTimeSendDmx);
}
auto endTime = (std::chrono::high_resolution_clock::now() - startTime);

printf("sendDmx times (us):"); // fast write
for (size_t i = 0; i < FLAGS_universes; i++) {
auto endTimeSendDmxUs = (
std::chrono::duration_cast<microseconds>((*sendDmxTimes)[i]).count());
printf(" %04ld", endTimeSendDmxUs); // fast write
}
auto endTimeUs = (
std::chrono::duration_cast<microseconds>(endTime).count());
printf("\nframe time: %08ld us\n", endTimeUs); // fast write
return true;
}

/*
* Main
*/
int main(int argc, char *argv[]) {
ola::AppInit(&argc, argv, "[options]", "Send DMX512 data to OLA.");

OlaClientWrapper wrapper;
StreamingClient ola_client;
if (FLAGS_advanced) {
if (!wrapper.Setup()) {
OLA_FATAL << "Setup failed";
exit(1);
}
} else {
if (!ola_client.Setup()) {
OLA_FATAL << "Setup failed";
exit(1);
}
}

std::vector<ola::DmxBuffer> buffers;
for (size_t i = 0; i < FLAGS_universes; i++) {
buffers.push_back(ola::DmxBuffer());
buffers[i].Blackout();
}

std::vector<nanoseconds> sendDmxTimes(FLAGS_universes);

if (FLAGS_advanced) {
ola::io::SelectServer *ss = wrapper.GetSelectServer();
ss->RegisterRepeatingTimeout(
FLAGS_sleep / MICROSECONDS_PER_MILLISECOND,
ola::NewCallback(&AdvancedSendData, &wrapper, &buffers, &sendDmxTimes));

wrapper.GetClient()->SetCloseHandler(
ola::NewSingleCallback(AdvancedConnectionClosed, ss));

ss->Run();
} else {
while (1) {
usleep(FLAGS_sleep);

if (FLAGS_oscillate_data) {
oscillateData(&buffers);
}

auto startTime = high_resolution_clock::now();
for (size_t i = 0; i < FLAGS_universes; i++) {
auto startTimeSendDmx = high_resolution_clock::now();
if (!ola_client.SendDmx(i + 1, buffers[i])) {
cout << "Send DMX failed" << endl;
exit(1);
}
sendDmxTimes[i] = (high_resolution_clock::now() - startTimeSendDmx);
}
auto endTime = (high_resolution_clock::now() - startTime);

printf("sendDmx times (us):"); // fast write
for (size_t i = 0; i < FLAGS_universes; i++) {
auto endTimeSendDmxUs = (
std::chrono::duration_cast<microseconds>(sendDmxTimes[i]).count());
printf(" %04ld", endTimeSendDmxUs); // fast write
}
auto endTimeUs = (
std::chrono::duration_cast<microseconds>(endTime).count());
printf("\nframe time: %08ld us\n", endTimeUs); // fast write
}
}
return 0;
}

0 comments on commit 9c5d84d

Please sign in to comment.