Skip to content

Commit

Permalink
Merge pull request #6 from janjurca/feature/rapid-aging
Browse files Browse the repository at this point in the history
Feature/rapid aging
  • Loading branch information
janjurca authored Feb 20, 2025
2 parents 2e4cf95 + 38b8b04 commit 9629652
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 115 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/fedora.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
name: Fedora

on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

on: [ push , pull_request ]

env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules

Expand All @@ -20,7 +12,7 @@ jobs:
steps:
- name: install_dependencies
run: |
dnf install -y cmake gcc-c++ make spdlog-devel git cxxopts-devel json-devel
dnf install -y cmake gcc-c++ make spdlog-devel git cxxopts-devel json-devel eigen3-devel
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -52,7 +44,7 @@ jobs:
steps:
- name: install_dependencies
run: |
dnf install -y cmake gcc-c++ make spdlog-devel git cxxopts-devel json-devel
dnf install -y cmake gcc-c++ make spdlog-devel git cxxopts-devel json-devel eigen3-devel
- uses: actions/checkout@v4
with:
Expand All @@ -71,7 +63,6 @@ jobs:
- name: configure
run: make tests


trigger-copr-build:
needs: [build, tests]
runs-on: ubuntu-latest
Expand Down
56 changes: 0 additions & 56 deletions .github/workflows/install.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Install dependencies
run: brew install spdlog fmt cxxopts nlohmann-json
run: brew install spdlog fmt cxxopts nlohmann-json eigen

- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: install_dependencies
run: |
sudo apt update
sudo apt install -y cmake g++ make libspdlog-dev libfmt-dev git libcxxopts-dev nlohmann-json3-dev
sudo apt install -y cmake g++ make libspdlog-dev libfmt-dev git libcxxopts-dev nlohmann-json3-dev libeigen3-dev
- uses: actions/checkout@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/cpm_modules
.DS_Store
.version
_CPack_Packages
_CPack_Packages
results.json*
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ if(USE_CPM)
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.14.1
)
CPMAddPackage(
NAME Eigen3
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen"
GIT_TAG "3.3.3" TRUE
)
else()
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(Eigen3 REQUIRED)
endif()

# ---- Add source files ----
Expand All @@ -66,11 +72,11 @@ target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>
# Link dependencies
if(USE_CPM)
target_link_libraries(
${PROJECT_NAME} PRIVATE fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json
${PROJECT_NAME} PRIVATE fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json Eigen3::Eigen
)
else()
target_link_libraries(
${PROJECT_NAME} PRIVATE fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json
${PROJECT_NAME} PRIVATE fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json Eigen3::Eigen
)
endif()

Expand All @@ -95,7 +101,7 @@ packageProject(
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "spdlog;fmt" CPACK YES
DEPENDENCIES "spdlog;fmt;eigen3" CPACK YES
)

