github.com/boki/go-xmp@v1.0.1/xmp/dump.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package xmp
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  )
    21  
    22  func (n Node) Dump(d int) {
    23  	pfx := strings.Repeat(">", d)
    24  	if len(pfx) > 0 {
    25  		pfx += " "
    26  	}
    27  	if n.Model != nil {
    28  		fmt.Printf("%sNODE MODEL %s (%d attr, %d children)\n", pfx, n.XMLName.Local, len(n.Attr), len(n.Nodes))
    29  	} else {
    30  		fmt.Printf("%sNODE EXT  %s (%d attr, %d children)\n", pfx, n.XMLName.Local, len(n.Attr), len(n.Nodes))
    31  	}
    32  	for i, v := range n.Attr {
    33  		fmt.Printf("%s ATTR %2d %s := %s\n", pfx, i, v.Name.Local, v.Value)
    34  	}
    35  	for i, v := range n.Nodes {
    36  		fmt.Printf("%d ", i)
    37  		v.Dump(d + 1)
    38  	}
    39  }
    40  
    41  func (d *Document) Dump() {
    42  	d.DumpNamespaces()
    43  	p, _ := d.ListPaths()
    44  	for _, v := range p {
    45  		fmt.Printf("%s = %s\n", v.Path.String(), v.Value)
    46  	}
    47  	// for _, v := range d.Nodes {
    48  	// 	v.Dump(0)
    49  	// }
    50  }
    51  
    52  func (d *Document) DumpNamespaces() {
    53  	for n, v := range d.intNsMap {
    54  		fmt.Printf("NS INT %s %+v\n", n, v)
    55  	}
    56  	for n, v := range d.extNsMap {
    57  		fmt.Printf("NS EXT %s %+v\n", n, v)
    58  	}
    59  }
    60  
    61  func DumpStats() {
    62  	fmt.Println("xmp: Node Pool Allocs ", npAllocs)
    63  	fmt.Println("xmp: Node Pool Frees  ", npFrees)
    64  	fmt.Println("xmp: Node Pool Hits   ", npHits)
    65  	fmt.Println("xmp: Node Pool Returns", npReturns)
    66  	fmt.Println("xmp: Node Pool InUse  ", npAllocs+npHits-npReturns-npFrees)
    67  	fmt.Println("xmp: Node Pool InPool ", Max64(0, npReturns-npHits))
    68  }