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 <pxl/v3_api_guard.hpp>
24 
25 #include "xpti/profile.hpp"
26 #include "xpti/xpti_types.hpp"
27 
28 namespace pxl
29 {
30 
31 // Type alias so users can write pxl::Profile::open(path).
33 
34 // Session control -----------------------------------------------------------------
35 // enableProfiling returns true iff this call actually started a session; false if a
36 // session was already active (the caller's cfg is not re-applied in that case).
37 // In coordinator mode the first device capture admits this process as the
38 // tenant's workload: up to about 20 s (registration and activation each wait
39 // up to 10 s), during which other profiling calls wait too. False if it failed.
40 // The device capture runs on device 0, or in coordinator mode on the lowest
41 // device the workload was admitted to.
42 bool enableProfiling(const xpti::ProfileConfig& cfg);
45 
46 // RAII helper. Idempotent w.r.t. already-enabled sessions: if profiling is already
47 // on when the ctor runs, the dtor does NOT disable.
49 {
50 public:
51  explicit ScopedProfile(const xpti::ProfileConfig& cfg);
53 
54  ScopedProfile(const ScopedProfile&) = delete;
58 
59 private:
60  bool enabledByMe_;
61 };
62 
63 namespace detail
64 {
65 // Returns true iff this call actually enabled profiling. Internal — users must
66 // not call this directly; it exists for callers that need to serialize the
67 // check-then-act race.
68 bool tryEnableProfiling(const xpti::ProfileConfig& cfg);
69 } // namespace detail
70 
71 } // 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:13
bool enableProfiling(const xpti::ProfileConfig &cfg)
void disableProfiling()
xpti::Profile Profile
Definition: profile.hpp:32
bool isProfilingEnabled()