Skip to content

Commit

Permalink
Cleanup Linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
hassila committed Apr 22, 2024
1 parent 1737e75 commit 5c2b63e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
12 changes: 4 additions & 8 deletions Platform/CLinuxOperatingSystemStats/CLinuxOperatingSystemStats.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ int CLinuxPerformanceCountersInit() {
errorCode = errno;
if (fd == -1) {
fprintf(stderr, "Error in perf_event_open syscall, failed with [%d], error: %s\n", errorCode, strerror(errorCode));
} else {
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
}

return fd;
Expand All @@ -44,15 +47,8 @@ void CLinuxPerformanceCountersDeinit(int fd) {
close(fd);
}

void CLinuxPerformanceCountersStart(int fd) {
// ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
// ioctl(fd, PERF_EVENT_IOC_RESET, 0);
}

void CLinuxPerformanceCountersStop(int fd, struct performanceCounters *performanceCounters) {
// ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
void CLinuxPerformanceCountersCurrent(int fd, struct performanceCounters *performanceCounters) {
read(fd, &performanceCounters->instructions, sizeof(performanceCounters->instructions));
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct performanceCounters {

int CLinuxPerformanceCountersInit(); // returns the perf events fd that must be passed to the reset of the functions
void CLinuxPerformanceCountersDeinit(int fd); // stop monitoring and close the fd
void CLinuxPerformanceCountersStart(int fd); // reset counters and start measuring
void CLinuxPerformanceCountersStop(int fd, struct performanceCounters *performanceCounters); // stop measuring and return counters
void CLinuxPerformanceCountersCurrent(int fd, struct performanceCounters *performanceCounters); // return current counters

#endif /* CLinuxOperatingSystemStats_h */
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@
func stopPerformanceCounters() {
}

func resetPerformanceCounters() {
}

func makePerformanceCounters() -> PerformanceCounters {
performanceCounters = getRusage()
return .init(instructions: Int(performanceCounters.ri_instructions))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,12 @@
}
}

func resetPerformanceCounters() { // NOP
}

func makePerformanceCounters() -> PerformanceCounters {
if performanceEventsFD > 0 {
CLinuxPerformanceCountersStop(performanceEventsFD, &performanceCounters)
CLinuxPerformanceCountersCurrent(performanceEventsFD, &performanceCounters)

Check warning on line 244 in Sources/Benchmark/OperatingSystemStats/OperatingSystemStatsProducer+Linux.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Benchmark/OperatingSystemStats/OperatingSystemStatsProducer+Linux.swift#L244

Added line #L244 was not covered by tests
}

.init(instructions: Int(performanceCounters.ri_instructions))
return .init(instructions: Int(performanceCounters.instructions))
}


// func resetSystemPerformanceCounters() {
// self.performanceCounters = .init()
// self.lock.withLock {
// if performanceEventsFD > 0 {
// // CLinuxPerformanceCountersStart(performanceEventsFD)
// }
// }
// }
//
// func recordPerformanceCounters() {
// self.lock.withLock {
// if performanceEventsFD > 0 {
// CLinuxPerformanceCountersStop(performanceEventsFD, &performanceCounters)
// }
// }
// }
}
#endif

0 comments on commit 5c2b63e

Please sign in to comment.