From 5d4687bcc44785289aa92799adc7745558020f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Nicklisch-Franken?= Date: Tue, 16 Jun 2026 16:35:45 +0200 Subject: [PATCH 1/2] Deleted trace-resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cabal.project: removed trace-resources local package, added source-repository-package pointing to hermod-tracing@f94edf21 flake.nix: added hermod-tracing flake input (branch without_contra_included) nix/haskell.nix: added hermod-tracing to function args and inputMap, renamed "trace-resources" → "hermod-trace-resources" in profiled builds 4 dependent cabal files: trace-resources → hermod-trace-resources 12 Haskell source files: all Cardano.Logging.Resources imports → Hermod.Tracing.Resources stylish-haskell.yml: removed trace-resources entry GhciSchemaGen.hs: updated path to ../hermod-tracing/hermod-trace-resources/src --- .github/workflows/stylish-haskell.yml | 1 - .../app/Cardano/Timeseries/Common.hs | 2 +- .../cardano-timeseries-io.cabal | 4 +- bench/locli/locli.cabal | 4 +- .../locli/src/Cardano/Analysis/API/Metrics.hs | 2 +- bench/locli/src/Cardano/Analysis/API/Types.hs | 2 +- bench/locli/src/Cardano/Unlog/LogObject.hs | 2 +- bench/locli/src/Cardano/Unlog/LogObjectDB.hs | 2 +- bench/locli/src/Cardano/Unlog/Resources.hs | 2 +- .../scripts/schema-gen/GhciSchemaGen.hs | 2 +- cabal.project | 10 +- cardano-node/cardano-node.cabal | 2 +- cardano-node/src/Cardano/Node/Tracing.hs | 2 +- .../src/Cardano/Node/Tracing/Consistency.hs | 4 +- .../src/Cardano/Node/Tracing/Documentation.hs | 4 +- .../Cardano/Node/Tracing/Tracers/Resources.hs | 2 +- cardano-tracer/cardano-tracer.cabal | 2 +- .../src/Cardano/Tracer/MetaTrace.hs | 2 +- cardano-tracer/src/Cardano/Tracer/Run.hs | 2 +- flake.nix | 7 +- nix/haskell.nix | 6 +- trace-resources/.gitignore | 11 - trace-resources/CHANGELOG.md | 26 -- trace-resources/LICENSE | 177 ----------- trace-resources/NOTICE | 13 - trace-resources/README.md | 3 - .../bench/trace-resources-bench.hs | 22 -- trace-resources/cbits/os-support-darwin.c | 289 ------------------ trace-resources/cbits/os-support-win.c | 96 ------ trace-resources/include/os-support-darwin.h | 38 --- trace-resources/include/os-support-win.h | 14 - .../src/Cardano/Logging/Resources.hs | 23 -- .../src/Cardano/Logging/Resources/Darwin.hsc | 114 ------- .../src/Cardano/Logging/Resources/Dummy.hs | 39 --- .../src/Cardano/Logging/Resources/Linux.hs | 153 ---------- .../src/Cardano/Logging/Resources/Types.hs | 163 ---------- .../src/Cardano/Logging/Resources/Windows.hsc | 179 ----------- trace-resources/test/trace-resources-test.hs | 59 ---- trace-resources/trace-resources.cabal | 109 ------- 39 files changed, 40 insertions(+), 1554 deletions(-) delete mode 100644 trace-resources/.gitignore delete mode 100644 trace-resources/CHANGELOG.md delete mode 100644 trace-resources/LICENSE delete mode 100644 trace-resources/NOTICE delete mode 100644 trace-resources/README.md delete mode 100644 trace-resources/bench/trace-resources-bench.hs delete mode 100644 trace-resources/cbits/os-support-darwin.c delete mode 100644 trace-resources/cbits/os-support-win.c delete mode 100644 trace-resources/include/os-support-darwin.h delete mode 100644 trace-resources/include/os-support-win.h delete mode 100644 trace-resources/src/Cardano/Logging/Resources.hs delete mode 100644 trace-resources/src/Cardano/Logging/Resources/Darwin.hsc delete mode 100644 trace-resources/src/Cardano/Logging/Resources/Dummy.hs delete mode 100644 trace-resources/src/Cardano/Logging/Resources/Linux.hs delete mode 100644 trace-resources/src/Cardano/Logging/Resources/Types.hs delete mode 100644 trace-resources/src/Cardano/Logging/Resources/Windows.hsc delete mode 100644 trace-resources/test/trace-resources-test.hs delete mode 100644 trace-resources/trace-resources.cabal diff --git a/.github/workflows/stylish-haskell.yml b/.github/workflows/stylish-haskell.yml index f709fe84c41..3e79c18a197 100644 --- a/.github/workflows/stylish-haskell.yml +++ b/.github/workflows/stylish-haskell.yml @@ -38,7 +38,6 @@ jobs: cardano-tracer trace-dispatcher trace-forward - trace-resources steps: - name: Download stylish-haskell diff --git a/bench/cardano-timeseries-io/app/Cardano/Timeseries/Common.hs b/bench/cardano-timeseries-io/app/Cardano/Timeseries/Common.hs index 65f096949e2..1905c49844e 100644 --- a/bench/cardano-timeseries-io/app/Cardano/Timeseries/Common.hs +++ b/bench/cardano-timeseries-io/app/Cardano/Timeseries/Common.hs @@ -4,7 +4,7 @@ module Cardano.Timeseries.Common(readStore, repl, printInterpResult, printExecutionResult) where -import Cardano.Logging.Resources (ResourceStats, Resources (..), readResourceStats) +import Hermod.Tracing.Resources (ResourceStats, Resources (..), readResourceStats) import Cardano.Timeseries.API import Cardano.Timeseries.Import.PlainCBOR diff --git a/bench/cardano-timeseries-io/cardano-timeseries-io.cabal b/bench/cardano-timeseries-io/cardano-timeseries-io.cabal index 7068567fb37..0f172e7687a 100644 --- a/bench/cardano-timeseries-io/cardano-timeseries-io.cabal +++ b/bench/cardano-timeseries-io/cardano-timeseries-io.cabal @@ -144,7 +144,7 @@ executable cardano-timeseries-io , statistics , text , time - , trace-resources + , hermod-trace-resources , vector test-suite cardano-timeseries-test @@ -184,6 +184,6 @@ benchmark cardano-timeseries-io-bench , statistics , text , time - , trace-resources + , hermod-trace-resources , vector , zlib diff --git a/bench/locli/locli.cabal b/bench/locli/locli.cabal index 282c9c16712..93e8ccd141f 100644 --- a/bench/locli/locli.cabal +++ b/bench/locli/locli.cabal @@ -136,7 +136,7 @@ library , text , text-short , time - , trace-resources + , hermod-trace-resources , transformers , transformers-except , unix @@ -197,7 +197,7 @@ executable locli-quick , text , text-short , time - , trace-resources + , hermod-trace-resources , sqlite-easy >= 1.1.0.1 , unordered-containers diff --git a/bench/locli/src/Cardano/Analysis/API/Metrics.hs b/bench/locli/src/Cardano/Analysis/API/Metrics.hs index 3cece471e13..b7bb4ab6c81 100644 --- a/bench/locli/src/Cardano/Analysis/API/Metrics.hs +++ b/bench/locli/src/Cardano/Analysis/API/Metrics.hs @@ -21,7 +21,7 @@ import Data.Time.Clock import Data.Map.Strict qualified as M -- Repo-local: -import Cardano.Logging.Resources.Types +import Hermod.Tracing.Resources.Types -- Package-local: import Data.CDF diff --git a/bench/locli/src/Cardano/Analysis/API/Types.hs b/bench/locli/src/Cardano/Analysis/API/Types.hs index 9f8331b3cfa..9c0305b5a70 100644 --- a/bench/locli/src/Cardano/Analysis/API/Types.hs +++ b/bench/locli/src/Cardano/Analysis/API/Types.hs @@ -15,7 +15,7 @@ import Options.Applicative qualified as Opt import Data.CDF import Data.Profile -import Cardano.Logging.Resources.Types +import Hermod.Tracing.Resources.Types import Cardano.Unlog.LogObject import Cardano.Util diff --git a/bench/locli/src/Cardano/Unlog/LogObject.hs b/bench/locli/src/Cardano/Unlog/LogObject.hs index fadc6bd0b4c..df5d3b482ce 100644 --- a/bench/locli/src/Cardano/Unlog/LogObject.hs +++ b/bench/locli/src/Cardano/Unlog/LogObject.hs @@ -33,7 +33,7 @@ module Cardano.Unlog.LogObject where import Cardano.Analysis.API.Ground -import Cardano.Logging.Resources.Types +import Hermod.Tracing.Resources.Types import Cardano.Prelude hiding (Text, show, toText) import Cardano.Util diff --git a/bench/locli/src/Cardano/Unlog/LogObjectDB.hs b/bench/locli/src/Cardano/Unlog/LogObjectDB.hs index 0ecb91ec19b..d528e75ff08 100644 --- a/bench/locli/src/Cardano/Unlog/LogObjectDB.hs +++ b/bench/locli/src/Cardano/Unlog/LogObjectDB.hs @@ -37,7 +37,7 @@ module Cardano.Unlog.LogObjectDB ) where import Cardano.Analysis.API.Ground -import Cardano.Logging.Resources.Types (ResourceStats, Resources (..)) +import Hermod.Tracing.Resources.Types (ResourceStats, Resources (..)) import Cardano.Unlog.LogObject import Cardano.Util hiding (count) diff --git a/bench/locli/src/Cardano/Unlog/Resources.hs b/bench/locli/src/Cardano/Unlog/Resources.hs index 428526684cc..1242129ef0e 100644 --- a/bench/locli/src/Cardano/Unlog/Resources.hs +++ b/bench/locli/src/Cardano/Unlog/Resources.hs @@ -18,7 +18,7 @@ import Cardano.Prelude import Data.Accum import Data.CDF import Cardano.Util -import Cardano.Logging.Resources.Types +import Hermod.Tracing.Resources.Types deriving instance Foldable Resources deriving instance Traversable Resources diff --git a/bench/trace-schemas/scripts/schema-gen/GhciSchemaGen.hs b/bench/trace-schemas/scripts/schema-gen/GhciSchemaGen.hs index 854d2750c9d..7d37fd243ed 100644 --- a/bench/trace-schemas/scripts/schema-gen/GhciSchemaGen.hs +++ b/bench/trace-schemas/scripts/schema-gen/GhciSchemaGen.hs @@ -55,8 +55,8 @@ rootDirs = , "../ouroboros-consensus/ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion" , "../ouroboros-consensus/ouroboros-consensus-cardano/src" , "../hermod-tracing/trace-dispatcher/src" + , "../hermod-tracing/hermod-trace-resources/src" , "trace-forward/src" - , "trace-resources/src" ] type ConstructorName = String diff --git a/cabal.project b/cabal.project index c818a53ab0c..650531a91a1 100644 --- a/cabal.project +++ b/cabal.project @@ -48,7 +48,6 @@ packages: bench/tx-generator bench/cardano-timeseries-io bench/trace-schemas/scripts/schema-gen - trace-resources trace-forward -- Needed when cross compiling @@ -86,3 +85,12 @@ allow-newer: -- IMPORTANT -- Do NOT add more source-repository-package stanzas here unless they are strictly -- temporary! Please read the section in CONTRIBUTING about updating dependencies. + +-- Temporary: hermod-trace-resources is pending publication to CHaP. +-- Update the tag to the hermod-tracing commit that includes hermod-trace-resources, +-- then remove this stanza once the package is available in CHaP. +source-repository-package + type: git + location: https://github.com/IntersectMBO/hermod-tracing + tag: f94edf21d7df01f43e115e370f0a48fd00240003 + subdir: hermod-trace-resources diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 2614d7d7884..0c17e7a71f8 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -183,7 +183,7 @@ library , time , trace-dispatcher ^>= 2.12.0 , trace-forward ^>= 2.4.0 - , trace-resources ^>= 0.2.4 + , hermod-trace-resources ^>= 0.2.4 , transformers , transformers-except , typed-protocols:{typed-protocols, stateful} >= 1.2 diff --git a/cardano-node/src/Cardano/Node/Tracing.hs b/cardano-node/src/Cardano/Node/Tracing.hs index 127a1e75ce0..503815b0268 100644 --- a/cardano-node/src/Cardano/Node/Tracing.hs +++ b/cardano-node/src/Cardano/Node/Tracing.hs @@ -9,7 +9,7 @@ module Cardano.Node.Tracing , ConsensusStartupException (..) ) where -import Cardano.Logging.Resources +import Hermod.Tracing.Resources import qualified Cardano.Network.Diffusion as Cardano.Diffusion import Cardano.Node.Handlers.Shutdown (ShutdownTrace) import Cardano.Node.Startup (NodeInfo, NodeStartupInfo, StartupTrace (..)) diff --git a/cardano-node/src/Cardano/Node/Tracing/Consistency.hs b/cardano-node/src/Cardano/Node/Tracing/Consistency.hs index b611c07fc90..2b4160d6061 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Consistency.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Consistency.hs @@ -14,8 +14,8 @@ module Cardano.Node.Tracing.Consistency import Cardano.Logging -import Cardano.Logging.Resources -import Cardano.Logging.Resources.Types () +import Hermod.Tracing.Resources +import Hermod.Tracing.Resources.Types () import Cardano.Network.NodeToNode (RemoteAddress) import qualified Cardano.Network.NodeToNode as NtN import qualified Cardano.Network.PeerSelection.ExtraRootPeers as Cardano.PublicRootPeers diff --git a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs index e5b0a998ad6..ddd8917de3c 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs @@ -27,8 +27,8 @@ import Cardano.Network.Tracing.PeerSelection () import Cardano.Network.Tracing.PeerSelectionCounters () import Cardano.Git.Rev (gitRev) import Cardano.Logging as Logging -import Cardano.Logging.Resources -import Cardano.Logging.Resources.Types () +import Hermod.Tracing.Resources +import Hermod.Tracing.Resources.Types () import qualified Cardano.Network.PeerSelection.ExtraRootPeers as Cardano.PublicRootPeers import qualified Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano import qualified Cardano.Network.PeerSelection.Governor.Types as Cardano diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Resources.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Resources.hs index dd8e31609f9..7e2dae8461f 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Resources.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Resources.hs @@ -4,7 +4,7 @@ module Cardano.Node.Tracing.Tracers.Resources ( startResourceTracer ) where -import Cardano.Logging.Resources +import Hermod.Tracing.Resources import Control.Concurrent (threadDelay) import Control.Concurrent.Async (async) diff --git a/cardano-tracer/cardano-tracer.cabal b/cardano-tracer/cardano-tracer.cabal index 26a6324fcc9..4bd54e45a87 100644 --- a/cardano-tracer/cardano-tracer.cabal +++ b/cardano-tracer/cardano-tracer.cabal @@ -199,7 +199,7 @@ library , time , trace-dispatcher ^>= 2.12.0 , trace-forward ^>= 2.4.0 - , trace-resources ^>= 0.2.4 + , hermod-trace-resources ^>= 0.2.4 , vector , wai ^>= 3.2 , warp ^>= 3.4 diff --git a/cardano-tracer/src/Cardano/Tracer/MetaTrace.hs b/cardano-tracer/src/Cardano/Tracer/MetaTrace.hs index b48b8a7a50d..627ce54e2a5 100644 --- a/cardano-tracer/src/Cardano/Tracer/MetaTrace.hs +++ b/cardano-tracer/src/Cardano/Tracer/MetaTrace.hs @@ -21,7 +21,7 @@ module Cardano.Tracer.MetaTrace ) where import Cardano.Logging -import Cardano.Logging.Resources +import Hermod.Tracing.Resources import Cardano.Timeseries.Component.Trace (TimeseriesTrace) import Cardano.Tracer.Configuration import Cardano.Tracer.Types (NodeId (..), NodeName) diff --git a/cardano-tracer/src/Cardano/Tracer/Run.hs b/cardano-tracer/src/Cardano/Tracer/Run.hs index ad10952cae1..dd6aedd8c71 100644 --- a/cardano-tracer/src/Cardano/Tracer/Run.hs +++ b/cardano-tracer/src/Cardano/Tracer/Run.hs @@ -11,7 +11,7 @@ module Cardano.Tracer.Run , runCardanoTracer ) where -import Cardano.Logging.Resources +import Hermod.Tracing.Resources import Cardano.Tracer.Acceptors.Run import Cardano.Tracer.CLI import Cardano.Tracer.Configuration diff --git a/flake.nix b/flake.nix index 9d2e94b87f8..1d2afd3395e 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,11 @@ flake = false; }; + hermod-tracing = { + url = "github:IntersectMBO/hermod-tracing/without_contra_included"; + flake = false; + }; + haskellNix = { url = "github:input-output-hk/haskell.nix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -503,7 +508,7 @@ cardanoNodeProject = (import ./nix/haskell.nix { inherit (final) haskell-nix; - inherit CHaP incl windowsCompilerNixName; + inherit CHaP hermod-tracing incl windowsCompilerNixName; macOS-security = macOS-security (final.pkgs); }) .appendModule [ diff --git a/nix/haskell.nix b/nix/haskell.nix index eb2dbf88ce3..2bce0b63059 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -4,6 +4,7 @@ { haskell-nix , incl , CHaP +, hermod-tracing , macOS-security , windowsCompilerNixName }: @@ -46,7 +47,8 @@ let flags: -systemd ''; inputMap = { - "https://chap.intersectmbo.org/" = CHaP; + "https://chap.intersectmbo.org/" = CHaP; + "https://github.com/IntersectMBO/hermod-tracing" = hermod-tracing; }; shell = { name = lib.mkDefault "cabal-dev-shell"; @@ -400,7 +402,7 @@ project.appendOverlays (with haskellLib.projectOverlays; [ [ "cardano-node" "cardano-tracer" "trace-forward" - "trace-resources" + "hermod-trace-resources" ] (name: { configureFlags = [ "--ghc-option=-fprof-auto" ]; }); }]; diff --git a/trace-resources/.gitignore b/trace-resources/.gitignore deleted file mode 100644 index e825f8bed1c..00000000000 --- a/trace-resources/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -.cabal-sandbox -dist -cabal.sandbox.config -TAGS -.stack-work/ -*.o -*.hi -*.dyn_o -*.dyn_hi -stack.yaml.lock -*.pdf diff --git a/trace-resources/CHANGELOG.md b/trace-resources/CHANGELOG.md deleted file mode 100644 index 8111c077bb3..00000000000 --- a/trace-resources/CHANGELOG.md +++ /dev/null @@ -1,26 +0,0 @@ -# Revision history for trace-resources - -## 0.2.4 -* Patch up CPU time metric on darwin - -## 0.2.3 - -* New names for metrics - -## 0.2.1.0 -- Nov 2023 - -* Optimized resource record creation on Linux -* Add microbenchmark for resource record creation -* Add cabal flag `with-netstat` (default: False) to enable netstat values in Linux resource traces (potentially expensive) - -## 0.2.0.2 -- Sep 2023 - -* Updated to `cardano-api-8.20`, `cardano-cli-8.8` and `ouroboros-network-0.9.1.0` - -## 0.2.0.0 -- May 2023 - -* Undocumented changes - -## 0.1.0.0 -- October 2022 - -* First version. Released on an unsuspecting world. diff --git a/trace-resources/LICENSE b/trace-resources/LICENSE deleted file mode 100644 index f433b1a53f5..00000000000 --- a/trace-resources/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/trace-resources/NOTICE b/trace-resources/NOTICE deleted file mode 100644 index 2595781f2d5..00000000000 --- a/trace-resources/NOTICE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2021-2023 Input Output Global Inc (IOG), 2023-2026 Intersect. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/trace-resources/README.md b/trace-resources/README.md deleted file mode 100644 index df371933b90..00000000000 --- a/trace-resources/README.md +++ /dev/null @@ -1,3 +0,0 @@ -trace-resources - -Query resource statistics for various platforms for tracing. diff --git a/trace-resources/bench/trace-resources-bench.hs b/trace-resources/bench/trace-resources-bench.hs deleted file mode 100644 index 57509904db9..00000000000 --- a/trace-resources/bench/trace-resources-bench.hs +++ /dev/null @@ -1,22 +0,0 @@ -{-# LANGUAGE CPP #-} - -import Criterion.Main -import Criterion.Types - - -#if defined(linux_HOST_OS) -import qualified Cardano.Logging.Resources.Linux as Platform -#elif defined(mingw32_HOST_OS) -import qualified Cardano.Logging.Resources.Windows as Platform -#elif defined(darwin_HOST_OS) -import qualified Cardano.Logging.Resources.Darwin as Platform -#else -import qualified Cardano.Logging.Resources.Dummy as Platform -#endif - - -main :: IO () -main = - defaultMainWith defaultConfig{ timeLimit = 15 } - [ bench "create record ResourceStats" (whnfIO Platform.readResourceStatsInternal) - ] diff --git a/trace-resources/cbits/os-support-darwin.c b/trace-resources/cbits/os-support-darwin.c deleted file mode 100644 index a71aa18ef99..00000000000 --- a/trace-resources/cbits/os-support-darwin.c +++ /dev/null @@ -1,289 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* -// includes for c_get_sys_disk_io_counters -// will require GHC options in cabal file: -// if os(darwin) -// ghc-options: -framework CoreFoundation -framework IOKit -// -#include -#include -#include -#include -#include -#include -#include -*/ -#include "os-support-darwin.h" - - -/* c_get_process_memory_info */ - -int c_get_process_memory_info2(struct mach_task_basic_info *counters, int pid) -{ - task_t task = MACH_PORT_NULL; - if (task_for_pid(current_task(), pid, &task) != KERN_SUCCESS) { - return -2; - } - struct mach_task_basic_info t_info; - mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT; - if (task_info(task, MACH_TASK_BASIC_INFO, (task_info_t)counters, &t_info_count) != KERN_SUCCESS) { - return -1; - } - return 1; -} - - -/* c_get_host_info */ -/* currently this is not used -int c_get_host_info2(struct host_basic_info *counters) -{ - mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; - mach_port_t host_port = mach_host_self(); - if (host_statistics(host_port, HOST_BASIC_INFO, - (host_info_t)counters, &count) != KERN_SUCCESS) { - return -2; - } - mach_port_deallocate(mach_task_self(), host_port); - return 1; -} */ - -/* c_get_boot_time */ - -long c_get_boot_time2() -{ - // copied from psutil - // fetch sysctl "kern.boottime" - static int request[2] = { CTL_KERN, KERN_BOOTTIME }; - struct timeval result; - size_t result_len = sizeof result; - time_t boot_time = 0; - - if (sysctl(request, 2, &result, &result_len, NULL, 0) == -1) { - return -1; - } - return result.tv_sec; -} - -/* c_get_sys_cpu_times */ -int c_get_sys_cpu_times2(CPU_TIMES *counters) -{ - mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT; - host_cpu_load_info_data_t r_load; - - mach_port_t host_port = mach_host_self(); - if (host_statistics(host_port, HOST_CPU_LOAD_INFO, - (host_info_t)&r_load, &count) != KERN_SUCCESS) { - return -2; - } - mach_port_deallocate(mach_task_self(), host_port); - counters->usertime = r_load.cpu_ticks[CPU_STATE_USER] * 100000 / CLK_TCK; - counters->systime = r_load.cpu_ticks[CPU_STATE_SYSTEM] * 100000 / CLK_TCK; - counters->idletime = r_load.cpu_ticks[CPU_STATE_IDLE] * 100000 / CLK_TCK; - counters->nicetime = r_load.cpu_ticks[CPU_STATE_NICE] * 100000 / CLK_TCK; - return 1; -} - -/* c_get_proc_cpu_times */ - - - -/* c_get_sys_disk_io_counters */ -/* adapted from psutil */ -int c_get_sys_disk_io_counters2(DISK_COUNTERS *counters) { - counters->ndsks = 0; - // uncomment the following to extract disk I/O metrics - // requires to include the right headers (see top of this file) - // and link to frameworks on Darwin (also described there) -/* - int noutput = 0; - CFDictionaryRef parent_dict; - CFDictionaryRef props_dict; - CFDictionaryRef stats_dict; - io_registry_entry_t parent; - io_registry_entry_t disk; - io_iterator_t disk_list; - - // Get list of disks - if (IOServiceGetMatchingServices( - kIOMasterPortDefault, - IOServiceMatching(kIOMediaClass), - &disk_list) != kIOReturnSuccess) { - return -4; - } - - // Iterate over disks - while ((disk = IOIteratorNext(disk_list)) != 0) { - parent_dict = NULL; - props_dict = NULL; - stats_dict = NULL; - - if (IORegistryEntryGetParentEntry(disk, kIOServicePlane, &parent) != kIOReturnSuccess) { - return -3; - } - - if (IOObjectConformsTo(parent, "IOBlockStorageDriver")) { - - if (IORegistryEntryCreateCFProperties(disk, - (CFMutableDictionaryRef *) &parent_dict, - kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { - IOObjectRelease(disk); - IOObjectRelease(parent); - return -2; - } - - if (IORegistryEntryCreateCFProperties(parent, - (CFMutableDictionaryRef *) &props_dict, - kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { - CFRelease(props_dict); - IOObjectRelease(disk); - IOObjectRelease(parent); - return -1; - } - - const int kMaxDiskNameSize = 64; - char disk_name[kMaxDiskNameSize+1]; memset(disk_name, 0, kMaxDiskNameSize+1); - CFStringRef disk_name_ref = (CFStringRef) - CFDictionaryGetValue(parent_dict, CFSTR(kIOBSDNameKey)); - CFStringGetCString(disk_name_ref, disk_name, - kMaxDiskNameSize, - CFStringGetSystemEncoding()); - counters->dsknames[noutput] = strdup(disk_name); - - stats_dict = (CFDictionaryRef) - CFDictionaryGetValue(props_dict, CFSTR(kIOBlockStorageDriverStatisticsKey)); - if (stats_dict == NULL) { - continue; - } - CFNumberRef number; - int64_t t_num64 = 0; - // Get disk reads/writes - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsReadsKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].reads = t_num64; - } - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsWritesKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].writes = t_num64; - } - // Get disk bytes read/written - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].read_bytes = t_num64; - } - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].write_bytes = t_num64; - } - // Get disk time spent reading/writing (nanoseconds) - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsTotalReadTimeKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].read_time = t_num64; - } - if ((number = (CFNumberRef)CFDictionaryGetValue(stats_dict, - CFSTR(kIOBlockStorageDriverStatisticsTotalWriteTimeKey)))) { - CFNumberGetValue(number, kCFNumberSInt64Type, &t_num64); - counters->dsks[noutput].write_time = t_num64; - } - - CFRelease(parent_dict); - IOObjectRelease(parent); - CFRelease(props_dict); - IOObjectRelease(disk); - - noutput++; - if (noutput >= MAX_DISK_COUNTERS) { break; } - } - } // while - IOObjectRelease (disk_list); - counters->ndsks = noutput; -*/ - return 1; -} - -/* c_get_sys_network_io_counters */ -/* adapted from psutil */ -int c_get_sys_network_io_counters2(NET_IO *counters) { - counters->nifs = 0; - int noutput = 0; - char *msghdrbuf = NULL, *end_of_list, *next; - struct if_msghdr *ifm; - int mib[6]; - mib[0] = CTL_NET; // networking subsystem - mib[1] = PF_ROUTE; // type of information - mib[2] = 0; // protocol (IPPROTO_xxx) - mib[3] = 0; // address family - mib[4] = NET_RT_IFLIST2; // operation - mib[5] = 0; - size_t buflen; - if (sysctl(mib, 6, NULL, &buflen, NULL, 0) < 0) { - return -4; - } - - msghdrbuf = malloc(buflen); - if (msghdrbuf == NULL) { - return -3; - } - if (sysctl(mib, 6, msghdrbuf, &buflen, NULL, 0) < 0) { - return -2; - } - - char nmbuf[12+1]; - - end_of_list = msghdrbuf + buflen; - for (next = msghdrbuf; next < end_of_list; ) { - ifm = (struct if_msghdr *)next; - next += ifm->ifm_msglen; - if (ifm->ifm_type == RTM_IFINFO2 && (ifm->ifm_flags & IFF_UP)) { - struct if_msghdr2 *if2m = (struct if_msghdr2 *)ifm; - // access name of interface and make a copy of the string - // struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1); - // memset(nmbuf, 0, 12+1); - // strncpy(nmbuf, sdl->sdl_data, MIN(12,sdl->sdl_nlen)); - // counters->ifnames[noutput] = strdup(nmbuf); - - // copy struct if_data64 - memcpy(&counters->ifs[noutput], &if2m->ifm_data, sizeof(struct if_data64)); - noutput++; - } - if (noutput >= MAX_NET_IO) { break; } - } - counters->nifs = noutput; - free(msghdrbuf); - return 1; -} - -uint64_t c_get_process_cpu_time_microseconds(pid_t pid) { - struct proc_taskinfo ti; - - int ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &ti, sizeof(ti)); - - if (ret <= 0) { - perror("proc_pidinfo"); - return 0; - } - - uint64_t user_microsec = ti.pti_total_user / 1e3; - uint64_t sys_microsec = ti.pti_total_system / 1e3; - - return user_microsec + sys_microsec; -} diff --git a/trace-resources/cbits/os-support-win.c b/trace-resources/cbits/os-support-win.c deleted file mode 100644 index 3635e34764f..00000000000 --- a/trace-resources/cbits/os-support-win.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -//#include - -#include "os-support-win.h" - - -/* c_get_process_memory_info */ - -int c_get_process_memory_info2 (PROCESS_MEMORY_COUNTERS *counters, DWORD pid) { - HANDLE hProc; - hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - FALSE, pid ); - if (NULL == hProc) { return -2; } - BOOL result = GetProcessMemoryInfo(hProc, counters, sizeof(PROCESS_MEMORY_COUNTERS)); - CloseHandle(hProc); - if (result == 1) - return 0; - else - return -1; -} - - -/* c_get_io_counters */ - -int c_get_io_counters2 (IO_COUNTERS *counters, DWORD pid) { - HANDLE hProc; - hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, - FALSE, pid ); - if (NULL == hProc) { return -2; } - BOOL result = GetProcessIoCounters(hProc, counters); - CloseHandle(hProc); - return result; -} - - -// defined in 'psutil' -// #define LO_T 1e-7 -// #define HI_T 429.4967296 - -/* c_get_sys_cpu_times */ -int c_get_sys_cpu_times2 (CPU_TIMES *cputimes) { - FILETIME usert={0,0}, kernelt={0,0}, idlet={0,0}; - if (! GetSystemTimes(&idlet, &kernelt, &usert) ) { - return -2; - } - cputimes->usertime = ((ULONGLONG)usert.dwHighDateTime << 32 | usert.dwLowDateTime) / 10; - ULONGLONG kerneltime = ((ULONGLONG)kernelt.dwHighDateTime << 32 | kernelt.dwLowDateTime) / 10; - cputimes->idletime = ((ULONGLONG)idlet.dwHighDateTime << 32 | idlet.dwLowDateTime) / 10; - cputimes->systime = kerneltime - cputimes->idletime; - return 1; -} - -/* c_get_proc_cpu_times */ -int c_get_proc_cpu_times2 (CPU_TIMES *cputimes, DWORD pid) { - HANDLE hProc; - hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, - FALSE, pid ); - if (NULL == hProc) { return -2; } - FILETIME usert={0,0}, kernelt={0,0}, createt={0,0}, exitt={0,0}; - if (! GetProcessTimes(hProc, &createt, &exitt, &kernelt, &usert) ) { - return -1; - } - CloseHandle(hProc); - /* FILETIME is a structured of two 32 bit counters to form a 64 bit time in 100 ns units */ - /* divide by 10 to get microseconds */ - /* start time: Jan-1 1601 UTC */ - cputimes->usertime = ((ULONGLONG)usert.dwHighDateTime << 32 | usert.dwLowDateTime) / 10; - cputimes->systime = ((ULONGLONG)kernelt.dwHighDateTime << 32 | kernelt.dwLowDateTime) / 10; - // return time since process start in "idletime" - cputimes->idletime = ((ULONGLONG)createt.dwHighDateTime << 32 | createt.dwLowDateTime) / 10; - return 1; -} - -/* c_get_system_info */ -int c_get_system_info2 (SYSTEM_INFO *sysinfo) { - GetSystemInfo (sysinfo); - return 1; -} - -/* c_get_win_bits */ -int c_get_win_bits2 (DWORD pid) { - BOOL res; - HANDLE hProc; - hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, - FALSE, pid ); - if (NULL == hProc) { return -2; } - if (! IsWow64Process(hProc, &res)) { - return -1; - } - CloseHandle(hProc); - if (res) { - return 32; - } - return 64; -} diff --git a/trace-resources/include/os-support-darwin.h b/trace-resources/include/os-support-darwin.h deleted file mode 100644 index 8a929800c6f..00000000000 --- a/trace-resources/include/os-support-darwin.h +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include -#include - -typedef struct _CPU_TIMES { - int64_t usertime; - int64_t systime; - int64_t idletime; - int64_t nicetime; -} CPU_TIMES; - -#define MAX_NET_IO 32 -typedef struct _NET_IO { - u_int32_t nifs; - char* ifnames[MAX_NET_IO]; - struct if_data64 ifs[MAX_NET_IO]; -} NET_IO; - -typedef struct _DISK_INFO { - int64_t reads, writes; - int64_t read_bytes, write_bytes; - int64_t read_time, write_time; // nanoseconds -} DISK_INFO; -#define MAX_DISK_COUNTERS 32 -typedef struct _DISK_COUNTERS { - u_int32_t ndsks; - char* dsknames[MAX_DISK_COUNTERS]; - DISK_INFO dsks[MAX_DISK_COUNTERS]; -} DISK_COUNTERS; - -int c_get_process_memory_info2 (struct mach_task_basic_info *counters, int pid); -//int c_get_host_info (struct host_basic_info *counters); -long c_get_boot_time2(); -int c_get_sys_cpu_times2(CPU_TIMES *counters); -int c_get_sys_network_io_counters2(NET_IO *counters); -int c_get_sys_disk_io_counters2(DISK_COUNTERS *counters); -uint64_t c_get_process_cpu_time_microseconds(pid_t); diff --git a/trace-resources/include/os-support-win.h b/trace-resources/include/os-support-win.h deleted file mode 100644 index 333ef6a2f26..00000000000 --- a/trace-resources/include/os-support-win.h +++ /dev/null @@ -1,14 +0,0 @@ - -typedef struct _CPU_TIMES { - ULONGLONG usertime; - ULONGLONG systime; - ULONGLONG idletime; -} CPU_TIMES; - -int c_get_process_memory_info2 (PROCESS_MEMORY_COUNTERS *counters, DWORD pid); -int c_get_io_counters2 (IO_COUNTERS *counters, DWORD pid); -int c_get_sys_cpu_times2 (CPU_TIMES *cputimes); -int c_get_proc_cpu_times2 (CPU_TIMES *cputimes, DWORD pid); -int c_get_system_info2 (SYSTEM_INFO *sysinfo); -int c_get_win_bits2 (DWORD pid); - diff --git a/trace-resources/src/Cardano/Logging/Resources.hs b/trace-resources/src/Cardano/Logging/Resources.hs deleted file mode 100644 index f747b6597a9..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources.hs +++ /dev/null @@ -1,23 +0,0 @@ -{-# LANGUAGE CPP #-} - -module Cardano.Logging.Resources - ( Resources(..) - , ResourceStats - , readResourceStats - ) where - - -import Cardano.Logging.Resources.Types -#if defined(linux_HOST_OS) -import qualified Cardano.Logging.Resources.Linux as Platform -#elif defined(mingw32_HOST_OS) -import qualified Cardano.Logging.Resources.Windows as Platform -#elif defined(darwin_HOST_OS) -import qualified Cardano.Logging.Resources.Darwin as Platform -#else -import qualified Cardano.Logging.Resources.Dummy as Platform -#endif - - -readResourceStats :: IO (Maybe ResourceStats) -readResourceStats = Platform.readResourceStatsInternal diff --git a/trace-resources/src/Cardano/Logging/Resources/Darwin.hsc b/trace-resources/src/Cardano/Logging/Resources/Darwin.hsc deleted file mode 100644 index e4ffa049585..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources/Darwin.hsc +++ /dev/null @@ -1,114 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE ForeignFunctionInterface #-} - -module Cardano.Logging.Resources.Darwin - ( readResourceStatsInternal - ) where - -#include "os-support-darwin.h" - -import Data.Word (Word64) -import Foreign.C.Types -import Foreign.Marshal.Alloc -import Foreign.Marshal.Error -import Foreign.Ptr -import Foreign.Storable -import qualified GHC.Stats as GhcStats -import System.Posix.Process (getProcessID) -import System.Posix.Types (ProcessID) -import Cardano.Logging.Resources.Types - -{- type aliases -} -type MACH_VM_SIZE_T = Word64 -data TIME_VALUE_T = TIME_VALUE_T Word64 Word64 - -{- memory information -} - -{- mach/task_info.h -struct time_value { - integer_t seconds; - integer_t microseconds; -}; -struct mach_task_basic_info { - mach_vm_size_t virtual_size; /* virtual memory size (bytes) */ - mach_vm_size_t resident_size; /* resident memory size (bytes) */ - mach_vm_size_t resident_size_max; /* maximum resident memory size (bytes) */ - time_value_t user_time; /* total user run time for - * terminated threads */ - time_value_t system_time; /* total system run time for - * terminated threads */ - policy_t policy; /* default policy for new threads */ - integer_t suspend_count; /* suspend count for task */ -}; -} - -data MachTaskBasicInfo = MachTaskBasicInfo - { _virtual_size :: !MACH_VM_SIZE_T - , _resident_size :: !MACH_VM_SIZE_T - , _resident_size_max :: !MACH_VM_SIZE_T - , _user_time :: !TIME_VALUE_T - , _system_time :: !TIME_VALUE_T - , _policy :: !Word64 - , _suspend_count :: !Word64 - } - -instance Storable TIME_VALUE_T where - alignment _ = #const offsetof(struct {char x__; struct time_value (y__); }, y__) - sizeOf _ = #size struct time_value - peek ptr = TIME_VALUE_T - <$> (#peek struct time_value, seconds) ptr - <*> (#peek struct time_value, microseconds) ptr - poke _ _ = pure () - -instance Storable MachTaskBasicInfo where - alignment _ = #const offsetof(struct {char x__; struct mach_task_basic_info (y__); }, y__) - sizeOf _ = #size struct mach_task_basic_info - peek ptr = MachTaskBasicInfo - <$> (#peek struct mach_task_basic_info, virtual_size) ptr - <*> (#peek struct mach_task_basic_info, resident_size) ptr - <*> (#peek struct mach_task_basic_info, resident_size_max) ptr - <*> (#peek struct mach_task_basic_info, user_time) ptr - <*> (#peek struct mach_task_basic_info, system_time) ptr - <*> (#peek struct mach_task_basic_info, policy) ptr - <*> (#peek struct mach_task_basic_info, suspend_count) ptr - poke _ _ = pure () - -foreign import ccall unsafe c_get_process_memory_info2 :: Ptr MachTaskBasicInfo -> CInt -> IO CInt - -foreign import ccall unsafe c_get_process_cpu_time_microseconds :: CInt -> IO Word64 - - -getMemoryInfo :: ProcessID -> IO MachTaskBasicInfo -getMemoryInfo pid = - allocaBytes 128 $ \ptr -> do - throwIfNeg_ (\res -> "c_get_process_memory_info2: failure returned: " ++ show (pred res)) - (succ <$> c_get_process_memory_info2 ptr (fromIntegral pid)) - peek ptr - -readResourceStatsInternal :: IO (Maybe ResourceStats) -readResourceStatsInternal = getProcessID >>= \pid -> do - rts <- GhcStats.getRTSStats - mem <- getMemoryInfo pid - cpuTimeMicro <- c_get_process_cpu_time_microseconds (fromIntegral pid) - pure . Just $ - Resources - { rCentiCpu = usToCenti cpuTimeMicro - , rCentiGC = nsToCenti $ GhcStats.gc_cpu_ns rts - , rCentiMut = nsToCenti $ GhcStats.mutator_cpu_ns rts - , rGcsMajor = fromIntegral $ GhcStats.major_gcs rts - , rGcsMinor = fromIntegral $ GhcStats.gcs rts - GhcStats.major_gcs rts - , rAlloc = GhcStats.allocated_bytes rts - , rLive = GhcStats.gcdetails_live_bytes $ GhcStats.gc rts - , rHeap = GhcStats.gcdetails_mem_in_use_bytes $ GhcStats.gc rts - , rRSS = _resident_size mem - , rCentiBlkIO = 0 - , rNetRd = 0 - , rNetWr = 0 - , rFsRd = 0 - , rFsWr = 0 - , rThreads = 0 - } - where - nsToCenti :: GhcStats.RtsTime -> Word64 - nsToCenti = fromIntegral . (`div` 10000000) - usToCenti :: Word64 -> Word64 - usToCenti = (`div` 10000) diff --git a/trace-resources/src/Cardano/Logging/Resources/Dummy.hs b/trace-resources/src/Cardano/Logging/Resources/Dummy.hs deleted file mode 100644 index cefa39be366..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources/Dummy.hs +++ /dev/null @@ -1,39 +0,0 @@ -module Cardano.Logging.Resources.Dummy - ( - readResourceStatsInternal - ) where - -import Cardano.Logging.Resources.Types - -import Data.Word -import qualified GHC.Stats as GhcStats -import System.CPUTime - - -readResourceStatsInternal :: IO (Maybe ResourceStats) -readResourceStatsInternal = do - cpu <- getCPUTime - rts <- GhcStats.getRTSStats - pure $ Just $ - Resources - { rCentiCpu = intToCenti cpu - , rCentiGC = nsToCenti $ GhcStats.gc_cpu_ns rts - , rCentiMut = nsToCenti $ GhcStats.mutator_cpu_ns rts - , rGcsMajor = fromIntegral $ GhcStats.major_gcs rts - , rGcsMinor = fromIntegral $ GhcStats.gcs rts - GhcStats.major_gcs rts - , rAlloc = GhcStats.allocated_bytes rts - , rLive = GhcStats.gcdetails_live_bytes $ GhcStats.gc rts - , rRSS = 0 - , rHeap = 0 - , rCentiBlkIO = 0 - , rNetRd = 0 - , rNetWr = 0 - , rFsRd = 0 - , rFsWr = 0 - , rThreads = 0 - } - where - nsToCenti :: GhcStats.RtsTime -> Word64 - nsToCenti = fromIntegral . (`div` 10000000) - intToCenti :: Integer -> Word64 - intToCenti = fromIntegral . (`div` 10000000) diff --git a/trace-resources/src/Cardano/Logging/Resources/Linux.hs b/trace-resources/src/Cardano/Logging/Resources/Linux.hs deleted file mode 100644 index 7f560905150..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources/Linux.hs +++ /dev/null @@ -1,153 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE RecordWildCards #-} - -module Cardano.Logging.Resources.Linux - ( - readResourceStatsInternal - ) where - -import Cardano.Logging.Resources.Types -import Data.Maybe (fromMaybe) -import qualified Data.Text as T -import qualified Data.Text.IO as T (readFile) -import qualified Data.Text.Read as T (decimal) -import Data.Word -import qualified GHC.Stats as GhcStats -import System.Posix.Files (fileMode, getFileStatus, intersectFileModes, ownerReadMode) - --- * Disk IO stats: --- /proc/[pid]/io (since kernel 2.6.20) --- This file contains I/O statistics for the process, for example: --- --- # cat /proc/3828/io --- rchar: 323934931 --- wchar: 323929600 --- syscr: 632687 --- syscw: 632675 --- read_bytes: 0 --- write_bytes: 323932160 --- cancelled_write_bytes: 0 --- --- The fields are as follows: --- --- rchar: characters read --- The number of bytes which this task has caused to be read from storage. This is simply the sum --- of bytes which this process passed to read(2) and similar system calls. It includes things such --- as terminal I/O and is unaffected by whether or not actual physical disk I/O was required (the --- read might have been satisfied from pagecache). --- --- wchar: characters written --- The number of bytes which this task has caused, or shall cause to be written to disk. Similar --- caveats apply here as with rchar. --- --- syscr: read syscalls --- Attempt to count the number of read I/O operations-that is, system calls such as read(2) and --- pread(2). --- --- syscw: write syscalls --- Attempt to count the number of write I/O operations-that is, system calls such as write(2) and --- pwrite(2). --- --- read_bytes: bytes read --- Attempt to count the number of bytes which this process really did cause to be fetched from the --- storage layer. This is accurate for block-backed filesystems. --- --- write_bytes: bytes written --- Attempt to count the number of bytes which this process caused to be sent to the storage layer. --- --- cancelled_write_bytes: --- The big inaccuracy here is truncate. If a process writes 1MB to a file and then deletes the --- file, it will in fact perform no writeout. But it will have been accounted as having caused 1MB --- of write. In other words: this field represents the number of bytes which this process caused --- to not happen, by truncating pagecache. A task can cause "negative" I/O too. If this task --- truncates some dirty pagecache, some I/O which another task has been accounted for (in its --- write\_bytes) will not be happening. --- --- Note: In the current implementation, things are a bit racy on 32-bit systems: if process A reads --- process B's /proc/[pid]/io while process B is updating one of these 64-bit counters, process A could --- see an intermediate result. --- --- Permission to access this file is governed by a ptrace access mode PTRACE\_MODE\_READ\_FSCREDS check; see --- ptrace(2). --- -readProcBlockInOut :: IO (Word64, Word64) -readProcBlockInOut = do - fields <- readProcList "/proc/self/io" - case -- We're only interested in 'read_bytes' & 'write_bytes': - fmap fromInteger . take 3 . drop 9 $ fields of - [fsRd, _, fsWr] -> pure (fsRd, fsWr) - _ -> pure (0, 0) - --- * Network stats: --- grep IpExt /proc//net/netstat --- IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts InBcastPkts OutBcastPkts InOctets OutOctets InMcastOctets OutMcastOctets InBcastOctets OutBcastOctets InCsumErrors InNoECTPkts InECT1Pkts InECT0Pkts InCEPkts --- IpExt: 0 0 20053 8977 2437 23 3163525943 196480057 2426648 1491754 394285 5523 0 3513269 0 217426 0 --- -readProcNetInOut :: IO (Word64, Word64) -#ifdef WITH_NETSTAT -readProcNetInOut = do - fields <- T.words . fourthLine . T.lines <$> T.readFile "/proc/self/net/netstat" - case -- We're only interested in 'InOctets' & 'OutOctets': - fmap readMaybeText . take 2 . drop 7 $ fields of - [Just netIn, Just netOut] -> pure (netIn, netOut) - _ -> pure (0, 0) - where - -- Assumption: 'IpExt:' values are on the fourth line of how the kernel displays the buffer - fourthLine ls = case drop 3 ls of - l:_ -> l - _ -> T.empty -#else -readProcNetInOut = pure (0, 0) -#endif - --- | TODO we have to expand the |readMemStats| function --- to read full data from |proc| -readResourceStatsInternal :: IO (Maybe ResourceStats) -readResourceStatsInternal = do - rts <- GhcStats.getRTSStats - net <- readProcNetInOut - fs <- readProcBlockInOut - mkProcStats rts net fs . fmap fromIntegral <$> readProcList "/proc/self/stat" - where - mkProcStats :: GhcStats.RTSStats -> (Word64, Word64) -> (Word64, Word64) -> [Word64] -> Maybe ResourceStats - mkProcStats rts - (rNetRd, rNetWr) - (rFsRd, rFsWr) - (_:_:_:_:_:_:_:_:_:_ -- 00-09 - :_:_:_:user:sys:_:_:_:_:rThreads -- 10-19 - :_:_:_:rss:_:_:_:_:_:_ -- 20-29 - :_:_:_:_:_:_:_:_:_:_ -- 30-39 - :_:rCentiBlkIO:_rest) = -- 40-42 - Just $ Resources - { rCentiCpu = user + sys - , rCentiGC = nsToCenti $ GhcStats.gc_cpu_ns rts - , rCentiMut = nsToCenti $ GhcStats.mutator_cpu_ns rts - , rGcsMajor = fromIntegral $ GhcStats.major_gcs rts - , rGcsMinor = fromIntegral $ GhcStats.gcs rts - GhcStats.major_gcs rts - , rAlloc = GhcStats.allocated_bytes rts - , rLive = GhcStats.gcdetails_live_bytes $ GhcStats.gc rts - , rHeap = GhcStats.gcdetails_mem_in_use_bytes $ GhcStats.gc rts - , rRSS = rss * 4096 -- TODO: this is really PAGE_SIZE. - , .. - } - mkProcStats _ _ _ _ = Nothing - nsToCenti :: GhcStats.RtsTime -> Word64 - nsToCenti = floor . (/ (10000000 :: Double)) . fromIntegral - -readProcList :: FilePath -> IO [Integer] -readProcList fp = do - fs <- getFileStatus fp - if readable fs - then do - cs <- T.readFile fp - return $ map (fromMaybe 0 . readMaybeText) (T.words cs) - else - return [] - where - readable fs = intersectFileModes (fileMode fs) ownerReadMode == ownerReadMode - -readMaybeText :: Integral a => T.Text -> Maybe a -readMaybeText t = - case T.decimal t of - Right (v, _) -> Just v - _ -> Nothing diff --git a/trace-resources/src/Cardano/Logging/Resources/Types.hs b/trace-resources/src/Cardano/Logging/Resources/Types.hs deleted file mode 100644 index d11efb634b6..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources/Types.hs +++ /dev/null @@ -1,163 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveFunctor #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE RecordWildCards #-} - -module Cardano.Logging.Resources.Types - ( Resources(..) - , ResourceStats - ) where - - -import Cardano.Logging - -import Data.Aeson -import Data.Text (pack) -import Data.Word -import GHC.Generics (Generic) - --- | Struct for resources used by the process -type ResourceStats = Resources Word64 - --- * HKD for resources used by the process. --- -data Resources a - = Resources - { rCentiCpu :: !a - , rCentiGC :: !a - , rCentiMut :: !a - , rGcsMajor :: !a - , rGcsMinor :: !a - , rAlloc :: !a - , rLive :: !a - , rHeap :: !a - , rRSS :: !a - , rCentiBlkIO :: !a - , rNetRd :: !a - , rNetWr :: !a - , rFsRd :: !a - , rFsWr :: !a - , rThreads :: !a - } - deriving (Functor, Generic, Show) - -instance Applicative Resources where - pure a = Resources a a a a a a a a a a a a a a a - f <*> x = - Resources - { rCentiCpu = rCentiCpu f (rCentiCpu x) - , rCentiGC = rCentiGC f (rCentiGC x) - , rCentiMut = rCentiMut f (rCentiMut x) - , rGcsMajor = rGcsMajor f (rGcsMajor x) - , rGcsMinor = rGcsMinor f (rGcsMinor x) - , rAlloc = rAlloc f (rAlloc x) - , rLive = rLive f (rLive x) - , rHeap = rHeap f (rHeap x) - , rRSS = rRSS f (rRSS x) - , rCentiBlkIO = rCentiBlkIO f (rCentiBlkIO x) - , rNetRd = rNetRd f (rNetRd x) - , rNetWr = rNetWr f (rNetWr x) - , rFsRd = rFsRd f (rFsRd x) - , rFsWr = rFsWr f (rFsWr x) - , rThreads = rThreads f (rThreads x) - } - -instance FromJSON a => FromJSON (Resources a) where - parseJSON = genericParseJSON jsonEncodingOptions - -instance ToJSON a => ToJSON (Resources a) where - toJSON = genericToJSON jsonEncodingOptions - toEncoding = genericToEncoding jsonEncodingOptions - -jsonEncodingOptions :: Options -jsonEncodingOptions = defaultOptions - { fieldLabelModifier = drop 1 - , tagSingleConstructors = True - , sumEncoding = - TaggedObject - { tagFieldName = "kind" - , contentsFieldName = "contents" - } - } - -instance LogFormatting ResourceStats where - forHuman Resources{..} = "Resources:" - <> " Cpu Ticks " <> (pack . show) rCentiCpu - <> ", GC centiseconds " <> (pack . show) rCentiGC - <> ", Mutator centiseconds " <> (pack . show) rCentiMut - <> ", GCs major " <> (pack . show) rGcsMajor - <> ", GCs minor " <> (pack . show) rGcsMinor - <> ", Allocated bytes " <> (pack . show) rAlloc - <>" , GC live bytes " <> (pack . show) rLive - <> ", RTS heap " <> (pack . show) rHeap - <> ", RSS " <> (pack . show) rRSS - <> ", Net bytes read " <> (pack . show) rNetRd - <> " written " <> (pack . show) rNetWr - <> ", FS bytes read " <> (pack . show) rFsRd - <> " written " <> (pack . show) rFsWr - <> ", Threads " <> (pack . show) rThreads - <> "." - - forMachine _dtal rs = mconcat - [ "kind" .= String "ResourceStats" - , "CentiCpu" .= Number (fromIntegral $ rCentiCpu rs) - , "CentiGC" .= Number (fromIntegral $ rCentiGC rs) - , "CentiMut" .= Number (fromIntegral $ rCentiMut rs) - , "GcsMajor" .= Number (fromIntegral $ rGcsMajor rs) - , "GcsMinor" .= Number (fromIntegral $ rGcsMinor rs) - , "Alloc" .= Number (fromIntegral $ rAlloc rs) - , "Live" .= Number (fromIntegral $ rLive rs) - , "Heap" .= Number (fromIntegral $ rHeap rs) - , "RSS" .= Number (fromIntegral $ rRSS rs) - , "CentiBlkIO" .= Number (fromIntegral $ rCentiBlkIO rs) - , "NetRd" .= Number (fromIntegral $ rNetRd rs) - , "NetWr" .= Number (fromIntegral $ rNetWr rs) - , "FsRd" .= Number (fromIntegral $ rFsRd rs) - , "FsWr" .= Number (fromIntegral $ rFsWr rs) - , "Threads" .= Number (fromIntegral $ rThreads rs) - ] - - asMetrics rs = - [ IntM "Stat.cputicks" (fromIntegral $ rCentiCpu rs) - , IntM "RTS.gcticks" (fromIntegral $ rCentiGC rs) - , IntM "RTS.mutticks" (fromIntegral $ rCentiMut rs) - , IntM "RTS.gcMajorNum" (fromIntegral $ rGcsMajor rs) - , IntM "RTS.gcMinorNum" (fromIntegral $ rGcsMinor rs) - , IntM "RTS.alloc" (fromIntegral $ rAlloc rs) - , IntM "RTS.gcLiveBytes" (fromIntegral $ rLive rs) - , IntM "RTS.gcHeapBytes" (fromIntegral $ rHeap rs) - , IntM "Mem.resident" (fromIntegral $ rRSS rs) - , IntM "Stat.blkIOticks" (fromIntegral $ rCentiBlkIO rs) - , IntM "Stat.netRd" (fromIntegral $ rNetRd rs) - , IntM "Stat.netWr" (fromIntegral $ rNetWr rs) - , IntM "Stat.fsRd" (fromIntegral $ rFsRd rs) - , IntM "Stat.fsWr" (fromIntegral $ rFsWr rs) - , IntM "RTS.threads" (fromIntegral $ rThreads rs) - ] - -instance MetaTrace ResourceStats where - namespaceFor Resources {} = - Namespace [] ["Resources"] - severityFor (Namespace _ ["Resources"]) _ = Just Info - severityFor _ns _ = Nothing - documentFor (Namespace _ ["Resources"]) = Just "" - documentFor _ns = Nothing - metricsDocFor (Namespace _ ["Resources"]) = - [("Stat.cputicks", "Kernel-reported CPU ticks (1/100th of a second), since process start") - ,("RTS.gcticks", "RTS-reported CPU ticks spent on GC") - ,("RTS.mutticks", "RTS-reported CPU ticks spent on mutator") - ,("RTS.gcMajorNum", "Major GCs") - ,("RTS.gcMinorNum", "Minor GCs") - ,("RTS.alloc", "RTS-reported bytes allocated") - ,("RTS.gcLiveBytes", "RTS-reported live bytes") - ,("RTS.gcHeapBytes", "RTS-reported heap bytes") - ,("Mem.resident", "Kernel-reported RSS (resident set size)") - ,("Stat.netRd", "IP packet bytes read") - ,("Stat.netWr", "IP packet bytes written") - ,("Stat.fsRd", "FS bytes read") - ,("Stat.fsWr", "FS bytes written") - ,("RTS.threads","RTS green thread count")] - metricsDocFor _ns = [] - allNamespaces = [ Namespace [] ["Resources"]] - diff --git a/trace-resources/src/Cardano/Logging/Resources/Windows.hsc b/trace-resources/src/Cardano/Logging/Resources/Windows.hsc deleted file mode 100644 index df8ddac9e40..00000000000 --- a/trace-resources/src/Cardano/Logging/Resources/Windows.hsc +++ /dev/null @@ -1,179 +0,0 @@ - -{-# LANGUAGE CPP #-} -{-# LANGUAGE ForeignFunctionInterface #-} -{-# LANGUAGE TypeApplications #-} - -module Cardano.Logging.Resources.Windows - ( readResourceStatsInternal - ) where - - -import Data.Word (Word64) -import Foreign.C.Types -import Foreign.Marshal.Alloc -import Foreign.Marshal.Error -import Foreign.Ptr -import Foreign.Storable -import qualified GHC.Stats as GhcStats -import System.Win32.Process (ProcessId, getCurrentProcessId) -import System.Win32.Types - -import Cardano.Logging.Resources.Types - - --- use PsAPI version 2 -#define PSAPI_VERSION 2 - -#include -#include - -#include "os-support-win.h" - - -{- type aliases -} -type ULONGLONG = Word64 - -{- memory information -} - -{- https://docs.microsoft.com/de-de/windows/win32/api/psapi/ns-psapi-process_memory_counters -typedef struct _PROCESS_MEMORY_COUNTERS { - DWORD cb; - DWORD PageFaultCount; - SIZE_T PeakWorkingSetSize; - SIZE_T WorkingSetSize; - SIZE_T QuotaPeakPagedPoolUsage; - SIZE_T QuotaPagedPoolUsage; - SIZE_T QuotaPeakNonPagedPoolUsage; - SIZE_T QuotaNonPagedPoolUsage; - SIZE_T PagefileUsage; - SIZE_T PeakPagefileUsage; -} PROCESS_MEMORY_COUNTERS; -} - -data ProcessMemoryCounters = ProcessMemoryCounters - { _cb :: DWORD - , _pageFaultCount :: DWORD - , _peakWorkingSetSize :: SIZE_T - , _workingSetSize :: SIZE_T - , _quotaPeakPagedPoolUsage :: SIZE_T - , _quotaPagedPoolUsage :: SIZE_T - , _quotaPeakNonPagedPoolUsage :: SIZE_T - , _quotaNonPagedPoolUsage :: SIZE_T - , _pagefileUsage :: SIZE_T - , _peakPagefileUsage :: SIZE_T - } - -instance Storable ProcessMemoryCounters where - alignment _ = #const offsetof(struct {char x__; PROCESS_MEMORY_COUNTERS (y__); }, y__) - sizeOf _ = #size PROCESS_MEMORY_COUNTERS - peek ptr = ProcessMemoryCounters - <$> (#peek PROCESS_MEMORY_COUNTERS, cb) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, PageFaultCount) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, PeakWorkingSetSize) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, WorkingSetSize) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, QuotaPeakPagedPoolUsage) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, QuotaPagedPoolUsage) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, QuotaPeakNonPagedPoolUsage) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, QuotaNonPagedPoolUsage) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, PagefileUsage) ptr - <*> (#peek PROCESS_MEMORY_COUNTERS, PeakPagefileUsage) ptr - poke _ _ = pure () - -foreign import ccall unsafe c_get_process_memory_info2 :: Ptr ProcessMemoryCounters -> CInt -> IO CInt - -{- I/O counters -} -{- https://docs.microsoft.com/de-de/windows/win32/api/winnt/ns-winnt-io_counters -typedef struct _IO_COUNTERS { - ULONGLONG ReadOperationCount; - ULONGLONG WriteOperationCount; - ULONGLONG OtherOperationCount; - ULONGLONG ReadTransferCount; - ULONGLONG WriteTransferCount; - ULONGLONG OtherTransferCount; -} IO_COUNTERS; -} - -data IOCounters = IOCounters - { _readOperationCount :: ULONGLONG - , _writeOperationCount :: ULONGLONG - , _otherOperationCount :: ULONGLONG - , _readTransferCount :: ULONGLONG - , _writeTransferCount :: ULONGLONG - , _otherTransferCount :: ULONGLONG - } - -instance Storable IOCounters where - alignment _ = #const offsetof(struct {char x__; IO_COUNTERS (y__); }, y__) - sizeOf _ = #size IO_COUNTERS - peek ptr = IOCounters - <$> (#peek IO_COUNTERS, ReadOperationCount) ptr - <*> (#peek IO_COUNTERS, WriteOperationCount) ptr - <*> (#peek IO_COUNTERS, OtherOperationCount) ptr - <*> (#peek IO_COUNTERS, ReadTransferCount) ptr - <*> (#peek IO_COUNTERS, WriteTransferCount) ptr - <*> (#peek IO_COUNTERS, OtherTransferCount) ptr - poke _ _ = pure () - -data CpuTimes = CpuTimes { - usertime :: ULONGLONG - , systime :: ULONGLONG - , _idletime :: ULONGLONG - } - -instance Storable CpuTimes where - alignment _ = #const offsetof(struct {char x__; CPU_TIMES (y__); }, y__) - sizeOf _ = #size CPU_TIMES - peek ptr = CpuTimes - <$> (#peek CPU_TIMES, usertime) ptr - <*> (#peek CPU_TIMES, systime) ptr - <*> (#peek CPU_TIMES, idletime) ptr - poke _ _ = pure () - -foreign import ccall unsafe c_get_proc_cpu_times2 :: Ptr CpuTimes -> CInt -> IO CInt - - -getMemoryInfo :: ProcessId -> IO ProcessMemoryCounters -getMemoryInfo pid = - allocaBytes 128 $ \ptr -> do - throwIfNeg_ (\res -> "c_get_process_memory_info2: failure returned: " ++ show res) - (c_get_process_memory_info2 ptr (fromIntegral pid)) - peek ptr - -readResourceStatsInternal :: IO (Maybe ResourceStats) -readResourceStatsInternal = getCurrentProcessId >>= \pid -> do - cpu <- getCpuTimes pid - mem <- getMemoryInfo pid - rts <- GhcStats.getRTSStats - pure . Just $ - Resources - { rCentiCpu = usecsToCenti $ usertime cpu + systime cpu - , rCentiGC = nsToCenti $ GhcStats.gc_cpu_ns rts - , rCentiMut = nsToCenti $ GhcStats.mutator_cpu_ns rts - , rGcsMajor = fromIntegral $ GhcStats.major_gcs rts - , rGcsMinor = fromIntegral $ GhcStats.gcs rts - GhcStats.major_gcs rts - , rAlloc = GhcStats.allocated_bytes rts - , rLive = GhcStats.gcdetails_live_bytes $ GhcStats.gc rts - , rHeap = GhcStats.gcdetails_mem_in_use_bytes $ GhcStats.gc rts - , rRSS = fromIntegral (_workingSetSize mem) - , rCentiBlkIO = 0 - , rNetRd = 0 - , rNetWr = 0 - , rFsRd = 0 - , rFsWr = 0 - , rThreads = 0 - } - where - usecsToCenti :: ULONGLONG -> Word64 - usecsToCenti ul = ul `div` 10000 - nsToCenti :: GhcStats.RtsTime -> Word64 - nsToCenti = fromIntegral . (`div` 10000000) - - -getCpuTimes :: ProcessId -> IO CpuTimes -getCpuTimes pid = - allocaBytes 128 $ \ptr -> do - res <- c_get_proc_cpu_times2 ptr (fromIntegral pid) - if res <= 0 - then do - putStrLn $ "c_get_proc_cpu_times2: failure returned: " ++ (show res) - return $ CpuTimes 0 0 0 - else - peek ptr diff --git a/trace-resources/test/trace-resources-test.hs b/trace-resources/test/trace-resources-test.hs deleted file mode 100644 index 7e9c7caaa24..00000000000 --- a/trace-resources/test/trace-resources-test.hs +++ /dev/null @@ -1,59 +0,0 @@ -{-# OPTIONS_GHC -Wno-unused-imports #-} - -import Cardano.Logging -import Cardano.Logging.Resources -import Cardano.Logging.Resources.Types - -import Control.Monad.IO.Class -import Data.IORef - -import Test.Tasty -import Test.Tasty.QuickCheck - - -main :: IO () -main = defaultMain tests - -tests :: TestTree -tests = localOption (QuickCheckTests 10) $ testGroup "trace-resources" - [ testProperty "resources available" playScript - ] - --- | Plays a script in a single thread -playScript :: Property -playScript = ioProperty $ do - stdoutTrRef <- newIORef [] - stdoutTracer' <- testTracer stdoutTrRef - forwardTrRef <- newIORef [] - forwardTracer' <- testTracer forwardTrRef - ekgTrRef <- newIORef [] - ekgTracer' <- testTracer ekgTrRef - tr <- mkCardanoTracer - stdoutTracer' - forwardTracer' - (Just ekgTracer') - ["Test"] - confState <- emptyConfigReflection - configureTracers confState emptyTraceConfig [tr] - traceIt tr 10 - -traceIt :: Trace IO ResourceStats -> Int -> IO Bool -traceIt _ 0 = pure True -traceIt tr n = do - mbResources <- readResourceStats - case mbResources of - Nothing -> pure False - Just res -> do - traceWith tr res - traceIt tr (n - 1) - - -testTracer :: MonadIO m - => IORef [FormattedMessage] - -> m (Trace m FormattedMessage) -testTracer ioRef = liftIO $ do - pure $ Trace $ arrow $ emit output' - where - output' (LoggingContext{}, Right msg) = liftIO $ do - modifyIORef ioRef (msg :) - output' (LoggingContext{}, _) = pure () diff --git a/trace-resources/trace-resources.cabal b/trace-resources/trace-resources.cabal deleted file mode 100644 index d83294cee2b..00000000000 --- a/trace-resources/trace-resources.cabal +++ /dev/null @@ -1,109 +0,0 @@ -cabal-version: 3.0 - -name: trace-resources -version: 0.2.4 -synopsis: Package for tracing resources for linux, mac and windows -description: Package for tracing resources for linux, mac and windows. -category: Cardano, - Trace, -copyright: 2021-2023 Input Output Global Inc (IOG), 2023-2026 Intersect. -author: Juergen Nicklisch-Franken -maintainer: operations@iohk.io -license: Apache-2.0 -license-files: LICENSE - NOTICE -extra-source-files: include/os-support-darwin.h - include/os-support-win.h -extra-doc-files: CHANGELOG.md - README.md - -Flag with-netstat - Description: Enable netstat values in Linux resource traces (potentially expensive) - Manual: True - Default: False - -common project-config - default-language: Haskell2010 - -library - import: project-config - hs-source-dirs: src - exposed-modules: Cardano.Logging.Resources - Cardano.Logging.Resources.Types - Cardano.Logging.Resources.Dummy - - default-extensions: OverloadedStrings - CPP - build-depends: base >=4.12 && <5 - , trace-dispatcher - , text - , aeson >= 2.1.0.0 - - if os(windows) - build-depends: Win32 - else - build-depends: unix - - ghc-options: -Wall - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints - -Wmissing-export-lists - -Wno-incomplete-patterns - - if flag(with-netstat) - CPP-options: -DWITH_NETSTAT - - if os(linux) - exposed-modules: Cardano.Logging.Resources.Linux - if os(windows) - exposed-modules: Cardano.Logging.Resources.Windows - c-sources: cbits/os-support-win.c - include-dirs: include/ - cc-options: -DPSAPI_VERSION=2 - if os(darwin) - exposed-modules: Cardano.Logging.Resources.Darwin - c-sources: cbits/os-support-darwin.c - include-dirs: include/ - -test-suite trace-resources-test - import: project-config - type: exitcode-stdio-1.0 - hs-source-dirs: test - main-is: trace-resources-test.hs - default-extensions: OverloadedStrings - build-depends: base >=4.12 && <5 - , trace-dispatcher - , text - , aeson - , QuickCheck - , tasty - , tasty-quickcheck - , trace-resources - ghc-options: "-with-rtsopts=-T" - -Wall - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints - -Wmissing-export-lists - -Wno-incomplete-patterns - -benchmark bench - import: project-config - type: exitcode-stdio-1.0 - main-is: trace-resources-bench.hs - hs-source-dirs: bench - build-depends: base >=4.12 && <5 - , criterion - , trace-resources - ghc-options: - -Wall -Wcompat -Wincomplete-record-updates - -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints - -Wunused-packages -threaded -rtsopts -O2 - "-with-rtsopts=-T" From 8baaa373ade4316e1b62225a555d7de70568124a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Nicklisch-Franken?= Date: Tue, 16 Jun 2026 19:32:58 +0200 Subject: [PATCH 2/2] Cabal and nix stuff --- cabal.project | 14 ++++++-------- flake.lock | 18 ++++++++++++++++++ flake.nix | 1 + nix/haskell.nix | 9 +++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/cabal.project b/cabal.project index 650531a91a1..5427082f425 100644 --- a/cabal.project +++ b/cabal.project @@ -86,11 +86,9 @@ allow-newer: -- Do NOT add more source-repository-package stanzas here unless they are strictly -- temporary! Please read the section in CONTRIBUTING about updating dependencies. --- Temporary: hermod-trace-resources is pending publication to CHaP. --- Update the tag to the hermod-tracing commit that includes hermod-trace-resources, --- then remove this stanza once the package is available in CHaP. -source-repository-package - type: git - location: https://github.com/IntersectMBO/hermod-tracing - tag: f94edf21d7df01f43e115e370f0a48fd00240003 - subdir: hermod-trace-resources +-- hermod-trace-resources is pending publication to CHaP. +-- Nix builds resolve it via the flake inputMap (see nix/haskell.nix + flake.nix). +-- For local cabal builds, add the following to your cabal.project.local: +-- +-- packages: +-- ../hermod-tracing/hermod-trace-resources diff --git a/flake.lock b/flake.lock index 07c24c46639..16b9c79d868 100644 --- a/flake.lock +++ b/flake.lock @@ -340,6 +340,23 @@ "type": "github" } }, + "hermod-tracing": { + "flake": false, + "locked": { + "lastModified": 1781620227, + "narHash": "sha256-KD9zDu81xIXYe0Bd5rJgVWS63YS3GbJw71CHjs+EH9Q=", + "owner": "IntersectMBO", + "repo": "hermod-tracing", + "rev": "f94edf21d7df01f43e115e370f0a48fd00240003", + "type": "github" + }, + "original": { + "owner": "IntersectMBO", + "ref": "without_contra_included", + "repo": "hermod-tracing", + "type": "github" + } + }, "hls": { "flake": false, "locked": { @@ -771,6 +788,7 @@ "flake-compat": "flake-compat", "hackageNix": "hackageNix_2", "haskellNix": "haskellNix", + "hermod-tracing": "hermod-tracing", "incl": "incl", "iohkNix": "iohkNix", "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 1d2afd3395e..fb77be484f3 100644 --- a/flake.nix +++ b/flake.nix @@ -65,6 +65,7 @@ outputs = { cardano-automation, CHaP, + hermod-tracing, haskellNix, incl, iohkNix, diff --git a/nix/haskell.nix b/nix/haskell.nix index 2bce0b63059..19646be6f65 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -32,6 +32,15 @@ let secure: True active-repositories: hackage.haskell.org, cardano-haskell-packages-local allow-newer: terminfo:base + + -- hermod-trace-resources is pending publication to CHaP. + -- Resolved via the hermod-tracing flake input (see inputMap below). + -- Remove once the package is available in CHaP. + source-repository-package + type: git + location: https://github.com/IntersectMBO/hermod-tracing + tag: f94edf21d7df01f43e115e370f0a48fd00240003 + subdir: hermod-trace-resources '' + lib.optionalString pkgs.stdenv.hostPlatform.isWindows '' -- When cross compiling we don't have a `ghc` package package plutus-tx-plugin