!1799 开启SP_daemon sdk data time_wait端口复用

Merge pull request !1799 from harrysunv9x/sdkdata_fix
This commit is contained in:
openharmony_ci 2024-08-22 09:35:31 +00:00 committed by Gitee
commit 844db64622
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 16 additions and 25 deletions

View File

@ -53,12 +53,14 @@ namespace OHOS {
int i = 0;
int socketFd = 0;
struct sockaddr_in address;
const int reuse = 1;
socketFd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (socketFd < 0) {
LOGE("Create socket error.");
return -1;
}
setsockopt(socketFd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
std::fill_n(reinterpret_cast<char*>(&address), sizeof(address), 0);
address.sin_family = AF_INET;

View File

@ -231,7 +231,7 @@ std::string SmartPerfCommand::ExecCommand()
}
index++;
}
std::string outGpuCounterDataPath = "/data/local/tmp/gpu_counter.csv";
std::string outGpuCounterDataPath = "/data/local/tmp";
gpuCounter.StopCollect(outGpuCounterDataPath);
std::this_thread::sleep_for(std::chrono::milliseconds(freq));
LOGI("SmartPerfCommand::WriteCsv start");

View File

@ -277,21 +277,21 @@ void SPTask::StopSdkRecv()
return;
}
std::string outSdkDataPath = std::string(outSdkDataDirChar) + "/sdk_data.csv";
if (fopen(outSdkDataPath.c_str(), "w") == nullptr) {
sdkDataMtx.lock();
std::ofstream outFile;
outFile.open(outSdkDataPath.c_str(), std::ios::out | std::ios::trunc);
if (!outFile.is_open()) {
LOGE("data %s open failed", outSdkDataPath.c_str());
ResetSdkParam();
return;
}
std::lock_guard<std::mutex> lock(sdkDataMtx);
std::ofstream outFile;
outFile.open(outSdkDataPath.c_str(), std::ios::out | std::ios::trunc);
std::string title = "source,timestamp,eventName,enable,value\r";
outFile << title << std::endl;
for (const auto &item : sdkvec) {
outFile << item << std::endl;
}
outFile.close();
sdkDataMtx.unlock();
ResetSdkParam();
}
@ -299,34 +299,22 @@ void SPTask::InitDataFile()
{
std::vector<std::string> files = {"sdk_data.csv", "gpu_counter.csv"};
std::string fileDir = baseOutPath + "/" + curTaskInfo.sessionId;
std::string filePath;
std::ifstream infile;
char fileDirChar[PATH_MAX] = {0x00};
if (realpath(fileDir.c_str(), fileDirChar) == nullptr) {
LOGE("data dir %s is nullptr", fileDir.c_str());
return;
}
for (const auto &file: files) {
filePath = fileDirChar;
filePath = filePath + "/" + file;
if (fopen(filePath.c_str(), "w") == nullptr) {
LOGE("data %s open failed", filePath.c_str());
std::string filePath = fileDir + "/" + file;
char filePathChar[PATH_MAX] = {0x00};
if ((realpath(filePath.c_str(), filePathChar) == nullptr)) {
LOGE("%s is not exist, init finish.", filePath.c_str());
continue;
}
infile = std::ifstream(filePath.c_str());
if (infile.good()) {
infile.close();
std::remove(filePath.c_str());
}
std::remove(filePathChar);
}
}
void SPTask::AsyncGetDataMap(std::function<void(std::string data)> msgTask)
{
long long lastTime = SPUtils::GetCurTime();
std::lock_guard<std::mutex> lock(asyncDataMtx);
asyncDataMtx.lock();
std::map<std::string, std::string> dataMap;
dataMap.insert(std::pair<std::string, std::string>(std::string("timestamp"), std::to_string(lastTime)));
std::future<std::map<std::string, std::string>> fpsResult = AsyncCollectFps();
@ -353,6 +341,7 @@ void SPTask::AsyncGetDataMap(std::function<void(std::string data)> msgTask)
if (costTime < curTaskInfo.freq) {
std::this_thread::sleep_for(std::chrono::milliseconds(pTime - costTime));
}
asyncDataMtx.unlock();
}
ErrCode SPTask::StartTask(std::function<void(std::string data)> msgTask)
@ -431,7 +420,7 @@ void SPTask::StopGetInfo()
}
void SPTask::StopGpuCounterRecv()
{
std::string outGpuCounterDataPath = baseOutPath + "/" + curTaskInfo.sessionId + "/gpu_counter.csv";
std::string outGpuCounterDataPath = baseOutPath + "/" + curTaskInfo.sessionId;
gpuCounter.StopCollect(outGpuCounterDataPath);
}
void SPTask::StopTask()