mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-16 09:05:41 +00:00
!6308 optimize: support trace wifi direct per-request and simplify implement
Merge pull request !6308 from waibozie/master
This commit is contained in:
commit
8a8f753345
@ -17,16 +17,9 @@
|
||||
|
||||
#include "hitrace/trace.h"
|
||||
|
||||
|
||||
namespace OHOS::SoftBus {
|
||||
static constexpr uint32_t TRACE_ID_OFFSET = 32;
|
||||
|
||||
WifiDirectTrace::WifiDirectTrace(const std::string &requestDeviceId, const std::string &receiveDeviceId)
|
||||
{
|
||||
this->requestDeviceId = requestDeviceId;
|
||||
this->receiverDeviceId = receiveDeviceId;
|
||||
}
|
||||
|
||||
static uint64_t ConvertTraceChainId(const std::string &requestDeviceId, const std::string &receiveDeviceId)
|
||||
{
|
||||
uint32_t request = 0;
|
||||
@ -44,19 +37,26 @@ static uint64_t ConvertTraceChainId(const std::string &requestDeviceId, const st
|
||||
return chainID;
|
||||
}
|
||||
|
||||
void WifiDirectTrace::StartTrace()
|
||||
void WifiDirectTrace::StartTrace(const std::string &requestDeviceId, const std::string &receiverDeviceId)
|
||||
{
|
||||
uint64_t chainId = ConvertTraceChainId(requestDeviceId, receiverDeviceId);
|
||||
// TODO: flags and name should specified
|
||||
auto hiTraceId = OHOS::HiviewDFX::HiTraceChain::Begin("", 0);
|
||||
hiTraceId.SetChainId(chainId);
|
||||
OHOS::HiviewDFX::HiTraceChain::SetId(hiTraceId);
|
||||
traceId = hiTraceId;
|
||||
auto traceId = OHOS::HiviewDFX::HiTraceChain::Begin("", 0);
|
||||
traceId.SetChainId(chainId);
|
||||
traceId.SetSpanId(0);
|
||||
OHOS::HiviewDFX::HiTraceChain::SetId(traceId);
|
||||
}
|
||||
|
||||
void WifiDirectTrace::StopTrace()
|
||||
{
|
||||
auto traceId = OHOS::HiviewDFX::HiTraceChain::GetId();
|
||||
OHOS::HiviewDFX::HiTraceChain::End(traceId);
|
||||
}
|
||||
|
||||
void WifiDirectTrace::SetRequestId(uint64_t requestId)
|
||||
{
|
||||
auto traceId = OHOS::HiviewDFX::HiTraceChain::GetId();
|
||||
traceId.SetSpanId(requestId);
|
||||
OHOS::HiviewDFX::HiTraceChain::SetId(traceId);
|
||||
}
|
||||
|
||||
} // namespace OHOS::SoftBus
|
||||
|
@ -1,38 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WIFI_DIRECT_TRACE_H
|
||||
#define WIFI_DIRECT_TRACE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hitrace/trace.h"
|
||||
|
||||
namespace OHOS::SoftBus {
|
||||
class WifiDirectTrace {
|
||||
public:
|
||||
WifiDirectTrace(const std::string &requestDeviceId, const std::string &receiveDeviceId);
|
||||
void StartTrace();
|
||||
void StopTrace();
|
||||
|
||||
private:
|
||||
std::string requestDeviceId;
|
||||
std::string receiverDeviceId;
|
||||
|
||||
OHOS::HiviewDFX::HiTraceId traceId;
|
||||
static void StartTrace(const std::string &requestDeviceId, const std::string &receiveDeviceId);
|
||||
static void StopTrace();
|
||||
static void SetRequestId(uint64_t requestId);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace OHOS::SoftBus
|
||||
#endif // WIFI_DIRECT_TRACE_H
|
||||
|
@ -57,11 +57,10 @@ void WifiDirectExecutor::Run(std::shared_ptr<WifiDirectProcessor> processor)
|
||||
processor_ = std::move(processor);
|
||||
do {
|
||||
if (IsActive()) {
|
||||
trace_ = std::make_shared<WifiDirectTrace>(WifiDirectUtils::GetLocalUuid(), remoteDeviceId_);
|
||||
WifiDirectTrace::StartTrace(WifiDirectUtils::GetLocalUuid(), remoteDeviceId_);
|
||||
} else {
|
||||
trace_ = std::make_shared<WifiDirectTrace>(remoteDeviceId_, WifiDirectUtils::GetLocalUuid());
|
||||
WifiDirectTrace::StartTrace(remoteDeviceId_, WifiDirectUtils::GetLocalUuid());
|
||||
}
|
||||
trace_->StartTrace();
|
||||
|
||||
processor_->BindExecutor(this);
|
||||
try {
|
||||
@ -73,10 +72,9 @@ void WifiDirectExecutor::Run(std::shared_ptr<WifiDirectProcessor> processor)
|
||||
ProcessUnHandleCommand();
|
||||
}
|
||||
|
||||
trace_->StopTrace();
|
||||
trace_ = nullptr;
|
||||
std::lock_guard lock(processorLock_);
|
||||
processor_ = nullptr;
|
||||
WifiDirectTrace::StopTrace();
|
||||
} while (scheduler_.ProcessNextCommand(this, processor_));
|
||||
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "executor terminate");
|
||||
|
@ -68,7 +68,6 @@ protected:
|
||||
std::thread thread_;
|
||||
|
||||
bool active_;
|
||||
std::shared_ptr<WifiDirectTrace> trace_;
|
||||
|
||||
bool started_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user