Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dune cache trim: also print number of files removed #9216

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
dune cache trim: also print number of files removed
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
  • Loading branch information
nojb committed Nov 17, 2023
commit 8d54611555372744fa4a1bfcaf7b8ddd9bdc181a
9 changes: 7 additions & 2 deletions bin/cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ let trim =
Dune_cache.Trimmer.trim ~goal
with
| Error s -> User_error.raise [ Pp.text s ]
| Ok { trimmed_bytes } ->
| Ok { trimmed_bytes; number_of_files_removed } ->
User_message.print
(User_message.make [ Pp.textf "Freed %s" (Bytes_unit.pp trimmed_bytes) ])
(User_message.make
[ Pp.textf
"Freed %s (%d files removed)"
(Bytes_unit.pp trimmed_bytes)
number_of_files_removed
])
;;

let size =
Expand Down
11 changes: 8 additions & 3 deletions src/dune_cache/trimmer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ open Stdune
open Dune_cache_storage

module Trimming_result = struct
type t = { trimmed_bytes : int64 }
type t =
{ trimmed_bytes : int64
; number_of_files_removed : int
}

let empty = { trimmed_bytes = 0L }
let empty = { trimmed_bytes = 0L; number_of_files_removed = 0 }

(* CR-someday amokhov: Right now Dune doesn't support large (>1Gb) files on
32-bit platforms due to the pervasive use of [int] for representing
individual file sizes. It's not fundamentally difficult to switch to
[int64], so we should do it if it becomes a real issue. *)
let add t ~(bytes : int) =
{ trimmed_bytes = Int64.add t.trimmed_bytes (Int64.of_int bytes) }
{ trimmed_bytes = Int64.add t.trimmed_bytes (Int64.of_int bytes)
; number_of_files_removed = t.number_of_files_removed + 1
}
;;
end

Expand Down
5 changes: 4 additions & 1 deletion src/dune_cache/trimmer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from Jenga's trimmer. *)

module Trimming_result : sig
type t = { trimmed_bytes : int64 }
type t =
{ trimmed_bytes : int64
; number_of_files_removed : int
}
end

(** Trim the cache by removing a set of unused files so that the total freed
Expand Down