PXL
profile.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2026 XCENA Inc.
3 //
4 // pxl::Profile — libpxl-side entry points into the xpti Profile API.
5 //
6 // v1 design (see tools/xprofiler/docs/design/profiling-api-redesign-plan.md):
7 //
8 // pxl::enableProfiling(cfg); // starts the current v1 default device session
9 // pxl::disableProfiling();
10 // pxl::isProfilingEnabled();
11 // pxl::Profile = xpti::Profile; // alias for Profile::open(path)
12 // pxl::ScopedProfile p(cfg); // RAII helper
13 //
14 // Live in-process attach (pxl::profile() / Map::profile() / Job::profile()) is NOT part
15 // of v1: it requires the xpti live-session manager, deferred to a Phase 3 follow-up (see
16 // design doc). v1 provides collection (enableProfiling / ScopedProfile / XPTI_ENABLE) plus
17 // offline analysis via Profile::open(path). The current facade delegates to xpti for
18 // session state and keeps ownership only so ScopedProfile does not stop sessions it did
19 // not start.
20 
21 #pragma once
22 
23 #include "xpti/profile.hpp"
24 
25 // Forward decl for xpti::ProfileConfig — already provided by xpti.hpp / xpti_types.hpp.
26 namespace xpti
27 {
28 struct ProfileConfig;
29 }
30 
31 namespace pxl
32 {
33 
34 // Type alias so users can write pxl::Profile::open(path).
36 
37 // Session control -----------------------------------------------------------------
38 // enableProfiling returns true iff this call actually started a session; false if a
39 // session was already active (the caller's cfg is not re-applied in that case).
40 bool enableProfiling(const xpti::ProfileConfig& cfg);
43 
44 // RAII helper. Idempotent w.r.t. already-enabled sessions: if profiling is already
45 // on when the ctor runs, the dtor does NOT disable.
47 {
48 public:
49  explicit ScopedProfile(const xpti::ProfileConfig& cfg);
51 
52  ScopedProfile(const ScopedProfile&) = delete;
56 
57 private:
58  bool enabledByMe_;
59 };
60 
61 namespace detail
62 {
63 // Returns true iff this call actually enabled profiling. Internal — users must
64 // not call this directly; it exists for callers that need to serialize the
65 // check-then-act race.
66 bool tryEnableProfiling(const xpti::ProfileConfig& cfg);
67 } // namespace detail
68 
69 } // namespace pxl
ScopedProfile(const xpti::ProfileConfig &cfg)
ScopedProfile(const ScopedProfile &)=delete
ScopedProfile(ScopedProfile &&)=delete
ScopedProfile & operator=(const ScopedProfile &)=delete
ScopedProfile & operator=(ScopedProfile &&)=delete
bool tryEnableProfiling(const xpti::ProfileConfig &cfg)
Definition: config.hpp:11
bool enableProfiling(const xpti::ProfileConfig &cfg)
void disableProfiling()
xpti::Profile Profile
Definition: profile.hpp:35
bool isProfilingEnabled()
Definition: map.hpp:17