added named pipe
This commit is contained in:
parent
5389cf9df1
commit
4b66e957cc
2 changed files with 366 additions and 186 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ CMakeCache.txt
|
||||||
Makefile
|
Makefile
|
||||||
*.bin
|
*.bin
|
||||||
qngmeter
|
qngmeter
|
||||||
|
*.json
|
||||||
391
QNGmeter.cpp
391
QNGmeter.cpp
|
|
@ -1,8 +1,16 @@
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -11,12 +19,15 @@
|
||||||
|
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <deque>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
#include "BiasAndAC.h"
|
#include "BiasAndAC.h"
|
||||||
#include "Monkey.h"
|
#include "Monkey.h"
|
||||||
#include "Serial.h"
|
#include "Serial.h"
|
||||||
|
|
@ -41,8 +52,45 @@ using namespace std;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _BSD_SOURCE
|
template<typename T>
|
||||||
#include <sys/time.h>
|
class ThreadSafeQueue {
|
||||||
|
private:
|
||||||
|
mutable std::mutex mtx;
|
||||||
|
std::deque<T> dataQueue;
|
||||||
|
std::condition_variable dataCond;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ThreadSafeQueue() {}
|
||||||
|
|
||||||
|
void push(T newData) {
|
||||||
|
std::lock_guard<std::mutex> lk(mtx);
|
||||||
|
dataQueue.push_back(std::move(newData));
|
||||||
|
dataCond.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool try_pop(T& value) {
|
||||||
|
std::lock_guard<std::mutex> lk(mtx);
|
||||||
|
if (dataQueue.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
value = std::move(dataQueue.front());
|
||||||
|
dataQueue.pop_front();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> wait_and_pop(T& value) {
|
||||||
|
std::unique_lock<std::mutex> lk(mtx);
|
||||||
|
dataCond.wait(lk, [this] { return !dataQueue.empty(); });
|
||||||
|
value = std::move(dataQueue.front());
|
||||||
|
dataQueue.pop_front();
|
||||||
|
return lk;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const {
|
||||||
|
std::lock_guard<std::mutex> lk(mtx);
|
||||||
|
return dataQueue.empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +138,7 @@ int main()
|
||||||
time(&timePrev);
|
time(&timePrev);
|
||||||
timePrev -= 8;
|
timePrev -= 8;
|
||||||
|
|
||||||
queue<shared_ptr<vector<uint32_t> > > dataQueue;
|
//queue<shared_ptr<vector<uint32_t> > > dataQueue;
|
||||||
|
|
||||||
double bitsThroughputCount = 0;
|
double bitsThroughputCount = 0;
|
||||||
double prevBitsThroughputCount = 0;
|
double prevBitsThroughputCount = 0;
|
||||||
|
|
@ -119,82 +167,135 @@ int main()
|
||||||
double meterScore = 0;
|
double meterScore = 0;
|
||||||
bool meterFreeze = false;
|
bool meterFreeze = false;
|
||||||
|
|
||||||
omp_set_nested(true);
|
const char* fifoPath = "/tmp/QNGmeter";
|
||||||
|
#ifdef __linux
|
||||||
|
mkfifo(fifoPath, 0666); // Create FIFO if it doesn't exist
|
||||||
|
int fifoFd = open(fifoPath, O_RDONLY | O_NONBLOCK);
|
||||||
|
if (fifoFd == -1) {
|
||||||
|
std::cerr << "Failed to open named pipe for reading." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma omp parallel sections num_threads(2)
|
fd_set readfds;
|
||||||
|
int maxfd = max(STDIN_FILENO, fifoFd) + 1;
|
||||||
|
|
||||||
|
ThreadSafeQueue<std::string> dataQueue; // Use a thread-safe queue for shared data
|
||||||
|
|
||||||
|
omp_set_nested(true); // Ensure nested parallelism is enabled
|
||||||
|
|
||||||
|
#pragma omp parallel sections
|
||||||
{
|
{
|
||||||
|
#pragma omp section
|
||||||
|
{
|
||||||
|
fd_set readfds;
|
||||||
|
int fifoFd = open ("/tmp/myfifo", O_RDONLY | O_NONBLOCK);
|
||||||
|
if (fifoFd == -1)
|
||||||
|
{
|
||||||
|
perror ("Failed to open FIFO");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxfd = max (STDIN_FILENO, fifoFd) + 1;
|
||||||
|
ThreadSafeQueue < std::string > dataQueue;
|
||||||
|
|
||||||
|
while (!doExit)
|
||||||
|
{
|
||||||
|
FD_ZERO (&readfds);
|
||||||
|
FD_SET (STDIN_FILENO, &readfds);
|
||||||
|
FD_SET (fifoFd, &readfds);
|
||||||
|
|
||||||
|
if (select (maxfd, &readfds, NULL, NULL, NULL) == -1)
|
||||||
|
{
|
||||||
|
perror ("select");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[4096];
|
||||||
|
ssize_t bytesRead;
|
||||||
|
|
||||||
|
if (FD_ISSET (STDIN_FILENO, &readfds))
|
||||||
|
{
|
||||||
|
bytesRead = read (STDIN_FILENO, buffer, sizeof (buffer));
|
||||||
|
if (bytesRead > 0)
|
||||||
|
{
|
||||||
|
dataQueue.push (std::string (buffer, bytesRead));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FD_ISSET (fifoFd, &readfds))
|
||||||
|
{
|
||||||
|
bytesRead = read (fifoFd, buffer, sizeof (buffer));
|
||||||
|
if (bytesRead > 0)
|
||||||
|
{
|
||||||
|
dataQueue.push (std::string (buffer, bytesRead));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close (fifoFd);
|
||||||
|
}
|
||||||
|
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{
|
{
|
||||||
// This section reads from stdin as binary data and enqueues it for testing
|
std::string buffer; // This will hold the raw binary string data from the queue
|
||||||
const size_t blockSize = 2048; // Number of uint32_t values in a block
|
while (!doExit)
|
||||||
const size_t bytesPerValue = sizeof(uint32_t);
|
|
||||||
const size_t bufferSize = blockSize * bytesPerValue; // Total bytes per block
|
|
||||||
char buffer[bufferSize]; // Temporary buffer to store bytes
|
|
||||||
while (!cin.eof() && !doExit) {
|
|
||||||
cin.read(buffer, bufferSize);
|
|
||||||
size_t bytesRead = cin.gcount();
|
|
||||||
|
|
||||||
// Convert read bytes to uint32_t and store in a vector
|
|
||||||
shared_ptr<vector<uint32_t>> newBuffer(new vector<uint32_t>());
|
|
||||||
for (size_t i = 0; i < bytesRead; i += bytesPerValue) {
|
|
||||||
if (i + bytesPerValue <= bytesRead) {
|
|
||||||
// Ensure we have a full 4 bytes to read
|
|
||||||
uint32_t value = 0;
|
|
||||||
memcpy(&value, buffer + i, bytesPerValue);
|
|
||||||
newBuffer->push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!newBuffer->empty()) {
|
|
||||||
#pragma omp critical
|
|
||||||
dataQueue.push(newBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doExit = true; // Exit if stdin closes or reaches EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma omp section
|
|
||||||
{
|
{
|
||||||
// This section processes the enqueued data
|
if (dataQueue.try_pop (buffer))
|
||||||
while (!doExit || !dataQueue.empty()) {
|
|
||||||
shared_ptr<vector<uint32_t>> testBuffer = nullptr;
|
|
||||||
#pragma omp critical
|
|
||||||
{
|
{
|
||||||
if (!dataQueue.empty()) {
|
// Assuming each uint32_t is stored in 4 bytes within the string
|
||||||
testBuffer = dataQueue.front();
|
// Convert the string buffer into a vector<uint32_t> for processing
|
||||||
dataQueue.pop();
|
std::vector < uint32_t > values;
|
||||||
}
|
const size_t numValues = buffer.size () / sizeof (uint32_t);
|
||||||
|
for (size_t i = 0; i < numValues; ++i)
|
||||||
|
{
|
||||||
|
uint32_t value;
|
||||||
|
memcpy (&value, buffer.data () + i * sizeof (uint32_t),
|
||||||
|
sizeof (uint32_t));
|
||||||
|
values.push_back (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testBuffer != nullptr) {
|
// Now, values contains the uint32_t data extracted from buffer
|
||||||
// Parallel processing of the testBuffer
|
// Process the values as needed
|
||||||
#pragma omp parallel sections num_threads(4)
|
#pragma omp parallel sections num_threads(4)
|
||||||
{
|
{
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{ for (uint32_t value : *testBuffer) biasAndAc.InsertWord32(value); }
|
{
|
||||||
|
for (uint32_t value:values)
|
||||||
|
biasAndAc.InsertWord32 (value);
|
||||||
|
}
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{ for (uint32_t value : *testBuffer) oqso.InsertWord32(value); }
|
{
|
||||||
|
for (uint32_t value:values)
|
||||||
|
oqso.InsertWord32 (value);
|
||||||
|
}
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{ for (uint32_t value : *testBuffer) serial.InsertWord32(value); }
|
{
|
||||||
|
for (uint32_t value:values)
|
||||||
|
serial.InsertWord32 (value);
|
||||||
|
}
|
||||||
#pragma omp section
|
#pragma omp section
|
||||||
{ for (uint32_t value : *testBuffer) entropy.InsertWord32(value); }
|
{
|
||||||
|
for (uint32_t value:values)
|
||||||
|
entropy.InsertWord32 (value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display results
|
// Display results
|
||||||
time(&timeNow);
|
time (&timeNow);
|
||||||
if (difftime(timeNow, timePrev) >= 10)
|
if (difftime (timeNow, timePrev) >= 10)
|
||||||
{
|
{
|
||||||
// calc rates
|
// calc rates
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
QueryPerformanceCounter(&nowCount);
|
QueryPerformanceCounter (&nowCount);
|
||||||
double newTimeInterval = ((double)nowCount.QuadPart - prevCount.QuadPart) / countFreq.QuadPart;
|
double newTimeInterval =
|
||||||
|
((double) nowCount.QuadPart -
|
||||||
|
prevCount.QuadPart) / countFreq.QuadPart;
|
||||||
prevCount = nowCount;
|
prevCount = nowCount;
|
||||||
#elif __linux
|
#elif __linux
|
||||||
gettimeofday(&stop, NULL);
|
gettimeofday (&stop, NULL);
|
||||||
newTimeInterval = (stop.tv_sec - start.tv_sec); // sec
|
newTimeInterval = (stop.tv_sec - start.tv_sec); // sec
|
||||||
newTimeInterval += (stop.tv_usec - start.tv_usec) /1000000.0; // us to sec
|
newTimeInterval += (stop.tv_usec - start.tv_usec) / 1000000.0; // us to sec
|
||||||
start = stop;
|
start = stop;
|
||||||
#elif MACOSX
|
#elif MACOSX
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -203,7 +304,8 @@ int main()
|
||||||
double newRate;
|
double newRate;
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
{
|
{
|
||||||
newBitInterval = (bitsThroughputCount - prevBitsThroughputCount);
|
newBitInterval =
|
||||||
|
(bitsThroughputCount - prevBitsThroughputCount);
|
||||||
prevBitsThroughputCount = bitsThroughputCount;
|
prevBitsThroughputCount = bitsThroughputCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,69 +313,74 @@ int main()
|
||||||
if (throughput == 0)
|
if (throughput == 0)
|
||||||
throughput = newRate;
|
throughput = newRate;
|
||||||
else
|
else
|
||||||
throughput = (2*throughput + newRate) / 3;
|
throughput = (2 * throughput + newRate) / 3;
|
||||||
|
|
||||||
double newBitsTestedRatio = (bitsTestedCount-prevBitsTestedCount) / newBitInterval;
|
double newBitsTestedRatio =
|
||||||
|
(bitsTestedCount - prevBitsTestedCount) / newBitInterval;
|
||||||
prevBitsTestedCount = bitsTestedCount;
|
prevBitsTestedCount = bitsTestedCount;
|
||||||
bitsTestedRatio = (2*bitsTestedRatio + newBitsTestedRatio) / 3;
|
bitsTestedRatio =
|
||||||
|
(2 * bitsTestedRatio + newBitsTestedRatio) / 3;
|
||||||
if (bitsTestedRatio > 1)
|
if (bitsTestedRatio > 1)
|
||||||
bitsTestedRatio = 1;
|
bitsTestedRatio = 1;
|
||||||
|
|
||||||
// meta test and meter
|
// meta test and meter
|
||||||
metaPs.clear();
|
metaPs.clear ();
|
||||||
meterZs.clear();
|
meterZs.clear ();
|
||||||
|
|
||||||
if (bitsTestedCount >= 65536)
|
if (bitsTestedCount >= 65536)
|
||||||
{
|
{
|
||||||
// Autocorrelation KS test
|
// Autocorrelation KS test
|
||||||
for (int i=0; i<32; i++)
|
for (int i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
metaPs.push_back(biasAndAc.AC.P_Chi2[i]);
|
metaPs.push_back (biasAndAc.AC.P_Chi2[i]);
|
||||||
meterZs.push_back(biasAndAc.AC.cumulativeACZScore[i]);
|
meterZs.push_back (biasAndAc.AC.
|
||||||
|
cumulativeACZScore[i]);
|
||||||
}
|
}
|
||||||
double AcKSP;
|
double AcKSP;
|
||||||
double AcKSN;
|
double AcKSN;
|
||||||
ks.KSUP(&AcKSP, &AcKSN, &metaPs[0], metaPs.size());
|
ks.KSUP (&AcKSP, &AcKSN, &metaPs[0], metaPs.size ());
|
||||||
|
|
||||||
// Combined KS test
|
// Combined KS test
|
||||||
metaPs.push_back(AcKSP);
|
metaPs.push_back (AcKSP);
|
||||||
|
|
||||||
metaPs.push_back(biasAndAc.Bias.P_Chi2);
|
metaPs.push_back (biasAndAc.Bias.P_Chi2);
|
||||||
meterZs.push_back(biasAndAc.Bias.cumulativeBiasZScore);
|
meterZs.push_back (biasAndAc.Bias.cumulativeBiasZScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitsTestedCount >= 4194304)
|
if (bitsTestedCount >= 4194304)
|
||||||
{
|
{
|
||||||
metaPs.push_back(serial.P_Chi2);
|
metaPs.push_back (serial.P_Chi2);
|
||||||
serialP = gamma.Gamma(128., serial.cumulativeSerialChi2);
|
serialP = gamma.Gamma (128., serial.cumulativeSerialChi2);
|
||||||
serialZ = ks.PtoZ(serialP);
|
serialZ = ks.PtoZ (serialP);
|
||||||
meterZs.push_back(serialZ);
|
meterZs.push_back (serialZ);
|
||||||
|
|
||||||
metaPs.push_back(entropy.P_Chi2);
|
metaPs.push_back (entropy.P_Chi2);
|
||||||
meterZs.push_back(entropy.cumulativeZScore);
|
meterZs.push_back (entropy.cumulativeZScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitsTestedCount >= 10485775)
|
if (bitsTestedCount >= 10485775)
|
||||||
{
|
{
|
||||||
metaPs.push_back(oqso.P_Chi2);
|
metaPs.push_back (oqso.P_Chi2);
|
||||||
meterZs.push_back(oqso.cumulativeZScore);
|
meterZs.push_back (oqso.cumulativeZScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitsTestedCount >= 65536)
|
if (bitsTestedCount >= 65536)
|
||||||
{
|
{
|
||||||
// This KS is combined AC KSP plus with other tests
|
// This KS is combined AC KSP plus with other tests
|
||||||
ks.KSUP(&KSP, &KSN, &metaPs[32], metaPs.size()-32);
|
ks.KSUP (&KSP, &KSN, &metaPs[32], metaPs.size () - 32);
|
||||||
|
|
||||||
meterFreeze = false;
|
meterFreeze = false;
|
||||||
for (int i=0; i<meterZs.size(); i++)
|
for (int i = 0; i < meterZs.size (); i++)
|
||||||
{
|
{
|
||||||
// freeze condition
|
// freeze condition
|
||||||
if (fabs(meterZs[i])>4.264897 || (metaPs[i]<0.00001 || metaPs[i]>0.99999))
|
if (fabs (meterZs[i]) > 4.264897
|
||||||
|
|| (metaPs[i] < 0.00001 || metaPs[i] > 0.99999))
|
||||||
meterFlags[i] = -1;
|
meterFlags[i] = -1;
|
||||||
// unfreeze condition
|
// unfreeze condition
|
||||||
if (meterFlags[i] == -1)
|
if (meterFlags[i] == -1)
|
||||||
{
|
{
|
||||||
if (fabs(meterZs[i])<2.326348 && (metaPs[i]>0.01 && metaPs[i]<0.99))
|
if (fabs (meterZs[i]) < 2.326348
|
||||||
|
&& (metaPs[i] > 0.01 && metaPs[i] < 0.99))
|
||||||
meterFlags[i] = 0;
|
meterFlags[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,24 +390,56 @@ int main()
|
||||||
|
|
||||||
// meter calc
|
// meter calc
|
||||||
if (meterFreeze == false)
|
if (meterFreeze == false)
|
||||||
meterScore = log(bitsTestedCount)/log(2.);
|
meterScore = log (bitsTestedCount) / log (2.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << " QNGmeter Console 1.0 Test Type z-score p[z<=x] p[chi2<=x] " << endl;
|
cout <<
|
||||||
cout << " +---------------------------+------------------------------------------------+" << endl;
|
" QNGmeter Console 1.0 Test Type z-score p[z<=x] p[chi2<=x] "
|
||||||
cout << " | | 1/0 Balance " << setiosflags(ios::fixed) << setprecision(3) << showpos << biasAndAc.Bias.cumulativeBiasZScore << " " << setprecision(4) << noshowpos << CStat::ZtoP(biasAndAc.Bias.cumulativeBiasZScore) << " " << biasAndAc.Bias.P_Chi2 << " |" << endl;
|
<< endl;
|
||||||
cout << " | | Serial Test " << setiosflags(ios::fixed) << setprecision(3) << showpos << serialZ << " " << setprecision(4) << noshowpos << serialP << " " << serial.P_Chi2 << " |" << endl;
|
cout <<
|
||||||
cout << " | | OQSO Test " << setiosflags(ios::fixed) << setprecision(3) << showpos << oqso.cumulativeZScore << " " << setprecision(4) << noshowpos << CStat::ZtoP(oqso.cumulativeZScore) << " " << oqso.P_Chi2 << " |" << endl;
|
" +---------------------------+------------------------------------------------+"
|
||||||
cout << " | | Entropy Test " << setiosflags(ios::fixed) << setprecision(3) << showpos << entropy.cumulativeZScore << " " << setprecision(4) << noshowpos << CStat::ZtoP(entropy.cumulativeZScore) << " " << serial.P_Chi2 << " |" << endl;
|
<< endl;
|
||||||
cout << " | | H: " << setiosflags(ios::fixed) << setprecision(9) << entropy.E << " |" << endl;
|
cout << " | | 1/0 Balance "
|
||||||
|
<< setiosflags (ios::
|
||||||
|
fixed) << setprecision (3) << showpos <<
|
||||||
|
biasAndAc.Bias.
|
||||||
|
cumulativeBiasZScore << " " << setprecision (4) <<
|
||||||
|
noshowpos << CStat::ZtoP (biasAndAc.Bias.
|
||||||
|
cumulativeBiasZScore) << " " <<
|
||||||
|
biasAndAc.Bias.P_Chi2 << " |" << endl;
|
||||||
|
cout << " | | Serial Test "
|
||||||
|
<< setiosflags (ios::
|
||||||
|
fixed) << setprecision (3) << showpos <<
|
||||||
|
serialZ << " " << setprecision (4) << noshowpos <<
|
||||||
|
serialP << " " << serial.P_Chi2 << " |" << endl;
|
||||||
|
cout << " | | OQSO Test "
|
||||||
|
<< setiosflags (ios::
|
||||||
|
fixed) << setprecision (3) << showpos <<
|
||||||
|
oqso.
|
||||||
|
cumulativeZScore << " " << setprecision (4) << noshowpos
|
||||||
|
<< CStat::ZtoP (oqso.cumulativeZScore) << " " << oqso.
|
||||||
|
P_Chi2 << " |" << endl;
|
||||||
|
cout << " | | Entropy Test "
|
||||||
|
<< setiosflags (ios::
|
||||||
|
fixed) << setprecision (3) << showpos <<
|
||||||
|
entropy.
|
||||||
|
cumulativeZScore << " " << setprecision (4) << noshowpos
|
||||||
|
<< CStat::ZtoP (entropy.
|
||||||
|
cumulativeZScore) << " " << serial.
|
||||||
|
P_Chi2 << " |" << endl;
|
||||||
|
cout << " | | H: " <<
|
||||||
|
setiosflags (ios::fixed) << setprecision (9) << entropy.
|
||||||
|
E << " |" << endl;
|
||||||
|
|
||||||
cout << " | | |" << endl;
|
cout <<
|
||||||
|
" | | |"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
for (int i=1; i<=32; i++)
|
for (int i = 1; i <= 32; i++)
|
||||||
{
|
{
|
||||||
switch(i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
cout << " | Start Time |";
|
cout << " | Start Time |";
|
||||||
|
|
@ -312,51 +451,83 @@ int main()
|
||||||
cout << " | Total Bits Tested |";
|
cout << " | Total Bits Tested |";
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
cout << " | " << scientific << setw(9) << setprecision(2) << bitsTestedCount << fixed << " |";
|
cout << " | " << scientific << setw (9) <<
|
||||||
|
setprecision (2) << bitsTestedCount << fixed <<
|
||||||
|
" |";
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
cout << " | Throughput |";
|
cout << " | Throughput |";
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
cout << " | " << setiosflags(ios::fixed) << setw(4) << setprecision(1) << (double)(throughput/1000000.0) << " Mbps |";
|
cout << " | " << setiosflags (ios::
|
||||||
|
fixed) << setw (4)
|
||||||
|
<< setprecision (1) << (double) (throughput /
|
||||||
|
1000000.0) <<
|
||||||
|
" Mbps |";
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
cout << " | Bits Tested Percent |";
|
cout << " | Bits Tested Percent |";
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
cout << " | " << setiosflags(ios::fixed) << setw(5) << setprecision(1) << (100*bitsTestedRatio) << "% |";
|
cout << " | " << setiosflags (ios::
|
||||||
|
fixed) << setw (5)
|
||||||
|
<< setprecision (1) << (100 *
|
||||||
|
bitsTestedRatio) <<
|
||||||
|
"% |";
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
cout << " | Meta KS+ Test |";
|
cout << " | Meta KS+ Test |";
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
cout << " | " << setiosflags(ios::fixed) << setw(5) << setprecision(3) << KSP << " |";
|
cout << " | " << setiosflags (ios::
|
||||||
|
fixed) << setw (5)
|
||||||
|
<< setprecision (3) << KSP << " |";
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
cout << " | Meta KS- Test |";
|
cout << " | Meta KS- Test |";
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
cout << " | " << setiosflags(ios::fixed) << setw(5) << setprecision(3) << KSN << " |";
|
cout << " | " << setiosflags (ios::
|
||||||
|
fixed) << setw (5)
|
||||||
|
<< setprecision (3) << KSN << " |";
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 29:
|
||||||
cout << " | QNGmeter Score |";
|
cout << " | QNGmeter Score |";
|
||||||
break;
|
break;
|
||||||
case 30:
|
case 30:
|
||||||
cout << " | " << setiosflags(ios::fixed) << setw(4) << setprecision(1) << abs(meterScore) << ((meterScore<0)? "-" : (meterFreeze==false)? "+" : " ") << " |";
|
cout << " | " << setiosflags (ios::
|
||||||
|
fixed) << setw (4)
|
||||||
|
<< setprecision (1) << abs (meterScore) <<
|
||||||
|
((meterScore < 0) ? "-" : (meterFreeze ==
|
||||||
|
false) ? "+" : " ") <<
|
||||||
|
" |";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << " | |";
|
cout << " | |";
|
||||||
}
|
}
|
||||||
cout << " " << setw(2) << i << "st AutoCorr " << setiosflags(ios::fixed) << setprecision(3) << showpos << biasAndAc.AC.cumulativeACZScore[i-1] << " " << setprecision(4) << noshowpos << CStat::ZtoP(biasAndAc.AC.cumulativeACZScore[i-1]) << " " << biasAndAc.AC.P_Chi2[i-1] << " |" << endl;
|
cout << " " << setw (2) << i << "st AutoCorr " <<
|
||||||
|
setiosflags (ios::
|
||||||
|
fixed) << setprecision (3) << showpos <<
|
||||||
|
biasAndAc.AC.cumulativeACZScore[i -
|
||||||
|
1] << " " <<
|
||||||
|
setprecision (4) << noshowpos << CStat::ZtoP (biasAndAc.
|
||||||
|
AC.
|
||||||
|
cumulativeACZScore
|
||||||
|
[i -
|
||||||
|
1]) <<
|
||||||
|
" " << biasAndAc.AC.P_Chi2[i - 1] << " |" << endl;
|
||||||
}
|
}
|
||||||
cout << " +---------------------------+------------------------------------------------+" << endl;
|
cout <<
|
||||||
|
" +---------------------------+------------------------------------------------+"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// put cursor in top corner
|
// put cursor in top corner
|
||||||
COORD coord;
|
COORD coord;
|
||||||
coord.X = 0;
|
coord.X = 0;
|
||||||
coord.Y = 0;
|
coord.Y = 0;
|
||||||
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
|
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE),
|
||||||
|
coord);
|
||||||
#elif __linux
|
#elif __linux
|
||||||
// clear screen
|
// clear screen
|
||||||
// printf("\E[H");
|
// printf("\E[H");
|
||||||
|
|
@ -364,16 +535,17 @@ int main()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
timePrev = timeNow;
|
timePrev = timeNow;
|
||||||
cout.flush();
|
cout.flush ();
|
||||||
|
buffer.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// End on an 'x' keypress
|
// End on an 'x' keypress
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (kbhit())
|
if (kbhit ())
|
||||||
{
|
{
|
||||||
char c = getch_();
|
char c = getch_ ();
|
||||||
|
|
||||||
if ( tolower(c) == 'x' )
|
if (tolower (c) == 'x')
|
||||||
{
|
{
|
||||||
doExit = true;
|
doExit = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -387,10 +559,17 @@ int main()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// give this thread a break from tight loop - waiting for data
|
// give this thread a break from tight loop - waiting for data
|
||||||
usleep(1000);
|
usleep (1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __linux
|
||||||
|
close(fifoFd); // Close the FIFO file descriptor when done
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue