Esempio n. 1
0
func (self *TerminalOutputter) Output(diff command.Diff) error {

	tableRows := diff.ToRows()

	// get the length of the longest row (the one with the most fields)
	longestRow := 0
	for _, row := range tableRows {
		longestRow = util.MaxInt(longestRow, len(row))
	}

	// bookkeep the length of the longest member of each column
	longestFields := make([]int, longestRow)
	for _, row := range tableRows {
		for idx, field := range row {
			longestFields[idx] = util.MaxInt(longestFields[idx], len(field))
		}
	}

	// write out each row
	for _, row := range tableRows {
		for idx, rowEl := range row {
			fmt.Printf("\t\t%v%v", strings.Repeat(" ",
				longestFields[idx]-len(rowEl)), rowEl)
		}
		fmt.Printf("\n")
	}
	fmt.Printf("\n")

	return nil

}
Esempio n. 2
0
// DumpIntents iterates through the previously-created intents and
// dumps all of the found collections.
func (dump *MongoDump) DumpIntents() error {
	resultChan := make(chan error)

	var jobs int
	if dump.ToolOptions != nil && dump.ToolOptions.HiddenOptions != nil {
		jobs = dump.ToolOptions.HiddenOptions.MaxProcs
	}
	jobs = util.MaxInt(jobs, 1)
	if jobs > 1 {
		dump.manager.Finalize(intents.LongestTaskFirst)
	} else {
		dump.manager.Finalize(intents.Legacy)
	}

	log.Logf(log.Info, "dumping with %v job threads", jobs)

	// start a goroutine for each job thread
	for i := 0; i < jobs; i++ {
		go func(id int) {
			log.Logf(log.DebugHigh, "starting dump routine with id=%v", id)
			for {
				intent := dump.manager.Pop()
				if intent == nil {
					log.Logf(log.DebugHigh, "ending dump routine with id=%v, no more work to do", id)
					resultChan <- nil
					return
				}
				err := dump.DumpIntent(intent)
				if err != nil {
					resultChan <- err
					return
				}
				dump.manager.Finish(intent)
			}
		}(i)
	}

	// wait until all goroutines are done or one of them errors out
	for i := 0; i < jobs; i++ {
		if err := <-resultChan; err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 3
0
// Implement the Diff interface.  Serializes the lock totals into rows by
// namespace.
func (self *ServerStatusDiff) ToRows() [][]string {
	// to return
	rows := [][]string{}

	// the header row
	headerRow := []string{"db", "total", "read", "write"}
	rows = append(rows, headerRow)

	// create the rows for the individual namespaces
	for ns, nsTotals := range self.Totals {

		nsRow := []string{ns}
		for _, total := range nsTotals {
			nsRow = append(nsRow, strconv.Itoa(util.MaxInt(0, total/1000))+"ms")
		}
		rows = append(rows, nsRow)

	}

	return rows
}
Esempio n. 4
0
// Implement the Diff interface. Serializes the information about the time
// spent in locks into rows to be printed.
func (self *TopDiff) ToRows() [][]string {
	// to return
	rows := [][]string{}

	// the header row
	headerRow := []string{"ns", "total", "read", "write",
		time.Now().Format("2006-01-02T15:04:05")}
	rows = append(rows, headerRow)

	// sort the namespaces
	nsSorted := []string{}
	for ns := range self.Totals {
		nsSorted = append(nsSorted, ns)
	}
	sort.Strings(nsSorted)

	// create the rows for the individual namespaces, iterating in sorted
	// order
	for _, ns := range nsSorted {

		nsTotals := self.Totals[ns]

		// some namespaces are skipped
		if skipNamespace(ns) {
			continue
		}

		nsRow := []string{ns}
		for _, total := range nsTotals {
			nsRow = append(nsRow, strconv.Itoa(util.MaxInt(0, total/1000))+"ms")
		}
		rows = append(rows, nsRow)
	}

	return rows
}