diff --git a/README.md b/README.md index 6ea30f3..c42da1a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,24 @@ OPTIONS: -h, --help Display available options ``` -### Build +### Nix Build + +With [`nix`](https://nixos.org/download/) installed you can run the binary directly from the github repo without cloning it +or installing any other system dependencies manually. +Build both packages using +```sh +nix build github:SoilRos/cpu-latency +``` +And the binaries can be found in `results/bin`. + +Or run the apps directly: +```sh +nix run github:SoilRos/cpu-latency#default > cpu-latency.csv +nix run github:SoilRos/cpu-latency#cpu-latency-plot -- -i cpu-latency.csv -o cpu-latency.png +``` +Thats it. The package definition can be found in `flake.nix` + +### Manual Build This program requires the `hwloc` API in order to bind threads and memory. Make sure to have it available on your system, for example: diff --git a/cpu-latency.csv b/cpu-latency.csv new file mode 100644 index 0000000..82b988e --- /dev/null +++ b/cpu-latency.csv @@ -0,0 +1,16 @@ +,,,,,,,,,,,,,,, +8.19047,,,,,,,,,,,,,,, +38.7161,43.3911,,,,,,,,,,,,,, +42.7849,41.2916,8.3785,,,,,,,,,,,,, +40.6754,40.5147,37.9108,39.2531,,,,,,,,,,,, +41.4751,34.3101,40.011,42.3767,10.2224,,,,,,,,,,, +39.167,42.7887,39.6729,40.9829,36.5744,43.2831,,,,,,,,,, +41.0165,40.2607,30.5628,39.7397,31.0674,35.1345,8.02883,,,,,,,,, +41.3245,36.9565,38.4529,37.2639,37.4976,38.8147,38.1139,37.7121,,,,,,,, +40.7089,33.8335,34.8358,35.9822,33.7611,33.0055,37.9209,38.3884,8.08093,,,,,,, +34.9224,40.167,38.8864,37.7187,38.1265,37.6803,37.4194,39.1452,33.8773,39.4251,,,,,, +38.1568,40.4715,39.2691,39.5195,38.0925,38.9488,32.5569,36.6864,39.3567,33.3397,8.19833,,,,, +39.4106,41.1751,35.8036,32.4971,38.3238,39.4311,31.8397,40.3429,32.8858,33.4102,37.5421,31.9478,,,, +39.5997,35.4925,42.9214,39.8932,33.9812,33.2923,36.7748,33.3397,36.9161,38.1162,38.2239,41.5213,7.5154,,, +36.4321,36.5922,40.6733,40.1444,41.5501,32.7673,34.4882,40.2444,31.9862,41.305,38.3385,40.4523,38.9662,41.9738,, +40.9362,35.827,40.7108,41.4788,37.766,33.6702,42.2824,38.1555,37.9444,33.301,40.524,33.7182,41.7284,42.1193,7.84817, diff --git a/cpu-latency.png b/cpu-latency.png new file mode 100644 index 0000000..f75fd73 Binary files /dev/null and b/cpu-latency.png differ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6769406 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1781074563, + "narHash": "sha256-md8WlXOlfnIeHeOScMTTHFyf2d6iaTwPl2apR5EQ3P4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9ae611a455b90cf061d8f332b977e387bda8e1ca", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9625317 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + description = "Measure the CPU latency between cores"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = f: + nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); + in + { + packages = forAllSystems (pkgs: { + default = pkgs.stdenv.mkDerivation { + pname = "cpu-latency"; + version = "0.1.0"; + src = ./.; + + nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config ]; + buildInputs = [ pkgs.hwloc ]; + + installPhase = '' + runHook preInstall + install -Dm755 cpu-latency $out/bin/cpu-latency + install -Dm755 ../cpu-latency-plot $out/bin/cpu-latency-plot + runHook postInstall + ''; + }; + }); + + apps = forAllSystems (pkgs: + let + system = pkgs.stdenv.hostPlatform.system; + pythonEnv = pkgs.python3.withPackages (ps: [ ps.matplotlib ps.numpy ]); + cpu-latency-plot = pkgs.writeShellScriptBin "cpu-latency-plot" '' + exec ${pythonEnv}/bin/python3 ${self.packages.${system}.default}/bin/cpu-latency-plot "$@" + ''; + in + { + default = self.apps.${system}.cpu-latency; + cpu-latency = { + type = "app"; + program = "${self.packages.${system}.default}/bin/cpu-latency"; + }; + cpu-latency-plot = { + type = "app"; + program = "${cpu-latency-plot}/bin/cpu-latency-plot"; + }; + }); + }; +}