Beispiel #1
0
// Add contestants to the database if necessary
func initialize(volt *voltdb.Conn) {
	rsp, err := volt.Call("Initialize", ttlContestants, contestants)
	if err != nil {
		log.Fatalf("Failed in initialize database. %v\n", err)
	}
	if rsp.Status() == voltdb.SUCCESS {
		var rs ScalarResult
		rsp.Table(0).Next(&rs)
		fmt.Printf("Initialized %d contestants.\n", rs.Result)
	} else {
		log.Fatalf("Failed to initialize %#v.\n", rsp)
	}
}
Beispiel #2
0
// printResults displays the current vote tally for each contestant.
func printResults(volt *voltdb.Conn) {
	type ResultsRow struct {
		Contestant string
		Id         int
		Votes      int
	}
	var row ResultsRow
	fmt.Printf("\nCurrent results:\n")
	response, _ := volt.Call("Results")
	table := response.Table(0)
	for table.HasNext() {
		if err := table.Next(&row); err != nil {
			log.Fatalf("Table iteration error %v\n", err)
		}
		fmt.Printf("%v\t%v\t%v\n", row.Contestant, row.Id, row.Votes)
	}
}
Beispiel #3
0
// dumpProcedureCost prints procedures ordered by (Invocations * AvgExecTime)
func dumpProcedureCost(volt *voltdb.Conn) {
	response, err := volt.Call("@Statistics", "PROCEDURE", 0)
	if err != nil {
		log.Fatalf("Error calling @Statistics PROCEDURE %v\n", err)
	}

	// accumulate running totals in this map by procedure name
	statsByProcedure := make(map[string]ProcedureCost)
	table := response.Table(0)
	for table.HasNext() {
		var row StatsProcedure
		if err := table.Next(&row); err != nil {
			log.Fatalf("Table iteration error %v\n", err)
		}
		if exists, ok := statsByProcedure[row.Procedure]; ok == true {
			// weighted average of exec times by timedInvocations
			avg := (exists.weight() + row.weight()) / (exists.TimedInvocations + row.TimedInvocations)
			exists.Invocations += row.Invocations
			exists.TimedInvocations += row.TimedInvocations
			exists.AvgExecTime = avg
		} else {
			var newEntry ProcedureCost
			newEntry.Procedure = row.Procedure
			newEntry.Invocations = row.Invocations
			newEntry.TimedInvocations = row.TimedInvocations
			newEntry.AvgExecTime = row.AvgExecTime
			statsByProcedure[newEntry.Procedure] = newEntry
		}
	}

	sorted := sortProcedureCostMap(statsByProcedure)
	var ttlWeight int64 = 0
	for _, stat := range sorted {
		ttlWeight += stat.weight()
	}
	for _, stat := range sorted {
		fmt.Printf("%0.1f%% %v\n", float64(stat.weight())/float64(ttlWeight)*100, stat)
	}
}