I'm trying to use Intel Performance Counter Monitor (PCM) to understand L3 cache miss and some other performance criteria in my code.
I'm not sure how to make sense out of the numbers I'm getting and would appreciate some insight.
I expect ideally to get 0 bytes read from the following piece of code however I'm getting a number that is close to 240KB read. If I try to run other processes, the 240KB number fluctuates (doesn't monotonically go up/down, it just has meaningful fluctuation (goes up first and then goes down) ).
volatile SystemCounterState before_sstate = getSystemCounterState();
volatile SystemCounterState after_sstate = getSystemCounterState();
cout << "Instructions per clock: " << getIPC( before_sstate, after_sstate )
<< ", L3 Cache hit ratio: " << getL3CacheHitRatio( before_sstate, after_sstate )
<< ", L3 Missed Cycles: " << getCyclesLostDueL3CacheMisses(before_sstate, after_sstate )
<< ", Bytes read: " << getBytesReadFromMC( before_sstate, after_sstate )
<< ", L3 Occupancy: " << getL3CacheOccupancy( after_sstate ) << endl;
Here is the output I'm getting:
Trying to use Linux perf events...
Successfully programmed on-core PMU using Linux perf
Instructions per clock: 0.637448, L3 Cache hit ratio: 0.820139, Missed Cycles: 0.075492, Bytes read: 263488, L3 Occupancy: 0
Does anyone know why I'm getting 240KB read although I'm actually not reading anything in the code? Is it sharing the compute resources with other processes and potentially capturing the stats from other processes as well?
If that's the case, how can I make sure that the information captured is isolated to this code/process running?
Related
Working with Arduino ESP32.
I managed to implement Environment temp + humidity using the specified BLE spec service and characteristic UUID's. I got lucky as I could see that the values were presenting wrong and could figure out what inputs were needed for correct outputs.
Now working with weight I am getting no value displaying for my weight measurement characteristic. I have the weight scale service (0x181D), Scale Feature (0x2A9E) and Weight Measurement (0x2A9D). I can send 0000 or 1111 to 2A9E to get a a formatted display of what the scale features are. Cool! I saw elsewhere on stack that having this characteristic set was required for the weight measurement to show.
I'm using 0000 as I don't need the timestamp or multi user. I've also read both datasheets (WSS_V1.0.0 & WSP_V1.0.0) for the characteristics I'm using and am still stuck. (WSS_V1.0.0 & WSP_V1.0.0)
WSS states the first byte sets the flags and the following bytes are for the weight. I've tried using
0000101010101010 == {0x0A, 0xAA} == 0000(flags) 1010(weight) ...
Which fits the format of 4 flag bytes followed by weight, followed by optionals.
still no luck. Online resources are limited, I've tried reading the docs and no examples are given.
Any help would be much appreciated and would assist in other looking for a similar answer
There's an example that has working code for those who stumble into this thread later down the line.
https://github.com/bneedhamia/CurieBLEBowlScale/blob/master/CurieBLEBowlScale.ino
A weight measurement has it's first byte dedicated to flags
/*
* Set the flags:
* bit 0 = 0 means we're reporting in SI units (kg and meters)
* bit 1 = 0 means there is no time stamp in our report
* bit 2 = 0 means User ID is NOT in our report
* bit 3 = 0 means no BMI and Height are in our report
* bits 4..7 are reserved, and set to zero.
*/
flags |= 0x0 << 0;
flags |= 0x0 << 1;
flags |= 0x0 << 2;
flags |= 0x0 << 3;
and the following two bytes contain the weight in big Endian.
bytes[0] = flags;
// BLE GATT multi-byte values are encoded Least-Significant Byte first.
bytes[1] = (unsigned char) newVal;
bytes[2] = (unsigned char) (newVal >> 8);
chrScaleValue->setValue(bytes, sizeof(bytes));
QFile vfile(file);
if(!vfile.open(QIODevice::ReadWrite | QIODevice::Text)) qDebug() << "FILE COULDN NOT BE OPENED";
QTextStream stream(&vfile);
stream << "Hello" << "=";
vfile.write("132");
Output to File - 132Hello=
In the above example, I write the data in 2 different ways but when I see the file I found some this type of result that while using "write()" the data within write() printed first instead of the above statements is displayed in the example.
The stream data is cached for a time (which is typical of writing to streams in general, eg. stdout and such). You can flush the stream data to be sure it is all written before writing to the file via a different method.
stream << "Hello=" << flush;
vfile.write("123");
Also see manipulator functions list in https://doc.qt.io/qt-5/qtextstream.html#details
Writing an end-of-line character (endln or \n) will also flush the stream buffer.
I am having issues with QDir losing Non-Ascii characters from my file names.
I have files with names like testingöäüß.txt or exampleΦ.shp and when trying to use Qt utilities like QDir and QFile they simply show up as testing.txt and example.shp. Seems as though I cannot tell those classes what kind of encoding to use. I'm trying QDirIterator and the QDir function entryInfoList:
QDir someDir("/home/blah"); //contains testingöäüß.txt
QDirIterator dirIter(someDir.absolutePath(), QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
while(dirIter.hasNext())
{
QString fileName1 = QFile::decodeName(dirIter.next().toUtf8());
std::cout << "QDirIterator Name " << fileName1.toStdString().c_str() << std::endl;
}
QFileInfoList fileInfoList = someDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
foreach(QFileInfo fileInfo, fileInfoList)
{
QString fileName1 = QFile::decodeName(fileInfo.fileName().toUtf8());
std::cout << "entryInfoList Name " << fileName1.toStdString().c_str() << std::endl;
QString fileName2 = QFile::decodeName(fileInfo.absoluteFilePath().toUtf8());
std::cout << "entryInfoList Name2 " << fileName2.toStdString().c_str() << std::endl;
QString fileName3 = QString::fromUtf8(dirIter.fileInfo().absoluteFilePath().toStdString().c_str());
std::cout << "entryInfoList Name3 " << fileName3.toStdString().c_str() << std::endl;
}
Every one of those prints will lack the non-ascii characters. Seems like as soon as you try to grab the file names to loop over they will be ascii only. Anyone have any ideas on this? Or can Qt simply not handle this? Thanks!
I know this is an old question, but I just ran into the same problem. The same exact Qt code would work fine on my development VM, but when I transferred it to an embedded Linux system (running on x86 so literally the same executable) my directory names just silently got their non-ASCII characters dropped.
Turned out the QTextCodec::codecForLocale on my dev VM was set to UTF-8, and on the embedded box it was System. If I manually changed the locale to UTF-8 before doing any filesystem operations (by calling QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"))), everything started working fine.
So why was this happening in the first place? My suspicion is that in the process of slimming down the embedded system's root filesystem I might have accidentally deleted some locale-related files that Qt was using to try to auto-detect the locale. When it couldn't determine it was on UTF-8, it fell back to System, which for whatever reason is broken (maybe for the same reason it couldn't detect UTF-8 in the first place).
I need to eventually fix whatever is causing it to not auto-detect, but in the short-term just manually setting a UTF-8 locale should work if you are experiencing this same issue.
Note that this has nothing to do with whether the console can display UTF-8, or anything to do with manual conversion of UTF-16 to UTF-8! So Felix's answer to this question is not correct, at least for this particular issue. To completely remove the capability of the console from the equation, I was also simply printing the number of UTF-16 characters in the string, and every non-ASCII character actually made the returned path and filename strings from QDir::entryInfoList have one less UTF-16 character. Additionally, the dead giveaway is that the characters were simply stripped out, not just replaced with garbage or question marks or whatever.
Qt can handle filenames with special characters. You just make them disappear somewhere in that string conversion stuff. (Which is completly unnecessary) Try it this way:
#include <QDebug>
//...
QFileInfoList fileInfoList = someDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
foreach(QFileInfo fileInfo, fileInfoList)
{
qDebug() << fileInfo.fileName();//uses qdebug
std::cout << fileInfo.fileName().toStdWString() << std::endl;//uses a 16Bit string on normal cout
}
If you still don't see them, it's because your console settings do not allow to display them. Try to write them to a file or display them in a gui - or simply try to open a file with that name, it will work.
I have my embedded linux box with 2 serial ports application, which tests all serial ports with wrap cable (only Rx connected to Tx, no other pins).
The second (non-console) port works fine.
The first (console) port sometimes works, but sometimes does inexplainable things.
To test the first channel I kill running 'getty' before opening it. The respawn is also forbidden.
Then I do the following:
system("killall getty");
Sleep(1000);
if ((fd = open(Name, O_RDWR | O_NOCTTY | O_NONBLOCK)) <= 0)
MsgFatal("Serial '%s' open error %d.", Name, errno);
BRN = B115200;
tcgetattr(fd, &Opts);
cfsetispeed(&Opts, BRN);
cfsetospeed(&Opts, BRN);
cfmakeraw(&Opts);
Opts.c_cflag |= PARENB;
Opts.c_cflag |= PARODD;
Opts.c_cflag &= ~CSTOPB;
Opts.c_cflag &= ~CRTSCTS; /* no HW flow control */
Opts.c_cflag |= CLOCAL | CREAD;
tcsetattr(fd,TCSANOW,&Opts));
After this, SOMETIMES (I mean on some run of the application) the next write operation blocks!
Any advice will be highly appreciated.
First off, the death of a getty process should immediately be reaped by its parent, either init or an aspect of BusyBox, and relaunched. How long it takes can vary, but it is usually pretty quick. But that shouldn't affect writing to the port.
How do you know the write is blocking? Please show that code.
How can I obtain this information:
Total Memory
Free Memory
Memory used by current running application ?
I think Qt should have memory options, that would be platform-independent, but
I can't find it. So what can I do when I want to make a platform-independent application that shows memory state?
Unfortunately, there is nothing built into Qt for this. You must do this per-platform.
Here are some samples to get you started. I had to implement this in one of my apps just last week. The code below is still very much in development; there may be errors or leaks, but it might at least point you in the correct direction. I was only interested in total physical RAM, but the other values are available in the same way. (Except perhaps memory in use by the current application ... not sure about that one.)
Windows (GlobalMemoryStatusEx)
MEMORYSTATUSEX memory_status;
ZeroMemory(&memory_status, sizeof(MEMORYSTATUSEX));
memory_status.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusEx(&memory_status)) {
system_info.append(
QString("RAM: %1 MB")
.arg(memory_status.ullTotalPhys / (1024 * 1024)));
} else {
system_info.append("Unknown RAM");
}
Linux (/proc/meminfo)
QProcess p;
p.start("awk", QStringList() << "/MemTotal/ { print $2 }" << "/proc/meminfo");
p.waitForFinished();
QString memory = p.readAllStandardOutput();
system_info.append(QString("; RAM: %1 MB").arg(memory.toLong() / 1024));
p.close();
Mac (sysctl)
QProcess p;
p.start("sysctl", QStringList() << "kern.version" << "hw.physmem");
p.waitForFinished();
QString system_info = p.readAllStandardOutput();
p.close();
Much better on POSIX OSes (Linux, Solaris, perhaps latest MacOS...) :
getrusage(...) secially look at ru_maxrss.
getrlimit(...) but I did not find any usefull info into.
sysconf(...) : _SC_PAGESIZE, _SC_PHYS_PAGES, _SC_AVPHYS_PAGES
sysinfo(...) : totalram, freeram, sharedram, totalswap,...
So much treasures on POSIX computers not available on Windows.
This is currently not possible in Qt. You would need to ifdef the different OS memory calls.