func close(connections connection.Connections) {
	log.Println("Closing database connections.")
	for _, dbh := range connections {
		dbh.Close()
	}
}
close closes database connections
package main
import (
	"flag"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
	"sync"
	"time"
	"github.com/sjmudd/queryprofiler/collection"
	"github.com/sjmudd/queryprofiler/connection"
	"github.com/sjmudd/queryprofiler/querykey"
	"github.com/sjmudd/queryprofiler/sample"
	"github.com/sjmudd/queryprofiler/version"
)
const (
	driver = "mysql"
	defaultIgnorePerformanceSchema = false
	defaultInterval                = 1
	defaultIterations              = 10
	defaultQueryFilter             = ""
	defaultTopN                    = 5
)
func toSeconds(t float64) string {
	if t == 0 {
		return "0s"
	}
	if t > 1 {
		return fmt.Sprintf("%.1f%s", t)
	}
	if t < 0.001 {
		return fmt.Sprintf(".1%f us", t*1000000)
	}
	return fmt.Sprintf(".1%f ms", t*1000)
}
func connect(dsns []string) connection.Connections {
	var connections connection.Connections
	var Connections string = "Connection"  
	var servers string = "connection"
	if len(dsns) != 1 {
		servers += "s"
		Connections += "s"
	}
	log.Println(fmt.Sprintf("Connecting to %d servers...", len(dsns)))
	for i, d := range dsns {
		conn := connection.NewConnection(d)
		conn.Open()  
		log.Println(fmt.Sprintf("%d: %s connected. Version: %s", i, conn.Name(), conn.Version()))
		connections = append(connections, conn)
	}
	return connections
}
func collect(connections connection.Connections, iterations int, intervalSeconds int, ignorePerformanceSchema bool, queryFilter string) []collection.Collections {
	var wg sync.WaitGroup
	var interval = time.Second * time.Duration(intervalSeconds)
	collections := make([]collection.Collections, len(connections))
	log.Println(fmt.Sprintf("Collecting data %d times...", iterations))
	for iteration := 1; iteration <= iterations; iteration++ {
		for i, conn := range connections {
			i := i        
			conn := conn  
			wg.Add(1)
			go func() {
				defer wg.Done()
				collection, err := collection.Collect(conn, ignorePerformanceSchema, queryFilter)
				if err != nil {
					log.Fatal("Failed to collect rows:", err)
				}
				collections[i] = append(collections[i], collection)
			}()
		}
		wg.Wait()
		var lengths []string
		for i := range collections {
			collectedLen := collections[i][len(collections[i])-1].Len()
			lengths = append(lengths, fmt.Sprintf("%d: %d", i, collectedLen))
		}
		log.Println(fmt.Sprintf("  %d: Collected rows: %s", iteration, strings.Join(lengths, ", ")))
		time.Sleep(interval)  
	}
	log.Println("Collecting finished.")
	return collections
}