topevents

package
v1.31.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:     2,
	CmdCategory:  commands.CategoryDebug,
	Name:         "topevents",
	Description:  "Shows gateway event processing stats for all or one shard",
	HideFromHelp: true,
	Arguments: []*dcmd.ArgDef{
		{Name: "shard", Type: dcmd.Int},
	},

	RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {

		shardsTotal, lastPeriod := bot.EventLogger.GetStats()

		sortable := make([]*DiscordEvtEntry, len(eventsystem.AllDiscordEvents))
		for i, _ := range sortable {
			sortable[i] = &DiscordEvtEntry{
				Name: eventsystem.AllDiscordEvents[i].String(),
			}
		}

		for i, _ := range shardsTotal {
			if data.Args[0].Value != nil && data.Args[0].Int() != i {
				continue
			}

			for de, j := range eventsystem.AllDiscordEvents {
				sortable[de].Total += shardsTotal[i][j]
				sortable[de].PerSecond += float64(lastPeriod[i][j]) / bot.EventLoggerPeriodDuration.Seconds()
			}
		}

		sort.Sort(DiscordEvtEntrySortable(sortable))

		out := "Total event stats across all shards:\n"
		if data.Args[0].Value != nil {
			out = fmt.Sprintf("Stats for shard %d:\n", data.Args[0].Int())
		}

		out += "```\n#     Total  -   /s  - Event\n"
		sum := int64(0)
		sumPerSecond := float64(0)
		for k, entry := range sortable {
			out += fmt.Sprintf("#%-2d: %7d - %5.1f - %s\n", k+1, entry.Total, entry.PerSecond, entry.Name)
			sum += entry.Total
			sumPerSecond += entry.PerSecond
		}

		out += fmt.Sprintf("\nTotal: %d, Events per second: %.1f", sum, sumPerSecond)
		out += "\n```"

		return out, nil
	}),
}

Functions

This section is empty.

Types

type DiscordEvtEntry

type DiscordEvtEntry struct {
	Name      string
	Total     int64
	PerSecond float64
}

type DiscordEvtEntrySortable

type DiscordEvtEntrySortable []*DiscordEvtEntry

func (DiscordEvtEntrySortable) Len

func (d DiscordEvtEntrySortable) Len() int

func (DiscordEvtEntrySortable) Less

func (d DiscordEvtEntrySortable) Less(i, j int) bool

func (DiscordEvtEntrySortable) Swap

func (d DiscordEvtEntrySortable) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL