dtrace keep getting error "error on enabled probe...invalid user access in action #1" - dtrace

I am trying to use dtrace to calculate the fps of games in openGL and metal on the macOS. However, I keep getting an error saying:
dtrace: error on enabled probe ID 2 (ID 86178: pid2741:OpenGL:CGLFlushDrawable:entry): invalid user access in action #1
when trying to get the fps of openGL games and I have no idea why.
Here is the script I have for the program I am executing:
#pragma D option switchrate=1000ms
#pragma D option bufsize=4m
BEGIN
{
i=timestamp;
diff=0;
}
pid$1:OpenGL:CGLFlushDrawable:entry,
objc$1:CAMetalLayer:-nextDrawable:entry
{
time = timestamp;
diff = time - i;
i = time;
printf("%s,%s,%d",execname, probefunc, diff);
}
ERROR
/pid==0/
{
time = timestamp;
diff = time - i;
i = time;
printf("%d\n",diff);
}
I got the code above from the count it app's github page.

Related

strange logging timestamp with chrono::sleep_until

I am testing application's latency during UDP communication on windows 10.
I tried to send a message every 1 second and receive a response sent immediately from the remote.
Send thread
It works every 1 second.
auto start = std::chrono::system_clock::now();
unsigned int count = 1;
while (destroyFlag.load(std::memory_order_acquire) == false)
{
if (isReady() == false)
{
break;
}
/*to do*/
worker_();
std::this_thread::sleep_until(start + std::chrono::milliseconds(interval_)* count++);
}
worker_()
Send thread call this. just send message and make log string.
socket_.send(address_);
logger_.log("," + std::string("Send") + "\n");
Receiver
When message arrives, it creates a receive log string and flushes it to a file.
auto& queueData = socket_.getQueue();
while (queueData.size() > 0)
{
auto str = queueData.dequeue();
logger_.log(",Receive" + str + "\n");
logger_.flush();
}
I've been testing it overnight and I can't figure out why I got this result.
chart for microseconds
x-axis : Hour_Minute_second
y-axis : microseconds
For a few hours it seemed to work as expected. But after that, the time gradually changed and went to a different time zone.
Does anyone know why this is happening?
std::chrono::steady_clock is working.
It made my charts straight.
And another way, turn off the windows automatically time synchronize.

Problem with esp8266 sending large JSON Document via MQTT

