show layer efficiency in layerview
This commit is contained in:
parent
1b5adfd447
commit
7f3dee181c
@ -123,7 +123,25 @@ func (node *FileNode) MetadataString() string {
|
||||
user := node.Data.FileInfo.TarHeader.Uid
|
||||
group := node.Data.FileInfo.TarHeader.Gid
|
||||
userGroup := fmt.Sprintf("%d:%d", user, group)
|
||||
size := humanize.Bytes(uint64(node.Data.FileInfo.TarHeader.FileInfo().Size()))
|
||||
|
||||
//size := humanize.Bytes(uint64(node.Data.FileInfo.TarHeader.FileInfo().Size()))
|
||||
var sizeBytes int64
|
||||
|
||||
if node.Data.FileInfo.TarHeader.FileInfo().IsDir() {
|
||||
|
||||
sizer := func(curNode *FileNode) error {
|
||||
if curNode.Data.DiffType != Removed {
|
||||
sizeBytes += curNode.Data.FileInfo.TarHeader.FileInfo().Size()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
node.VisitDepthChildFirst(sizer, nil)
|
||||
} else {
|
||||
sizeBytes = node.Data.FileInfo.TarHeader.FileInfo().Size()
|
||||
}
|
||||
|
||||
size := humanize.Bytes(uint64(sizeBytes))
|
||||
|
||||
return style.Sprint(fmt.Sprintf(AttributeFormat, dir, fileMode, userGroup, size))
|
||||
}
|
||||
|
@ -149,7 +149,6 @@ func (tree *FileTree) GetNode(path string) (*FileNode, error) {
|
||||
}
|
||||
|
||||
func (tree *FileTree) AddPath(path string, data FileInfo) (*FileNode, error) {
|
||||
// fmt.Printf("ADDPATH: %s %+v\n", path, data)
|
||||
nodeNames := strings.Split(strings.Trim(path, "/"), "/")
|
||||
node := tree.Root
|
||||
for idx, name := range nodeNames {
|
||||
@ -193,14 +192,12 @@ func (tree *FileTree) Compare(upper *FileTree) error {
|
||||
lowerNode, _ := tree.GetNode(upperNode.Path())
|
||||
if lowerNode == nil {
|
||||
newNode, err := tree.AddPath(upperNode.Path(), upperNode.Data.FileInfo)
|
||||
// fmt.Printf("added new upperNode at %s\n", newNode.Path())
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot add new upperNode %s: %v", upperNode.Path(), err.Error())
|
||||
}
|
||||
newNode.AssignDiffType(Added)
|
||||
} else {
|
||||
diffType := lowerNode.compare(upperNode)
|
||||
// fmt.Printf("found existing upperNode at %s\n", lowerNode.Path())
|
||||
return lowerNode.deriveDiffType(diffType)
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,11 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/wagoodman/docker-image-explorer/filetree"
|
||||
"golang.org/x/net/context"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
LayerFormat = "%-25s %7s %s"
|
||||
LayerFormat = "%-25s %5s %7s %s"
|
||||
)
|
||||
|
||||
func check(e error) {
|
||||
@ -51,8 +52,11 @@ func NewManifest(reader *tar.Reader, header *tar.Header) ImageManifest {
|
||||
}
|
||||
|
||||
type Layer struct {
|
||||
TarPath string
|
||||
History types.ImageHistory
|
||||
TarPath string
|
||||
History types.ImageHistory
|
||||
Index int
|
||||
Tree *filetree.FileTree
|
||||
RefTrees []*filetree.FileTree
|
||||
}
|
||||
|
||||
func (layer *Layer) Id() string {
|
||||
@ -69,7 +73,12 @@ func (layer *Layer) Id() string {
|
||||
|
||||
func (layer *Layer) String() string {
|
||||
|
||||
return fmt.Sprintf(LayerFormat, layer.Id(), humanize.Bytes(uint64(layer.History.Size)), strings.TrimPrefix(layer.History.CreatedBy, "/bin/sh -c "))
|
||||
return fmt.Sprintf(LayerFormat,
|
||||
layer.Id(),
|
||||
strconv.Itoa(int(100.0*filetree.EfficiencyScore(layer.RefTrees[:layer.Index+1]))) + "%",
|
||||
//"100%",
|
||||
humanize.Bytes(uint64(layer.History.Size)),
|
||||
strings.TrimPrefix(layer.History.CreatedBy, "/bin/sh -c "))
|
||||
}
|
||||
|
||||
func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
|
||||
@ -144,6 +153,9 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
|
||||
for idx := 0; idx < len(layers); idx++ {
|
||||
layers[idx] = new(Layer)
|
||||
layers[idx].History = history[idx]
|
||||
layers[idx].Index = idx
|
||||
layers[idx].Tree = trees[idx]
|
||||
layers[idx].RefTrees = trees
|
||||
if len(manifest.LayerTarPaths) > idx {
|
||||
layers[idx].TarPath = manifest.LayerTarPaths[idx]
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ func (view *FileTreeView) Update() error {
|
||||
}
|
||||
return nil
|
||||
}, nil)
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
|
||||
func (view *FileTreeView) KeyHelp() string {
|
||||
|
@ -133,7 +133,7 @@ func (view *LayerView) Update() error {
|
||||
func (view *LayerView) Render() error {
|
||||
view.gui.Update(func(g *gocui.Gui) error {
|
||||
// update header
|
||||
headerStr := fmt.Sprintf("Cmp "+image.LayerFormat, "Image ID", "Size", "Filter")
|
||||
headerStr := fmt.Sprintf("Cmp "+image.LayerFormat, "Image ID", "%Eff.", "Size", "Filter")
|
||||
fmt.Fprintln(view.header, Formatting.Header(vtclean.Clean(headerStr, false)))
|
||||
|
||||
// update contents
|
||||
@ -145,7 +145,7 @@ func (view *LayerView) Render() error {
|
||||
layerStr := layer.String()
|
||||
if idx == 0 {
|
||||
// TODO: add size
|
||||
layerStr = fmt.Sprintf(image.LayerFormat, layer.History.ID[0:25], "", "FROM "+layer.Id())
|
||||
layerStr = fmt.Sprintf(image.LayerFormat, layer.History.ID[0:25], "", "", "FROM "+layer.Id())
|
||||
}
|
||||
|
||||
compareBar := view.renderCompareBar(idx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user