mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 00:21:11 +08:00
More stability in networking
This commit is contained in:
parent
20d3fb47a6
commit
a422f69deb
@ -347,10 +347,29 @@ void EasyMainWindow::onCollapseAllClicked(bool)
|
|||||||
|
|
||||||
void EasyMainWindow::onCaptureClicked(bool)
|
void EasyMainWindow::onCaptureClicked(bool)
|
||||||
{
|
{
|
||||||
|
if(m_client != nullptr)
|
||||||
|
{
|
||||||
|
profiler::net::Message requestMessage(profiler::net::MESSAGE_TYPE_REQUEST_START_CAPTURE);
|
||||||
|
m_client->write((const char*)&requestMessage, sizeof(requestMessage));
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Warning" ,"No connection with profiling app",QMessageBox::Close);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QMessageBox::information(this,"Capturing frames..." ,"Close this window to stop capturing.",QMessageBox::Close);
|
QMessageBox::information(this,"Capturing frames..." ,"Close this window to stop capturing.",QMessageBox::Close);
|
||||||
|
|
||||||
profiler::net::Message requestMessage(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
|
if(m_client != nullptr)
|
||||||
m_client->write((const char*)&requestMessage, sizeof(requestMessage));
|
{
|
||||||
|
profiler::net::Message requestMessage(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
|
||||||
|
m_client->write((const char*)&requestMessage, sizeof(requestMessage));
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,"Warning" ,"Application was disconnected",QMessageBox::Close);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//int sock = nn_socket (AF_SP, NN_BUS);
|
//int sock = nn_socket (AF_SP, NN_BUS);
|
||||||
//assert (sock >= 0);
|
//assert (sock >= 0);
|
||||||
@ -536,7 +555,7 @@ void EasyMainWindow::readTcpData()
|
|||||||
|
|
||||||
|
|
||||||
profiler::net::Message* message = (profiler::net::Message*)data.data();
|
profiler::net::Message* message = (profiler::net::Message*)data.data();
|
||||||
qInfo() << "rec size: " << data.size() << " " << QString(data);;
|
//qInfo() << "rec size: " << data.size() << " " << QString(data);;
|
||||||
if(!m_recFrames && !message->isEasyNetMessage()){
|
if(!m_recFrames && !message->isEasyNetMessage()){
|
||||||
return;
|
return;
|
||||||
}else if(m_recFrames){
|
}else if(m_recFrames){
|
||||||
@ -569,6 +588,8 @@ void EasyMainWindow::readTcpData()
|
|||||||
of << m_receivedProfileData.str();
|
of << m_receivedProfileData.str();
|
||||||
of.close();
|
of.close();
|
||||||
|
|
||||||
|
m_receivedProfileData.str(std::string());
|
||||||
|
m_receivedProfileData.clear();
|
||||||
loadFile(QString(tempfilename.c_str()));
|
loadFile(QString(tempfilename.c_str()));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -582,7 +603,7 @@ void EasyMainWindow::readTcpData()
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
qInfo() << "Receive unknown " << message->type;
|
//qInfo() << "Receive unknown " << message->type;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -599,11 +620,15 @@ void EasyMainWindow::onNewConnection()
|
|||||||
qInfo() << "New connection!" << m_client;
|
qInfo() << "New connection!" << m_client;
|
||||||
|
|
||||||
|
|
||||||
connect(m_client, &QAbstractSocket::disconnected, m_client, &QObject::deleteLater) ;
|
connect(m_client, SIGNAL(disconnected()), this, SLOT(onDisconnection())) ;
|
||||||
connect(m_client, SIGNAL(readyRead()), this, SLOT(readTcpData()) );
|
connect(m_client, SIGNAL(readyRead()), this, SLOT(readTcpData()) );
|
||||||
|
|
||||||
profiler::net::Message requestMessage(profiler::net::MESSAGE_TYPE_REQUEST_START_CAPTURE);
|
|
||||||
m_client->write((const char*)&requestMessage, sizeof(requestMessage));
|
}
|
||||||
|
|
||||||
|
void EasyMainWindow::onDisconnection()
|
||||||
|
{
|
||||||
|
m_client = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -96,8 +96,8 @@ protected:
|
|||||||
::profiler::SerializedData m_serializedDescriptors;
|
::profiler::SerializedData m_serializedDescriptors;
|
||||||
EasyFileReader m_reader;
|
EasyFileReader m_reader;
|
||||||
|
|
||||||
QTcpServer* m_server;
|
QTcpServer* m_server = nullptr;
|
||||||
QTcpSocket* m_client;
|
QTcpSocket* m_client = nullptr;
|
||||||
std::stringstream m_receivedProfileData;
|
std::stringstream m_receivedProfileData;
|
||||||
bool m_recFrames = false;
|
bool m_recFrames = false;
|
||||||
public:
|
public:
|
||||||
@ -128,6 +128,7 @@ protected slots:
|
|||||||
|
|
||||||
void readTcpData();
|
void readTcpData();
|
||||||
void onNewConnection();
|
void onNewConnection();
|
||||||
|
void onDisconnection();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Private non-virtual methods
|
// Private non-virtual methods
|
||||||
|
@ -240,7 +240,7 @@ int main(int argc, char* argv[])
|
|||||||
std::cout << "Resource loading count: " << RESOURCE_LOADING_COUNT << std::endl;
|
std::cout << "Resource loading count: " << RESOURCE_LOADING_COUNT << std::endl;
|
||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
EASY_PROFILER_ENABLE;
|
//EASY_PROFILER_ENABLE;
|
||||||
EASY_MAIN_THREAD;
|
EASY_MAIN_THREAD;
|
||||||
profiler::startListenSignalToCapture();
|
profiler::startListenSignalToCapture();
|
||||||
//one();
|
//one();
|
||||||
@ -285,5 +285,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
std::cout << "Blocks count: " << blocks_count << std::endl;
|
std::cout << "Blocks count: " << blocks_count << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
profiler::stopListenSignalToCapture();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,8 @@ ProfileManager::ProfileManager()
|
|||||||
// #ifdef _WIN32
|
// #ifdef _WIN32
|
||||||
// PREVIOUS_FILTER = SetUnhandledExceptionFilter(easyTopLevelExceptionFilter);
|
// PREVIOUS_FILTER = SetUnhandledExceptionFilter(easyTopLevelExceptionFilter);
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
m_stopListen = ATOMIC_VAR_INIT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileManager::~ProfileManager()
|
ProfileManager::~ProfileManager()
|
||||||
@ -266,14 +268,17 @@ void ProfileManager::startListenSignalToCapture()
|
|||||||
{
|
{
|
||||||
if(!m_isAlreadyListened)
|
if(!m_isAlreadyListened)
|
||||||
{
|
{
|
||||||
|
m_stopListen.store(false);
|
||||||
m_listenThread = std::thread(&ProfileManager::startListen, this);
|
m_listenThread = std::thread(&ProfileManager::startListen, this);
|
||||||
m_isAlreadyListened = true;
|
m_isAlreadyListened = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::stopListenSignalToCapture()
|
void ProfileManager::stopListenSignalToCapture()
|
||||||
{
|
{
|
||||||
|
m_stopListen.store(true);
|
||||||
|
m_isAlreadyListened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::setEnabled(bool isEnable)
|
void ProfileManager::setEnabled(bool isEnable)
|
||||||
@ -436,6 +441,8 @@ const char* ProfileManager::setThreadName(const char* name, const char* filename
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
void error(const char *msg)
|
void error(const char *msg)
|
||||||
@ -466,14 +473,25 @@ void ProfileManager::startListen()
|
|||||||
(char *)&serv_addr.sin_addr.s_addr,
|
(char *)&serv_addr.sin_addr.s_addr,
|
||||||
server->h_length);
|
server->h_length);
|
||||||
serv_addr.sin_port = htons(portno);
|
serv_addr.sin_port = htons(portno);
|
||||||
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
|
|
||||||
error("ERROR connecting");
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = 1; /* 30 Secs Timeout */
|
||||||
|
tv.tv_usec = 0; // Not init'ing this can cause strange errors
|
||||||
|
|
||||||
|
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
|
||||||
|
|
||||||
|
while(!m_stopListen.load() && (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0 ) ) {}
|
||||||
|
//if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
|
||||||
|
// error("ERROR connecting");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
profiler::net::Message replyMessage(profiler::net::MESSAGE_TYPE_REPLY_START_CAPTURING);
|
profiler::net::Message replyMessage(profiler::net::MESSAGE_TYPE_REPLY_START_CAPTURING);
|
||||||
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
bzero(buffer,256);
|
bzero(buffer,256);
|
||||||
while(1)
|
while(!m_stopListen.load())
|
||||||
{
|
{
|
||||||
n = read(sockfd,buffer,255);
|
n = read(sockfd,buffer,255);
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -220,7 +221,7 @@ class ProfileManager final
|
|||||||
int m_socket = 0;//TODO crossplatform
|
int m_socket = 0;//TODO crossplatform
|
||||||
|
|
||||||
uint32_t dumpBlocksToStream(StreamWriter& _stream);
|
uint32_t dumpBlocksToStream(StreamWriter& _stream);
|
||||||
|
std::atomic_bool m_stopListen;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static ProfileManager& instance();
|
static ProfileManager& instance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user