mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 07:02:25 +00:00
add trace for fence
Signed-off-by: yexiandong <yexiandong@huawei.com>
This commit is contained in:
parent
2a2f3dbcd4
commit
ea20fa113f
@ -19,6 +19,7 @@
|
||||
#include "buffer_manager.h"
|
||||
#include "buffer_utils.h"
|
||||
#include "sync_fence.h"
|
||||
#include "sync_fence_tracker.h"
|
||||
|
||||
#define DEFINE_MESSAGE_VARIABLES(arg, ret, opt, LOGE) \
|
||||
MessageOption opt; \
|
||||
@ -79,6 +80,10 @@ GSError BufferClientProducer::RequestBuffer(const BufferRequestConfig &config, s
|
||||
bedata->ReadFromParcel(reply);
|
||||
retval.fence = SyncFence::ReadFromMessageParcel(reply);
|
||||
reply.ReadInt32Vector(&retval.deletingBuffers);
|
||||
|
||||
static SyncFenceTracker releaseFenceThread("Release Fence");
|
||||
releaseFenceThread.TrackFence(retval.fence);
|
||||
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
@ -108,6 +113,9 @@ GSError BufferClientProducer::FlushBuffer(uint32_t sequence, const sptr<BufferEx
|
||||
SEND_REQUEST_WITH_SEQ(BUFFER_PRODUCER_FLUSH_BUFFER, arguments, reply, option, sequence);
|
||||
CHECK_RETVAL_WITH_SEQ(reply, sequence);
|
||||
|
||||
static SyncFenceTracker acquireFenceThread("Acquire Fence");
|
||||
acquireFenceThread.TrackFence(fence);
|
||||
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,6 @@ RSRenderThread::RSRenderThread()
|
||||
ROSEN_LOGD("RSRenderThread DrawFrame(%" PRIu64 ") in %s", prevTimestamp_, renderContext_ ? "GPU" : "CPU");
|
||||
Animate(prevTimestamp_);
|
||||
Render();
|
||||
RS_ASYNC_TRACE_BEGIN("waiting GPU running", 1111); // 1111 means async trace code for gpu
|
||||
SendCommands();
|
||||
ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP);
|
||||
jankDetector_.CalculateSkippedFrame(renderStartTimeStamp, jankDetector_.GetSysTimeNs());
|
||||
|
@ -31,6 +31,7 @@ config("sync_fence_public_config") {
|
||||
"export",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits",
|
||||
"//foundation/graphic/graphic_2d/utils/log",
|
||||
]
|
||||
}
|
||||
|
||||
@ -38,6 +39,7 @@ ohos_shared_library("sync_fence") {
|
||||
sources = [
|
||||
"src/sync_fence.cpp",
|
||||
"src/sync_fence_timeline.cpp",
|
||||
"src/sync_fence_tracker.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":sync_fence_config" ]
|
||||
@ -46,10 +48,13 @@ ohos_shared_library("sync_fence") {
|
||||
|
||||
public_deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//commonlibrary/c_utils/base:utils",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
43
utils/sync_fence/export/sync_fence_tracker.h
Normal file
43
utils/sync_fence/export/sync_fence_tracker.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 UTILS_INCLUDE_SYNC_FENCE_TRACKER_H
|
||||
#define UTILS_INCLUDE_SYNC_FENCE_TRACKER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <event_handler.h>
|
||||
#include "sync_fence.h"
|
||||
|
||||
namespace OHOS {
|
||||
class SyncFenceTracker {
|
||||
public:
|
||||
explicit SyncFenceTracker(const std::string threadName);
|
||||
|
||||
SyncFenceTracker() = delete;
|
||||
~SyncFenceTracker() = default;
|
||||
|
||||
void TrackFence(const sptr<SyncFence>& fence);
|
||||
|
||||
private:
|
||||
const uint32_t SYNC_TIME_OUT = 3000;
|
||||
const std::string threadName_;
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr;
|
||||
std::atomic<uint32_t> fencesQueued_;
|
||||
std::atomic<uint32_t> fencesSignaled_;
|
||||
|
||||
void Loop(const sptr<SyncFence>& fence);
|
||||
};
|
||||
}
|
||||
#endif // UTILS_INCLUDE_SYNC_FENCE_TRACKER_H
|
70
utils/sync_fence/src/sync_fence_tracker.cpp
Normal file
70
utils/sync_fence/src/sync_fence_tracker.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#include "sync_fence_tracker.h"
|
||||
#include "hilog/log.h"
|
||||
#include "rs_trace.h"
|
||||
|
||||
namespace OHOS {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, 0xD001400, "SyncFence" };
|
||||
}
|
||||
|
||||
SyncFenceTracker::SyncFenceTracker(const std::string threadName)
|
||||
: threadName_(threadName),
|
||||
fencesQueued_(0),
|
||||
fencesSignaled_(0)
|
||||
{
|
||||
auto runner = OHOS::AppExecFwk::EventRunner::Create(threadName_);
|
||||
handler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
|
||||
void SyncFenceTracker::TrackFence(const sptr<SyncFence>& fence)
|
||||
{
|
||||
std::string fenceMsg;
|
||||
if (fence->SyncFileReadTimestamp() != SyncFence::FENCE_PENDING_TIMESTAMP) {
|
||||
fenceMsg = threadName_ + " " + std::to_string(fencesQueued_.load()) + " has signaled";
|
||||
RS_TRACE_NAME(fenceMsg.c_str());
|
||||
fencesQueued_++;
|
||||
fencesSignaled_++;
|
||||
return;
|
||||
}
|
||||
|
||||
fenceMsg = threadName_ + " " + std::to_string(fencesQueued_.load());
|
||||
RS_TRACE_NAME(fenceMsg.c_str());
|
||||
if (handler_) {
|
||||
handler_->PostTask([this, fence]() {
|
||||
Loop(fence);
|
||||
});
|
||||
fencesQueued_++;
|
||||
}
|
||||
}
|
||||
|
||||
void SyncFenceTracker::Loop(const sptr<SyncFence>& fence)
|
||||
{
|
||||
uint32_t fenceIndex = 0;
|
||||
fenceIndex = fencesSignaled_.load();
|
||||
{
|
||||
std::string fenceMsg = "Waiting for " + threadName_ + " " + std::to_string(fenceIndex);
|
||||
RS_TRACE_NAME(fenceMsg.c_str());
|
||||
int32_t result = fence->Wait(SYNC_TIME_OUT);
|
||||
if (result < 0) {
|
||||
HiLog::Error(LABEL, "Error waiting for SyncFence: %s", strerror(result));
|
||||
}
|
||||
}
|
||||
fencesSignaled_++;
|
||||
}
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user