I developed a little application that read data from a sensor, store them in SPIFFS memory of my wemos D1 mini (esp8266) and then create a JSON Document and send it via MQTT to my topic. The problem is that as long as I send a JSON Doc with 10 object everything works great, but when I increase the size of the doc over 10 object nothing works. Eventually I need to send a JSON doc with 100 object inside.
What have I already done?
I'm using PubSubClient and I already set the MAX_PACKET_SIZE to the correct value
Using arduinojson assistant I found out the size of my JSON Document (8192 bytes)
I tried to use mqtt.fx to test if the problem was the esp8266 or the mqtt broker. Using mqtt.fx I'm able to send a JSON doc with 100 objects
As soon as I increase the size of the JSON doc I get a wdt error from the serial monitor of my arduino IDE.
I search the internet for wdt error but I don't get what they are and how to solve my problem
Last things I already tried to show on the serial monitor the file.txt in the SPIFFS where I store the data and I can store and then read the 100 object
So in the end I think it's an esp8266 problem and not PubSubClient or MQTT. Am I right?
Does anyone of you here ever encountered this problem before or have some other test I can run?
I search the internet for wdt error but I don't get what they are and how to solve my problem
WDT stands for a Watch Dog Timer. https://os.mbed.com/cookbook/WatchDog-Timer#:~:text=A%20watchdog%20timer%20(WDT)%20is,a%20software%20or%20hardware%20fault.
A watchdog timer (WDT) is a hardware timer that automatically generates a system reset if the main program neglects to periodically service it. It is often used to automatically reset an embedded device that hangs because of a software or hardware fault. Some systems may also refer to it as a computer operating properly (COP) timer. Many microcontrollers including the mbed processor have watchdog timer hardware.
Let's paint a better picture with an example. Let's say that you setup a WDT with a time of 10 seconds. Then the WDT starts counting down from 10 seconds. If it reaches 0 the processor will reset. "Feeding" the WDT will reset the countdown to the original value in this case 10 seconds. So if the WDT has counted down to 4 seconds remaining and you feed it, it resets the countdown back to 10 and starts counting down again.
Does anyone of you here ever encountered this problem before or have some other test I can run?
It looks to me like sending a larger JSON object takes a longer period of time than what the WDT is set for. One possibility would be to break up the JSON object into multiple pieces and send it in smaller chunks instead of one large one. This way the time between WDT "feedings" is reduced. I have no idea if this would be possible for you to change. But this should at least give you a better idea of what's happening.
OK in the end the problem was that sending a large JsonDocument triggered the WDT and the only way I found to overcome this problem was, as suggested by adamvz, to create a main file with all the 100 object, then call a function to split that file in 10 smaller one and send each of them over the internet through an HTTP request or Mosquitto.
Supposing you already created the main file in the spiffs memory, then:
This to split the main file:
void WritePacks() {
sourceFile = LittleFS.open("/file.txt", "r");
if (!sourceFile) {
Serial.println(F("Error: file.txt open failed"));
} else {
Serial.println("File open w/ success");
for (byte idx = 0; idx < outputCount; idx++) {
String aLine;
aLine.reserve(capacity);
if (sourceFile.available() == 0) break;
destinationFile = LittleFS.open(outputFileNames[idx], "w");
if (!destinationFile) {
Serial.print(F("can't open destination "));
Serial.println(outputFileNames[idx]);
break;
} else {
int lineCount = 0;
while (sourceFile.available() && (lineCount <= 10)) {
aLine = sourceFile.readStringUntil('\n');
destinationFile.println(aLine); // double check if the '\n' is in the String or not (--> print or println accordingly)
lineCount++;
}
outputIndex = idx;
Serial.println(outputIndex);
destinationFile.close();
}
} // end for
sourceFile.close();
}
}//end WritePacks
This to publish:
//------ HTTP Publish ------
void httpPublish(){
const char * outputFileNames[] = {"/out1.txt", "/out2.txt", "/out3.txt", "/out4.txt", "/out5.txt", "/out6.txt", "/out7.txt", "/out8.txt", "/out9.txt", "/out10.txt"};
const byte outputCount = sizeof outputFileNames / sizeof outputFileNames[0];
byte outputIndex = 0;
File sourceFile;
File destinationFile;
//Serial.println(capacity);
for (byte idx = 0; idx < outputCount; idx++) {
DynamicJsonDocument doc(capacity);
DynamicJsonDocument globalDoc(capacity);
StaticJsonDocument <1024> localDoc;
String aLine;
aLine.reserve(capacity);
destinationFile = LittleFS.open(outputFileNames[idx], "r");
if (!destinationFile) {
Serial.print(F("can't open destination "));
Serial.println(outputFileNames[idx]);
break;
} else {
Serial.print("Reading: ");
Serial.println(outputFileNames[idx]);
//int lineCount = 0;
while (destinationFile.available()) {
aLine = destinationFile.readStringUntil('\n');
DeserializationError error = deserializeJson(localDoc, aLine);
if (!error) globalDoc.add(localDoc);
else{ Serial.println("Error Writing All files");}
}//while
JsonObject Info = doc.createNestedObject("Info");
Info["Battery"] = battery;
Info["ID"] = id;
Info["Latitudine"] = latitudine;
Info["Longitudine"] = longitudine;
JsonArray Data = doc.createNestedArray("Data");
Data.add(globalDoc);
HTTPClient http;
//Send request
http.begin("yourURL");
char buffer[capacity];
size_t n = serializeJson(doc, buffer);
http.POST(buffer);
Serial.println(buffer);
http.end();
destinationFile.close();
}
}// end for
}//end httpPublish

How not to display system errors in C++?

I have a program that check some information about logical drives but if the drive like A:\ is not in it will display an error, like "
Windows - No Disk
Exception Processing Message C00000013 Parameters 75b76 etc
Cancel Try Again Continue
Is there any way to disable such errors to appear and just let the program continue or automatically press continue button ?
UPDATE:
DWORD drives = GetLogicalDrives();
for (int i = 0; i<26; i++)
{
if ((drives & (1 << i)))
{
TCHAR driveName[] = { TEXT('A') + i, TEXT(':'), TEXT('\\'), TEXT('\0') };
cout<<driveName;
}
}
If i run the code on XP it get the error that A:\ doesn't exists. Is there any way to disable this ?
You're looking for SetErrorMode(SEM_FAILCRITICALERRORS)

requested the Runtime to terminate it in an unusual way

