|
3 | 3 | * SPDX-License-Identifier: MIT |
4 | 4 | */ |
5 | 5 |
|
6 | | -#include "stats.h" |
| 6 | +#include "include_internal/hipfile-stats.h" |
7 | 7 | #include <iostream> |
8 | 8 | #include <unistd.h> |
9 | 9 | #include <cstring> |
@@ -47,17 +47,37 @@ main(int argc, char *argv[]) |
47 | 47 | return 1; |
48 | 48 | } |
49 | 49 | } |
50 | | - hipFile::StatsClient client{pid}; |
51 | | - if (!client.connectServer()) { |
52 | | - std::cerr << "Failed to collect info from target process.\n"; |
| 50 | + |
| 51 | + hipFileStatsContext_t *context; |
| 52 | + if (hipFileStatsCreateContext(&context, pid) != hipFileStatsSuccess) { |
| 53 | + std::cerr << "Failed to create context for target process.\n"; |
| 54 | + return 1; |
| 55 | + } |
| 56 | + if (hipFileStatsConnectToTargetProcess(context) != hipFileStatsSuccess) { |
| 57 | + std::cerr << "Failed to connect to target process.\n"; |
| 58 | + hipFileStatsCloseContext(context); |
53 | 59 | return 1; |
54 | 60 | } |
55 | 61 | if (!imm) { |
56 | | - client.pollProcess(-1); |
| 62 | + if (hipFileStatsPollTargetProcess(context, -1) != hipFileStatsSuccess) { |
| 63 | + std::cerr << "Failed to poll target process.\n"; |
| 64 | + hipFileStatsCloseContext(context); |
| 65 | + return 1; |
| 66 | + } |
| 67 | + } |
| 68 | + int fd{dup(STDOUT_FILENO)}; |
| 69 | + if (fd < 0) { |
| 70 | + std::cerr << "Failed to duplicate stdout file descriptor.\n"; |
| 71 | + hipFileStatsCloseContext(context); |
| 72 | + return 1; |
57 | 73 | } |
58 | | - if (!client.generateReport(std::cout)) { |
59 | | - std::cerr << "No stats could be collected from target process.\n"; |
| 74 | + if (hipFileStatsGenerateReport(context, fd) != hipFileStatsSuccess) { |
| 75 | + std::cerr << "Failed to generate report from target process.\n"; |
| 76 | + close(fd); |
| 77 | + hipFileStatsCloseContext(context); |
60 | 78 | return 1; |
61 | 79 | } |
| 80 | + close(fd); |
| 81 | + hipFileStatsCloseContext(context); |
62 | 82 | return 0; |
63 | 83 | } |
0 commit comments