Skip to content

Commit

Permalink
refactor PerfettoSession to TracingSession
Browse files Browse the repository at this point in the history
  • Loading branch information
esseivaju committed May 23, 2024
1 parent cb7981d commit f22e751
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
9 changes: 3 additions & 6 deletions app/celer-sim/celer-sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
# include "RunnerInputIO.json.hh"
#endif

#if CELERITAS_USE_PERFETTO
# include "corecel/sys/PerfettoSession.hh"
#endif
#include "corecel/sys/TracingSession.hh"

using namespace std::literals::string_view_literals;

Expand Down Expand Up @@ -80,10 +78,9 @@ int get_openmp_thread()
void run(std::istream* is, std::shared_ptr<OutputRegistry> output)
{
CELER_EXPECT(is);
#if CELERITAS_USE_PERFETTO
PerfettoSession tracing_session("celer-sim.perfetto-trace");
TracingSession tracing_session("celer-sim.perfetto-trace");
tracing_session.start();
#endif

ScopedProfiling profile_this{"celer-sim"};
ScopedMem record_mem("celer-sim.run");

Expand Down
2 changes: 1 addition & 1 deletion src/corecel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if(CELERITAS_USE_Perfetto)
list(APPEND PRIVATE_DEPS Celeritas::Perfetto)
list(APPEND SOURCES
sys/Counter.perfetto.cc
sys/PerfettoSession.cc
sys/TracingSession.perfetto.cc
sys/ScopedProfiling.perfetto.cc
)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file corecel/sys/PerfettoSession.hh
//! \file corecel/sys/TracingSession.hh
//! \brief RAII class for managing a perfetto session and its resources.
//---------------------------------------------------------------------------//
#pragma once
Expand All @@ -14,8 +14,6 @@
#include "celeritas_config.h"
#include "corecel/Macros.hh"

#include "PerfettoSession.hh"

namespace perfetto
{
class TracingSession;
Expand All @@ -30,23 +28,36 @@ enum class ProfilingBackend : uint32_t
System
};

class PerfettoSession
#if CELERITAS_USE_PERFETTO
class TracingSession
{
public:
explicit PerfettoSession();
PerfettoSession(std::string_view);
~PerfettoSession();
TracingSession();
explicit TracingSession(std::string_view);
~TracingSession();

void start();
//!@{
//! Prevent copying and moving for RAII class
CELER_DEFAULT_MOVE_DELETE_COPY(PerfettoSession);
CELER_DEFAULT_MOVE_DELETE_COPY(TracingSession);
//!@}
void start();

private:
bool started_{false};
std::unique_ptr<perfetto::TracingSession> session_;
int fd_{-1};
};
#else

//! noop
class TracingSession
{
public:
TracingSession() = default;
explicit TracingSession(std::string_view) {}

void start() {};
};
#endif

} // namespace celeritas
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file corecel/sys/PerfettoSession.cc
//! \file corecel/sys/TracingSession.perfetto.cc
//! \brief RAII class for managing a perfetto session and its resources.
//---------------------------------------------------------------------------//
#include "PerfettoSession.hh"
#include "TracingSession.hh"

#include <fcntl.h>
#include <perfetto.h>
Expand Down Expand Up @@ -63,7 +63,7 @@ perfetto::TraceConfig configure_session()
namespace celeritas
{

PerfettoSession::PerfettoSession()
TracingSession::TracingSession()
: session_{initialize_session(ProfilingBackend::System)}
{
if (use_profiling())
Expand All @@ -72,7 +72,7 @@ PerfettoSession::PerfettoSession()
}
}

PerfettoSession::PerfettoSession(std::string_view filename)
TracingSession::TracingSession(std::string_view filename)
: session_{initialize_session(ProfilingBackend::InProcess)}, fd_{[&] {
return use_profiling()
? open(filename.data(), O_RDWR | O_CREAT | O_TRUNC, 0660)
Expand All @@ -85,7 +85,7 @@ PerfettoSession::PerfettoSession(std::string_view filename)
}
}

PerfettoSession::~PerfettoSession()
TracingSession::~TracingSession()
{
if (use_profiling())
{
Expand All @@ -99,7 +99,7 @@ PerfettoSession::~PerfettoSession()
}
}
}
void PerfettoSession::start()
void TracingSession::start()
{
if (use_profiling())
{
Expand Down

0 comments on commit f22e751

Please sign in to comment.