My problem is:
I built a c++ code for simulating a communication network (using OMNeT++ discrete event simulator) until there is no errors and the simulation completed, when I tried to increase the number of simulated entities, in any run at some point of time the simulation stops with a message printed in the command prompt says “This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information” and an error message displayed in a dedicated window under the title Application error says ”The exception unknown software exception (0x40000015) occurred in the application at location ....... ”
I think the problem, i.e., the simulation stops at and due to this part " ((cMessage *)msg->dup() " in the following code (but that may not be correct):
********
`void ChannelAccess::sendToChannel(AirFrame *msg)
{
const ChannelControl::ModuleList& neighbors = cc->getNeighbors(myHostRef);
coreEV << "sendToChannel: sending to gates\n";
// loop through all hosts in range
ChannelControl::ModuleList::const_iterator it;
for (it = neighbors.begin(); it != neighbors.end(); ++it)
{
cModule *mod = *it;
// we need to send to each radioIn[] gate
cGate *radioGate = mod->gate("radioIn");
if (radioGate == NULL)
error("module %s must have a gate called radioIn", mod->fullPath().c_str());
for (int i = 0; i < radioGate->size(); i++)
{
ChannelControl::HostRef h = cc->lookupHost(mod);
if (h == NULL)
error("cannot find module in channel control");
if (h->channel == msg->getChannelNumber())
{
coreEV << "sending message to host listening on the same channel\n";
// account for propagation delay, based on distance in meters
// Over 300m, dt=1us=10 bit times # 10Mbps
sendDirect((cMessage *)msg->dup(),myHostRef->pos.distance(h->pos) / LIGHT_SPEED, mod, radioGate->id() + i);
}
else
coreEV << "skipping host listening on a different channel\n";
}
}
// register transmission in ChannelControl
cc->addOngoingTransmission(myHostRef, msg);
}
`
*********
So, any help will be appreciated as I would like to run the simulation for large number of nodes.
For knowledge I use win xp SP3 and win 7, OMNet++ 3.3, Microsoft visual c++ 2005 express edition, one of the computers I ran the simulation on is i7 processor with 8G RAM.
Thank you in advance.

Restarted Process Output won't Read

So I made a GUI in C++ which calls a child process every time a button is clicked twice. The StandardOutput is redirected, doesn't use ShellExecute.
I made a simple dummy process to test it, let's say dummy.exe, which basically just do this :
void() {
printf("0");
}
And that's all. The process will exit itself after 0 is plotted.
The process is started when a button is clicked, which does this :
private: System::Void bt_getData_Click(System::Object^ sender, System::EventArgs^ e) {
if (bt_getData->Text == "Get Data") {
proc->Start();
bt_getData->Text = "Stop";
}
else if (bt_getData->Text == "Stop") {
bt_getData->Text = "Get Data";
}
}
Then it will read the output using the OutputDataReceived EventHandler.
The problem is when I clicked the button again, the process will be Restarted, but the GUI can't read the new Output.
Case 1 : I cancelled the output read in the OutputDataReceived EventHandler then restart the process, but the next restarted process output can't be read.
private: System::Void outputData(System::Object^ sender, System::Diagnostics::DataReceivedEventArgs^ e) {
x0 = xt;
xt += 1;
if (xt*x_scale > pb_Graph->Width) {
x0 = 0;
xt = 0;
imgTemp = gcnew Bitmap(pb_Graph->Image, 460, 460);
gpcGraph->Clear(Color::Transparent);
}
y0 = yt;
yt = Convert::ToInt16(e->Data);
ret_index++;
if (ret_index > 2047) ret_index = 0;
gpcGraph->DrawLine(greenPen,(float)x0*x_scale,pb_Graph->Height - (float)y0/y_scale - y_null,(float)xt*x_scale,pb_Graph->Height - (float)yt/y_scale - y_null);
pb_Graph->Refresh();
}
After three times restart, this error shows :
An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
Additional information: An async read operation has already been started on the stream.
Case 2 : I didn't cancel the output read. The same error with case 1 shows, but it is still understandable to me.
Case 3 : I didn't redo the BeginOutputReadLine() when restarting. The error doesn't shown, but the restarted process output can't be read.
My actual goal is to restart the process periodically using a 1 mS timer, so I tested the restart process first using button. But it seems that the newly generated output can't be read.
Any help would be appreciated :)
Okay... I've managed to prevent the errors using different method, which is to call
process->StandardOutput->ReadLine();
This way the async stream reading won't happen.