0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 16:11:02 +08:00

More stability in networking

This commit is contained in:
Sergey Yagovtsev 2016-09-08 23:15:01 +03:00
parent 20d3fb47a6
commit a422f69deb
5 changed files with 62 additions and 15 deletions

View File

@ -347,10 +347,29 @@ void EasyMainWindow::onCollapseAllClicked(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);
profiler::net::Message requestMessage(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
m_client->write((const char*)&requestMessage, sizeof(requestMessage));
if(m_client != nullptr)
{
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);
//assert (sock >= 0);
@ -536,7 +555,7 @@ void EasyMainWindow::readTcpData()
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()){
return;
}else if(m_recFrames){
@ -569,6 +588,8 @@ void EasyMainWindow::readTcpData()
of << m_receivedProfileData.str();
of.close();
m_receivedProfileData.str(std::string());
m_receivedProfileData.clear();
loadFile(QString(tempfilename.c_str()));
}
@ -582,7 +603,7 @@ void EasyMainWindow::readTcpData()
} break;
default:
qInfo() << "Receive unknown " << message->type;
//qInfo() << "Receive unknown " << message->type;
break;
}
@ -599,11 +620,15 @@ void EasyMainWindow::onNewConnection()
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()) );
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;
}
//////////////////////////////////////////////////////////////////////////

View File

@ -96,8 +96,8 @@ protected:
::profiler::SerializedData m_serializedDescriptors;
EasyFileReader m_reader;
QTcpServer* m_server;
QTcpSocket* m_client;
QTcpServer* m_server = nullptr;
QTcpSocket* m_client = nullptr;
std::stringstream m_receivedProfileData;
bool m_recFrames = false;
public:
@ -128,6 +128,7 @@ protected slots:
void readTcpData();
void onNewConnection();
void onDisconnection();
private:
// Private non-virtual methods

View File

@ -240,7 +240,7 @@ int main(int argc, char* argv[])
std::cout << "Resource loading count: " << RESOURCE_LOADING_COUNT << std::endl;
auto start = std::chrono::system_clock::now();
EASY_PROFILER_ENABLE;
//EASY_PROFILER_ENABLE;
EASY_MAIN_THREAD;
profiler::startListenSignalToCapture();
//one();
@ -285,5 +285,7 @@ int main(int argc, char* argv[])
std::cout << "Blocks count: " << blocks_count << std::endl;
profiler::stopListenSignalToCapture();
return 0;
}

View File

@ -183,6 +183,8 @@ ProfileManager::ProfileManager()
// #ifdef _WIN32
// PREVIOUS_FILTER = SetUnhandledExceptionFilter(easyTopLevelExceptionFilter);
// #endif
m_stopListen = ATOMIC_VAR_INIT(false);
}
ProfileManager::~ProfileManager()
@ -266,14 +268,17 @@ void ProfileManager::startListenSignalToCapture()
{
if(!m_isAlreadyListened)
{
m_stopListen.store(false);
m_listenThread = std::thread(&ProfileManager::startListen, this);
m_isAlreadyListened = true;
}
}
void ProfileManager::stopListenSignalToCapture()
{
m_stopListen.store(true);
m_isAlreadyListened = false;
}
void ProfileManager::setEnabled(bool isEnable)
@ -436,6 +441,8 @@ const char* ProfileManager::setThreadName(const char* name, const char* filename
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
void error(const char *msg)
@ -466,14 +473,25 @@ void ProfileManager::startListen()
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
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);
char buffer[256];
bzero(buffer,256);
while(1)
while(!m_stopListen.load())
{
n = read(sockfd,buffer,255);

View File

@ -32,6 +32,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#include <functional>
#include <sstream>
#include <string.h>
#include <atomic>
//////////////////////////////////////////////////////////////////////////
@ -220,7 +221,7 @@ class ProfileManager final
int m_socket = 0;//TODO crossplatform
uint32_t dumpBlocksToStream(StreamWriter& _stream);
std::atomic_bool m_stopListen;
public:
static ProfileManager& instance();