-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add process self-inspection primitives to src/lang/process
#2767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME process | ||
| PRIVATE_HEADERS error.h | ||
| SOURCES spawn.cc command_line.h) | ||
| PRIVATE_HEADERS error.h usage.h | ||
| SOURCES spawn.cc usage.cc command_line.h) | ||
|
|
||
| if(SOURCEMETA_CORE_INSTALL) | ||
| sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME process) | ||
| endif() | ||
|
|
||
| target_link_libraries(sourcemeta_core_process PRIVATE sourcemeta::core::text) | ||
| target_link_libraries(sourcemeta_core_process PRIVATE sourcemeta::core::numeric) | ||
|
|
||
| # Matching the condition the sources compile the Windows implementation under, | ||
| # so that a MinGW build does not link what it never calls | ||
| if(WIN32 AND NOT MINGW) | ||
| target_link_libraries(sourcemeta_core_process PRIVATE psapi) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||
| #ifndef SOURCEMETA_CORE_PROCESS_USAGE_H_ | ||||||
| #define SOURCEMETA_CORE_PROCESS_USAGE_H_ | ||||||
|
|
||||||
| #ifndef SOURCEMETA_CORE_PROCESS_EXPORT | ||||||
| #include <sourcemeta/core/process_export.h> | ||||||
| #endif | ||||||
|
|
||||||
| #include <chrono> // std::chrono::nanoseconds, std::chrono::system_clock | ||||||
| #include <cstdint> // std::uint64_t | ||||||
| #include <optional> // std::optional | ||||||
|
|
||||||
| namespace sourcemeta::core { | ||||||
|
|
||||||
| /// @ingroup process | ||||||
| /// What the running process has consumed so far. | ||||||
| /// | ||||||
| /// Every member carries no value where the platform cannot cheaply answer, so | ||||||
| /// that a caller reports nothing rather than a zero it cannot tell apart from | ||||||
| /// a measurement. | ||||||
| struct ProcessUsage { | ||||||
| /// Combined user and system processor time | ||||||
| std::optional<std::chrono::nanoseconds> cpu_time{std::nullopt}; | ||||||
| /// Physical memory currently held, in bytes | ||||||
| std::optional<std::uint64_t> resident_bytes{std::nullopt}; | ||||||
| /// Address space currently mapped, in bytes | ||||||
| std::optional<std::uint64_t> virtual_bytes{std::nullopt}; | ||||||
| }; | ||||||
|
|
||||||
| /// @ingroup process | ||||||
| /// What the running process currently holds open, and how much it may. | ||||||
| /// | ||||||
| /// Every member carries no value where the platform cannot cheaply answer, so | ||||||
| /// that a caller reports nothing rather than a zero it cannot tell apart from | ||||||
| /// a measurement. | ||||||
| struct ProcessDescriptors { | ||||||
| /// Open file descriptors, or open handles on platforms that count those | ||||||
| std::optional<std::uint64_t> open{std::nullopt}; | ||||||
| /// The ceiling the platform enforces, where there is one and it is finite | ||||||
| std::optional<std::uint64_t> maximum{std::nullopt}; | ||||||
| }; | ||||||
|
|
||||||
| /// @ingroup process | ||||||
| /// | ||||||
| /// Read what the running process has consumed so far. For example: | ||||||
| /// | ||||||
| /// ```cpp | ||||||
| /// #include <sourcemeta/core/process.h> | ||||||
| /// #include <chrono> | ||||||
| /// #include <cassert> | ||||||
| /// | ||||||
| /// const auto usage{sourcemeta::core::process_usage()}; | ||||||
| /// assert(usage.cpu_time.value() >= std::chrono::nanoseconds::zero()); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The example calls Prompt for AI agents
Suggested change
|
||||||
| /// ``` | ||||||
| SOURCEMETA_CORE_PROCESS_EXPORT | ||||||
| auto process_usage() noexcept -> ProcessUsage; | ||||||
|
|
||||||
| /// @ingroup process | ||||||
| /// | ||||||
| /// Read what the running process currently holds open. This costs a directory | ||||||
| /// scan on some platforms. For example: | ||||||
| /// | ||||||
| /// ```cpp | ||||||
| /// #include <sourcemeta/core/process.h> | ||||||
| /// #include <cassert> | ||||||
| /// | ||||||
| /// const auto descriptors{sourcemeta::core::process_descriptors()}; | ||||||
| /// assert(descriptors.open.value() > 0); | ||||||
| /// ``` | ||||||
| SOURCEMETA_CORE_PROCESS_EXPORT | ||||||
| auto process_descriptors() noexcept -> ProcessDescriptors; | ||||||
|
|
||||||
| /// @ingroup process | ||||||
| /// | ||||||
| /// Read when the running process began. The answer does not change. For | ||||||
| /// example: | ||||||
| /// | ||||||
| /// ```cpp | ||||||
| /// #include <sourcemeta/core/process.h> | ||||||
| /// #include <chrono> | ||||||
| /// #include <cassert> | ||||||
| /// | ||||||
| /// const auto started{sourcemeta::core::process_start_time()}; | ||||||
| /// assert(started.value() <= std::chrono::system_clock::now()); | ||||||
| /// ``` | ||||||
| SOURCEMETA_CORE_PROCESS_EXPORT | ||||||
| auto process_start_time() noexcept | ||||||
| -> std::optional<std::chrono::system_clock::time_point>; | ||||||
|
|
||||||
| } // namespace sourcemeta::core | ||||||
|
|
||||||
| #endif | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: When
SOURCEMETA_CORE_LANG_NUMERIC=OFF, the process target still references the nonexistentsourcemeta::core::numerictarget. Make the dependency/platform selection consistent, or require and validate numeric as a process prerequisite before adding this link.Prompt for AI agents