Skip to content

Commit

Permalink
added optional performance monitoring, create html folder if doesn't …
Browse files Browse the repository at this point in the history
…exist
  • Loading branch information
sirus20x6 committed Oct 27, 2024
1 parent 7cdebf3 commit 8e775d1
Show file tree
Hide file tree
Showing 6 changed files with 1,795 additions and 1,665 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ add_executable(stargen
star_trek.cpp
structs.cpp
utils.cpp
PerformanceMonitor.cpp
_deps/tracy-src/public/TracyClient.cpp
)

Expand Down
32 changes: 32 additions & 0 deletions PerformanceMonitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "PerformanceMonitor.h"
#include <iostream>

// Global instance definition
PerformanceMonitor performanceMonitor;

void PerformanceMonitor::setEnabled(bool enable) {
enabled = enable;
if (enable) {
lastFileTime = Clock::now();
}
}

void PerformanceMonitor::recordFileOperation(const std::string& fileName) {
if (!enabled) return;

auto currentTime = Clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
currentTime - lastFileTime);

if (!lastFileName.empty()) {
std::cout << "Time between " << lastFileName << " and " << fileName
<< ": " << duration.count() << "ms\n";
}

lastFileName = fileName;
lastFileTime = currentTime;
}

bool PerformanceMonitor::isEnabled() const {
return enabled;
}
22 changes: 22 additions & 0 deletions PerformanceMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <chrono>
#include <string>

class PerformanceMonitor {
private:
using Clock = std::chrono::high_resolution_clock;
using TimePoint = std::chrono::time_point<Clock>;

bool enabled = false;
TimePoint lastFileTime;
std::string lastFileName;

public:
void setEnabled(bool enable);
void recordFileOperation(const std::string& fileName);
bool isEnabled() const;
};

// Global instance declaration
extern PerformanceMonitor performanceMonitor;
Loading

0 comments on commit 8e775d1

Please sign in to comment.