file(GLOB standalone_sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/standalone/source/*.cpp)
Expand All @@ -106,10 +112,12 @@ set_target_properties(${PROJECT_NAME}Executable PROPERTIES CXX_STANDARD 17 OUTPU
if(USE_CPM)
target_link_libraries(
${PROJECT_NAME}Executable ${PROJECT_NAME} fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json
Eigen3::Eigen
)
else()
target_link_libraries(
${PROJECT_NAME}Executable ${PROJECT_NAME} fmt::fmt spdlog::spdlog nlohmann_json::nlohmann_json
Eigen3::Eigen
)
endif()

Expand All @@ -133,8 +141,10 @@ install(TARGETS ${PROJECT_NAME}Executable RUNTIME DESTINATION ${CMAKE_INSTALL_BI
if(USE_CPM)
set(CPACK_RPM_BUILDREQUIRES "cmake, gcc-c++, git")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "spdlog, fmt, json-devel")
set(CPACK_RPM_BUILDREQUIRES "cmake, gcc-c++, spdlog-devel, fmt-devel, git, json-devel")
set(CPACK_RPM_PACKAGE_REQUIRES "spdlog, fmt, json-devel, eigen3")
set(CPACK_RPM_BUILDREQUIRES
"cmake, gcc-c++, spdlog-devel, fmt-devel, git, json-devel, eigen3-devel"
)
endif()
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/usr")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Actions Status](https://github.com/janjurca/filestorm/workflows/MacOS/badge.svg)](https://github.com/janjurca/filestorm/actions)
[![Actions Status](https://github.com/janjurca/filestorm/workflows/Fedora/badge.svg)](https://github.com/janjurca/filestorm/actions)
[![Actions Status](https://github.com/janjurca/filestorm/workflows/Ubuntu/badge.svg)](https://github.com/janjurca/filestorm/actions)
[![codecov](https://codecov.io/gh/janjurca/filestorm/branch/master/graph/badge.svg)](https://codecov.io/gh/janjurca/filestorm)
[![Actions Status](https://github.com/janjurca/filestorm/workflows/MacOS/badge.svg?branch=master)](https://github.com/janjurca/filestorm/actions)
[![Actions Status](https://github.com/janjurca/filestorm/workflows/Fedora/badge.svg?branch=master)](https://github.com/janjurca/filestorm/actions)
[![Actions Status](https://github.com/janjurca/filestorm/workflows/Ubuntu/badge.svg?branch=master)](https://github.com/janjurca/filestorm/actions)
[![codecov](https://codecov.io/gh/janjurca/filestorm/branch/master/graph/badge.svg?branch=master)](https://codecov.io/gh/janjurca/filestorm)
[![rpmbuild](https://copr.fedorainfracloud.org/coprs/jjurca/filestorm/package/filestorm/status_image/last_build.png)](https://copr.fedorainfracloud.org/coprs/jjurca/filestorm/)
<!---
[![Actions Status](https://github.com/janjurca/filestorm/workflows/Install/badge.svg)](https://github.com/janjurca/filestorm/actions)
Expand Down
10 changes: 6 additions & 4 deletions include/filestorm/filetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FileTree {

int getFallocationCount() { return fallocated_count; }

int getExtentsCount(bool update = true) {
std::vector<extents> getExtents(bool update = true) {
if (update) {
if (type == Type::FILE) {
_extents.clear();
Expand All @@ -63,12 +63,14 @@ class FileTree {
_extents.clear();
}
}
return _extents.size();
return _extents;
}

int getExtentsCount(bool update = true) { return getExtents(update).size(); }

std::uintmax_t size() { return fs_utils::file_size(path(true)); }

std::tuple<size_t, size_t> getHoleAdress(size_t blocksize, bool increment) {
std::tuple<size_t, size_t> getHoleAddress(size_t blocksize, bool increment) {
size_t start = 0, end = size() / 2;
for (int i = 0; i < fallocated_count; i++) {
size_t length = end - start;
Expand All @@ -90,7 +92,7 @@ class FileTree {

bool isPunchable(size_t blocksize) {
try {
getHoleAdress(blocksize, false);
getHoleAddress(blocksize, false);
return true;
} catch (const std::exception& e) {
return false;
Expand Down
84 changes: 84 additions & 0 deletions include/filestorm/polycurve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef POLYCURVE_H
#define POLYCURVE_H

#include <Eigen/Dense>
#include <cmath>
#include <iostream>
#include <numeric> // for std::reduce (C++17) or std::accumulate
#include <stdexcept>
#include <vector>

class PolyCurve {
public:
// Constructor: specify the polynomial degree.
// The second parameter is the subsampling count (default 1 means no subsampling).
explicit PolyCurve(int degree, int subsampling = 1);

// Add a data point (x, y). When subsampling > 1 the point is buffered and only every
// "subsampling"-th point (averaged over the last 'subsampling' calls) is added.
void addPoint(float y);

// Remove the oldest data point (from the front).
void popOldestPoint();

// Remove the specified number of oldest data points.
// If count is greater than the number of points, all points will be removed.
void popOldestPoints(size_t count);

// Clear all data points.
void clearPoints();

// Fit the polynomial to the current data points using least squares.
// Throws an exception if there are not enough points.
void fitPolyCurve();

// Evaluate the fitted polynomial at a given x.
float evaluate(float x);

// Evaluate the first derivative f'(x) at a given x.
float derivative(float x);

// Compute and return the tangent angle (in degrees) relative to the y-axis at a given x.
float getTangentAngle(float x);

// Return the polynomial coefficients (ensures the curve is fitted).
const Eigen::VectorXd& getCoefficients() const;

// Print all stored data points.
void printPoints() const;

// Return the number of data points currently stored.
size_t getPointCount() const;

float slope() const;

float slopeAngle() const;

bool isFitted() const { return fitted; };

private:
// Main data storage for points that will be used for fitting.
std::vector<float> y_points;

// Subsampling buffers.
// (Since we want to average both x and y values, we buffer x too.)
std::vector<float> y_subsample_buffer;

int poly_degree; // Degree of the polynomial to be fitted.
Eigen::VectorXd coeffs; // Polynomial coefficients (from constant term to highest degree).
bool fitted; // Flag indicating whether the current coefficients are up-to-date.
int subsampling; // How many points to average before adding a new point.

float maximum_value = 0;
// Helper function to compute the average of the values in a vector.
float average(std::vector<float> const& v) {
if (v.empty()) {
return 0;
}
auto const count = static_cast<float>(v.size());
// Using std::reduce (available in C++17); you could also use std::accumulate.
return std::reduce(v.begin(), v.end()) / count;
}
};

#endif // POLYCURVE_H
8 changes: 6 additions & 2 deletions include/filestorm/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class Result {
public:
enum Action { DELETE_FILE, CREATE_FILE, CREATE_FILE_OVERWRITE, CREATE_FILE_READ, CREATE_DIR, ALTER_SMALLER_TRUNCATE, ALTER_SMALLER_FALLOCATE, ALTER_BIGGER, NONE };
enum Operation { WRITE, TRIM, OVERWRITE, READ };
enum Action { DELETE_FILE, CREATE_FILE, CREATE_FILE_FALLOCATE, CREATE_FILE_OVERWRITE, CREATE_FILE_READ, CREATE_DIR, ALTER_SMALLER_TRUNCATE, ALTER_SMALLER_FALLOCATE, ALTER_BIGGER, NONE };
enum Operation { WRITE, TRIM, OVERWRITE, READ, FALLOCATE };
static std::vector<Result> results;

private:
Expand Down Expand Up @@ -58,6 +58,8 @@ class Result {
return "DELETE_FILE";
case CREATE_FILE:
return "CREATE_FILE";
case CREATE_FILE_FALLOCATE:
return "CREATE_FILE_FALLOCATE";
case CREATE_DIR:
return "CREATE_DIR";
case CREATE_FILE_OVERWRITE:
Expand Down Expand Up @@ -87,6 +89,8 @@ class Result {
return "OVERWRITE";
case READ:
return "READ";
case FALLOCATE:
return "FALLOCATE";
default:
logger.debug("Unknown Operation id {}", (int)operation);
return "Unknown Operation";
Expand Down
Loading

0 comments on commit 9629652

Please sign in to comment.