Commit e1a0c48d authored by Antonio Caggiano's avatar Antonio Caggiano
Browse files

Initialize perfetto

Define some categories, initialize perfetto in Context constructor
and trace some GL entry-points and Context methods.

Change-Id: Ib41908442b0b741459d936bb099aca36c6de2aee
parent ff8bfbca
......@@ -380,7 +380,7 @@ angle_static_library("angle_common") {
public_deps = [
":angle_abseil",
":libperfetto",
":angle_perfetto",
":includes",
]
public_configs += [ ":angle_common_config" ]
......
......@@ -34,6 +34,7 @@
#include "common/angleutils.h"
#include "common/entry_points_enum_autogen.h"
#include "common/system_utils.h"
#include "common/trace.h"
namespace gl
{
......@@ -146,6 +147,8 @@ ScopedPerfEventHelper::~ScopedPerfEventHelper()
{
g_debugAnnotator->endEvent(mContext, mFunctionName, mEntryPoint);
}
TRACE_EVENT_END(ENTRY_POINTS);
}
void ScopedPerfEventHelper::begin(const char *format, ...)
......@@ -165,6 +168,8 @@ void ScopedPerfEventHelper::begin(const char *format, ...)
mCalledBeginEvent = true;
g_debugAnnotator->beginEvent(mContext, mEntryPoint, mFunctionName, buffer.data());
}
TRACE_EVENT_BEGIN(ENTRY_POINTS, perfetto::StaticString(mFunctionName));
}
LogMessage::LogMessage(const char *file, const char *function, int line, LogSeverity severity)
......
......@@ -22,6 +22,7 @@
#include "common/angleutils.h"
#include "common/entry_points_enum_autogen.h"
#include "common/platform.h"
#include "common/trace.h"
#if defined(ANGLE_PLATFORM_WINDOWS)
# include <sal.h>
......
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// trace.cpp: Tracing utilities.
#include "common/trace.h"
#if defined(ANGLE_USE_PERFETTO)
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
#endif
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// trace.h: Tracing utilities.
#ifndef COMMON_TRACE_H_
#define COMMON_TRACE_H_
#if defined(ANGLE_USE_PERFETTO)
# include <perfetto.h>
# define ENTRY_POINTS "entry-points"
# define VALIDATION "validation"
# define CONTEXT "context"
# define STATE_TRACKER "state-tracker"
# define BACKEND "backend"
PERFETTO_DEFINE_CATEGORIES(
perfetto::Category(ENTRY_POINTS).SetDescription("Events associated to GL API entry-points"),
perfetto::Category(VALIDATION).SetDescription("Events from the validation layer"),
perfetto::Category(CONTEXT).SetDescription("Events from the ANGLE context"),
perfetto::Category(STATE_TRACKER).SetDescription("Events from the ANGLE state-tracker"),
perfetto::Category(BACKEND).SetDescription("Events from the ANGLE backend"));
# define ANGLE_TRACE(c, e) TRACE_EVENT(c, e)
# define ANGLE_TRACE_EP(f) ANGLE_TRACE(ENTRY_POINTS, f)
# define ANGLE_TRACE_VAL(f) ANGLE_TRACE(VALIDATION, f)
# define ANGLE_TRACE_CTX(f) ANGLE_TRACE(CONTEXT, f)
# define ANGLE_TRACE_ST(f) ANGLE_TRACE(STATE_TRACKER, f)
# define ANGLE_TRACE_BE(f) ANGLE_TRACE(BACKEND, f)
#else
# define TRACE_EVENT_END(x)
# define TRACE_EVENT_BEGIN(x, y)
# define ENTRY_POINTS
# define ANGLE_TRACE(c, e) (void)(c)
# define ANGLE_TRACE_EP(f) (void)(f)
# define ANGLE_TRACE_VAL(f) (void)(f)
# define ANGLE_TRACE_CTX(f) (void)(f)
# define ANGLE_TRACE_ST(f) (void)(f)
# define ANGLE_TRACE_BE(f) (void)(f)
#endif
#endif // COMMON_TRACE_H_
......@@ -19,6 +19,7 @@
#include "common/platform.h"
#include "common/system_utils.h"
#include "common/utilities.h"
#include "common/trace.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Display.h"
......@@ -441,10 +442,26 @@ Context::Context(egl::Display *display,
// Implementations now require the display to be set at context creation.
ASSERT(mDisplay);
#if defined(ANGLE_USE_PERFETTO)
perfetto::TracingInitArgs args;
// The system backend writes events into a system Perfetto daemon,
// allowing merging app and system events (e.g., ftrace) on the same
// timeline. Requires the Perfetto `traced` daemon to be running (e.g.,
// on Android Pie and newer).
args.backends |= perfetto::kSystemBackend;
perfetto::Tracing::Initialize(args);
perfetto::TrackEvent::Register();
#endif
}
egl::Error Context::initialize()
{
ANGLE_TRACE_CTX("Context::initialize");
if (!mImplementation)
return egl::Error(EGL_NOT_INITIALIZED, "native context creation failed");
return egl::NoError();
......@@ -452,6 +469,8 @@ egl::Error Context::initialize()
void Context::initializeDefaultResources()
{
ANGLE_TRACE_CTX("Context::initializeDefaultResources");
mImplementation->setMemoryProgramCache(mMemoryProgramCache);
initCaps();
......@@ -654,6 +673,8 @@ void Context::initializeDefaultResources()
egl::Error Context::onDestroy(const egl::Display *display)
{
ANGLE_TRACE_CTX("Context::onDestroy");
if (!mHasBeenCurrent)
{
// The context is never current, so default resources are not allocated.
......@@ -765,6 +786,8 @@ egl::Error Context::makeCurrent(egl::Display *display,
egl::Surface *drawSurface,
egl::Surface *readSurface)
{
ANGLE_TRACE_CTX("Context::makeCurrent");
mDisplay = display;
if (!mHasBeenCurrent)
......@@ -813,6 +836,8 @@ egl::Error Context::makeCurrent(egl::Display *display,
egl::Error Context::unMakeCurrent(const egl::Display *display)
{
ANGLE_TRACE_CTX("Context::unMakeCurrent");
ANGLE_TRY(angle::ResultToEGL(mImplementation->onUnMakeCurrent(this)));
ANGLE_TRY(unsetDefaultFramebuffer());
......@@ -833,16 +858,22 @@ egl::Error Context::unMakeCurrent(const egl::Display *display)
BufferID Context::createBuffer()
{
ANGLE_TRACE_CTX("Context::createBuffer");
return mState.mBufferManager->createBuffer();
}
GLuint Context::createProgram()
{
ANGLE_TRACE_CTX("Context::createProgram");
return mState.mShaderProgramManager->createProgram(mImplementation.get()).value;
}
GLuint Context::createShader(ShaderType type)
{
ANGLE_TRACE_CTX("Context::createShader");
return mState.mShaderProgramManager
->createShader(mImplementation.get(), mState.mLimitations, type)
.value;
......@@ -850,22 +881,30 @@ GLuint Context::createShader(ShaderType type)
TextureID Context::createTexture()
{
ANGLE_TRACE_CTX("Context::createTexture");
return mState.mTextureManager->createTexture();
}
RenderbufferID Context::createRenderbuffer()
{
ANGLE_TRACE_CTX("Context::createRenderBuffer");
return mState.mRenderbufferManager->createRenderbuffer();
}
// Returns an unused framebuffer name
FramebufferID Context::createFramebuffer()
{
ANGLE_TRACE_CTX("Context::createFramebuffer");
return mState.mFramebufferManager->createFramebuffer();
}
void Context::genFencesNV(GLsizei n, FenceNVID *fences)
{
ANGLE_TRACE_CTX("Context::genFencesNV");
for (int i = 0; i < n; i++)
{
GLuint handle = mFenceNVHandleAllocator.allocate();
......@@ -876,11 +915,15 @@ void Context::genFencesNV(GLsizei n, FenceNVID *fences)
ProgramPipelineID Context::createProgramPipeline()
{
ANGLE_TRACE_CTX("Context::createProgramPipeline");
return mState.mProgramPipelineManager->createProgramPipeline();
}
GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
{
ANGLE_TRACE_CTX("Context::createShaderProgramv");
const ShaderProgramID shaderID = PackParam<ShaderProgramID>(createShader(type));
if (shaderID.value)
{
......@@ -940,16 +983,22 @@ GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLcha
MemoryObjectID Context::createMemoryObject()
{
ANGLE_TRACE_CTX("Context::createMemoryObject");
return mState.mMemoryObjectManager->createMemoryObject(mImplementation.get());
}
SemaphoreID Context::createSemaphore()
{
ANGLE_TRACE_CTX("Context::createSemaphore");
return mState.mSemaphoreManager->createSemaphore(mImplementation.get());
}
void Context::deleteBuffer(BufferID bufferName)
{
ANGLE_TRACE_CTX("Context::deleteBuffer");
Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
if (buffer)
{
......
......@@ -32,6 +32,8 @@ libangle_common_sources = [
"src/common/bitset_utils.h",
"src/common/debug.cpp",
"src/common/debug.h",
"src/common/trace.cpp",
"src/common/trace.h",
"src/common/entry_points_enum_autogen.cpp",
"src/common/entry_points_enum_autogen.h",
"src/common/event_tracer.cpp",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment