size: Get the item's size from the daemon rather than compute it.
This removes all I/O, which obviously makes things faster. * guix/scripts/size.scm (file-size, store-item-exists?): Remove. (query-path-info*): New procedure. (file-size*): Rename to... (file-size): ... this; adjust caller. Use 'query-path-info*' instead of 'file-size'.
This commit is contained in:
parent
40a7d4e58b
commit
83bde59fb3
@ -29,7 +29,6 @@
|
|||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
#:use-module (srfi srfi-34)
|
#:use-module (srfi srfi-34)
|
||||||
#:use-module (srfi srfi-37)
|
#:use-module (srfi srfi-37)
|
||||||
#:use-module (ice-9 ftw)
|
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 format)
|
#:use-module (ice-9 format)
|
||||||
#:export (profile?
|
#:export (profile?
|
||||||
@ -48,42 +47,24 @@
|
|||||||
(self-size profile-self-size) ;size in bytes
|
(self-size profile-self-size) ;size in bytes
|
||||||
(closure-size profile-closure-size)) ;size of dependencies in bytes
|
(closure-size profile-closure-size)) ;size of dependencies in bytes
|
||||||
|
|
||||||
(define (file-size file)
|
|
||||||
"Return the size of bytes of FILE, entering it if FILE is a directory."
|
|
||||||
(file-system-fold (const #t)
|
|
||||||
(lambda (file stat result) ;leaf
|
|
||||||
(+ (stat:size stat) result))
|
|
||||||
(lambda (directory stat result) ;down
|
|
||||||
(+ (stat:size stat) result))
|
|
||||||
(lambda (directory stat result) ;up
|
|
||||||
result)
|
|
||||||
(lambda (file stat result) ;skip
|
|
||||||
result)
|
|
||||||
(lambda (file stat errno result)
|
|
||||||
(format (current-error-port)
|
|
||||||
"file-size: ~a: ~a~%" file
|
|
||||||
(strerror errno))
|
|
||||||
result)
|
|
||||||
0
|
|
||||||
file
|
|
||||||
lstat))
|
|
||||||
|
|
||||||
(define substitutable-path-info*
|
(define substitutable-path-info*
|
||||||
(store-lift substitutable-path-info))
|
(store-lift substitutable-path-info))
|
||||||
|
|
||||||
(define (store-item-exists? item)
|
(define (query-path-info* item)
|
||||||
"Return #t if ITEM is in the store, and protect it from GC. Otherwise
|
"Monadic version of 'query-path-info' that returns #f when ITEM is not in
|
||||||
return #f."
|
the store."
|
||||||
(lambda (store)
|
(lambda (store)
|
||||||
(add-temp-root store item)
|
(guard (c ((nix-protocol-error? c)
|
||||||
(values (valid-path? store item) store)))
|
;; ITEM is not in the store; return #f.
|
||||||
|
(values #f store)))
|
||||||
|
(values (query-path-info store item) store))))
|
||||||
|
|
||||||
(define (file-size* item)
|
(define (file-size item)
|
||||||
"Like 'file-size', but resort to information from substitutes if ITEM is not
|
"Return the size in bytes of ITEM, resorting to information from substitutes
|
||||||
in the store."
|
if ITEM is not in the store."
|
||||||
(mlet %store-monad ((exists? (store-item-exists? item)))
|
(mlet %store-monad ((info (query-path-info* item)))
|
||||||
(if exists?
|
(if info
|
||||||
(return (file-size item))
|
(return (path-info-nar-size info))
|
||||||
(mlet %store-monad ((info (substitutable-path-info* (list item))))
|
(mlet %store-monad ((info (substitutable-path-info* (list item))))
|
||||||
(match info
|
(match info
|
||||||
((info)
|
((info)
|
||||||
@ -149,7 +130,7 @@ profile of ITEM and its requisites."
|
|||||||
(cons item refs))))))
|
(cons item refs))))))
|
||||||
(sizes (mapm %store-monad
|
(sizes (mapm %store-monad
|
||||||
(lambda (item)
|
(lambda (item)
|
||||||
(>>= (file-size* item)
|
(>>= (file-size item)
|
||||||
(lambda (size)
|
(lambda (size)
|
||||||
(return (cons item size)))))
|
(return (cons item size)))))
|
||||||
refs)))
|
refs)))
|
||||||
|
Loading…
Reference in New Issue
Block a user