Conversation
32d6697 to
79e93b7
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a small public C API wrapper around the existing hipFile::StatsClient (to enable non-C++ consumers) and migrates the ais-stats tool to use that wrapper.
Changes:
- Added a new exported C header/API (
include/hipfile-stats.h) and its implementation wrapper (src/amd_detail/hipfile-stats.cpp) aroundhipFile::StatsClient. - Updated
tools/ais-statsto use the new C API instead of directly instantiatingStatsClient. - Made
StatsClient::pollProcess()andStatsClient::generateReport()constto support use via aconstcontext pointer.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/ais-stats/ais-stats.cpp | Switches the CLI tool to the new C API context/connect/poll/report flow. |
| src/amd_detail/stats.h | Marks StatsClient polling/report methods as const for wrapper usage. |
| src/amd_detail/stats.cpp | Implements the const-qualified StatsClient methods. |
| src/amd_detail/hipfile-stats.cpp | New C API wrapper implementation around StatsClient. |
| src/amd_detail/CMakeLists.txt | Adds the new wrapper source file to the AMD detail library build. |
| include/hipfile-stats.h | New public C header exposing the stats API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/amd_detail/hipfile-stats.cpp
Outdated
| std::string report = stream.str(); | ||
| if (write(fd, report.c_str(), report.size()) == -1) { | ||
| return HipFileStatsReportGenerationFailed; | ||
| } |
There was a problem hiding this comment.
generateReport() writes the report with a single write() call and treats any non--1 return as success. write() can legally return a short byte count (and can be interrupted with EINTR), which would truncate the report while still returning HipFileStatsSuccess. Consider looping until all bytes are written (handling EINTR) and treating short writes as failure.
c5b6eb2 to
c6c72e2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| size_t written{0}; | ||
| while (written < total_size) { | ||
| ssize_t n{write(fd, data + written, total_size - written)}; | ||
| if (n < 0) { | ||
| return hipFileStatsReportGenerationFailed; | ||
| } | ||
| written += static_cast<size_t>(n); | ||
| } |
There was a problem hiding this comment.
The write loop treats any write() error as fatal, but does not handle EINTR (should retry) and can spin forever if write() ever returns 0. Update the loop to retry on EINTR and treat n == 0 as an error to avoid an infinite loop.
c6c72e2 to
ccbb060
Compare
ccbb060 to
00c742b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return hipFileStatsInvalidArgument; | ||
| } | ||
| const IStatsClient *client{reinterpret_cast<const IStatsClient *>(context)}; | ||
| if (!client->pollProcess(timeoutMs)) { |
There was a problem hiding this comment.
hipFileStatsPollTargetProcess treats a false return from IStatsClient::pollProcess as hipFileStatsTargetProcessNotAccessible. StatsClient::pollProcess returns false on a normal timeout (poll() == 0) as well as on poll() errors, so callers using a finite timeout will get an error code for an expected timeout condition. Consider adding a distinct timeout error code (and optionally distinguishing poll() errors) or updating the API contract so the return code reflects timeout vs. failure.
| if (!client->pollProcess(timeoutMs)) { | |
| if (!client->pollProcess(timeoutMs)) { | |
| // For finite timeouts, a false return can indicate a normal timeout. | |
| // Distinguish this from an actual accessibility failure. | |
| if (timeoutMs >= 0) { | |
| return hipFileStatsTimeout; | |
| } |
00c742b to
400fe1f
Compare
Creates a C API that wraps StatsClient and updates ais-stats to use the new API