Skip to content

Commit 400fe1f

Browse files
committed
Update ais-stats to use new API.
1 parent b989df8 commit 400fe1f

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

tools/ais-stats/ais-stats.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: MIT
44
*/
55

6-
#include "stats.h"
6+
#include "include_internal/hipfile-stats.h"
77
#include <iostream>
88
#include <unistd.h>
99
#include <cstring>
@@ -47,17 +47,37 @@ main(int argc, char *argv[])
4747
return 1;
4848
}
4949
}
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);
5359
return 1;
5460
}
5561
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;
5773
}
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);
6078
return 1;
6179
}
80+
close(fd);
81+
hipFileStatsCloseContext(context);
6282
return 0;
6383
}

0 commit comments

Comments
 (0)