示例#1
0
文件: app.go 项目: ChengShuY/ps-top
// NewApp sets up the application given various parameters.
func NewApp(settings Settings) *App {
	logger.Println("app.NewApp()")
	app := new(App)

	anonymiser.Enable(settings.Anonymise) // not dynamic at the moment
	app.dbh = settings.Conn.Handle()

	status := global.NewStatus(app.dbh)
	variables := global.NewVariables(app.dbh)
	// Prior to setting up screen check that performance_schema is enabled.
	// On MariaDB this is not the default setting so it will confuse people.
	ensurePerformanceSchemaEnabled(variables)

	app.ctx = context.NewContext(status, variables)
	app.ctx.SetWantRelativeStats(true)
	app.count = settings.Count
	app.finished = false

	app.stdout = settings.Stdout
	app.display = settings.Disp
	app.display.SetContext(app.ctx)
	app.SetHelp(false)

	if err := view.ValidateViews(app.dbh); err != nil {
		log.Fatal(err)
	}

	logger.Println("app.Setup() Setting the default view to:", settings.View)
	app.currentView.SetByName(settings.View) // if empty will use the default

	app.setupInstruments = setup_instruments.NewSetupInstruments(app.dbh)
	app.setupInstruments.EnableMonitoring()

	app.wi.SetWaitInterval(time.Second * time.Duration(settings.Interval))

	// setup to their initial types/values
	logger.Println("app.NewApp() Setup models")
	app.fsbi = fsbi.NewFileSummaryByInstance(app.ctx)
	app.tiwsbt = tiwsbt.NewTableIoLatency(app.ctx)
	app.tlwsbt = tlwsbt.NewTableLockLatency(app.ctx)
	app.ewsgben = ewsgben.NewMutexLatency(app.ctx)
	app.essgben = essgben.NewStagesLatency(app.ctx)
	app.memory = memory_usage.NewMemoryUsage(app.ctx)
	app.users = user_latency.NewUserLatency(app.ctx)
	logger.Println("app.NewApp() Finished initialising models")

	logger.Println("app.NewApp() fixLatencySetting()")
	app.fixLatencySetting() // adjust to see ops/latency

	logger.Println("app.NewApp() resetDBStatistics()")
	app.resetDBStatistics()

	logger.Println("app.NewApp() finishes")
	return app
}
示例#2
0
文件: app.go 项目: denji/ps-top
// NewApp sets up the application given various parameters.
func NewApp(conn *connector.Connector, interval int, count int, stdout bool, defaultView string, disp display.Display) *App {
	logger.Println("app.NewApp()")
	app := new(App)

	app.ctx = new(context.Context)
	app.count = count
	app.dbh = conn.Handle()
	app.finished = false
	app.stdout = stdout
	app.display = disp
	app.display.SetContext(app.ctx)
	app.SetHelp(false)

	if err := view.ValidateViews(app.dbh); err != nil {
		log.Fatal(err)
	}

	logger.Println("app.Setup() Setting the default view to:", defaultView)
	app.view.SetByName(defaultView) // if empty will use the default

	app.setupInstruments = setup_instruments.NewSetupInstruments(app.dbh)
	app.setupInstruments.EnableMonitoring()

	app.wi.SetWaitInterval(time.Second * time.Duration(interval))

	variables, _ := lib.SelectAllGlobalVariablesByVariableName(app.dbh)
	// setup to their initial types/values
	app.fsbi = fsbi.NewFileSummaryByInstance(variables)
	app.tlwsbt = new(tlwsbt.Object)
	app.ewsgben = new(ewsgben.Object)
	app.essgben = new(essgben.Object)

	app.ctx.SetWantRelativeStats(true) // we show info from the point we start collecting data
	app.fsbi.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.tlwsbt.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.tiwsbt.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.users.SetWantRelativeStats(app.ctx.WantRelativeStats()) // ignored
	app.essgben.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.ewsgben.SetWantRelativeStats(app.ctx.WantRelativeStats()) // ignored

	app.fixLatencySetting() // adjust to see ops/latency

	app.resetDBStatistics()

	// get short name (to save space)
	hostname, _ := lib.SelectGlobalVariableByVariableName(app.dbh, "HOSTNAME")
	app.ctx.SetHostname(hostname)
	// get the MySQL version
	mysqlVersion, _ := lib.SelectGlobalVariableByVariableName(app.dbh, "VERSION")
	app.ctx.SetMySQLVersion(mysqlVersion)

	return app
}