コード例 #1
0
ファイル: lock.go プロジェクト: dbenque/maglogparser
func StatLock(onlyCmd bool, setWindow bool) {

	result := statThreadID()

	start := time.Unix(0, 0)
	end := time.Now().Add(24 * time.Hour)

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 20, 0, 2, ' ', tabwriter.AlignRight)

	fmt.Fprintln(w, "Time\tTID\tWait\tTill\tCommand\tStart\tEnd\tDuration\t")

	for _, stat := range result {

		if onlyCmd && stat.rcmd == nil {
			continue
		}

		max := stat.r.NextByThread.Time.Sub(stat.r.Time)

		cmd := "nil"
		cmdTime := "nil"
		if stat.rcmd != nil {
			cmdTime = stat.rcmd.Time.Format(utils.DateFormat)
			cmd = stat.rcmd.Cmd
		}

		cmdCompleteTime := "nil"
		if stat.rcmdCompleted != nil {
			cmdCompleteTime = stat.rcmdCompleted.Time.Format(utils.DateFormat)
		}

		duration := ""
		if stat.rcmdCompleted != nil && stat.rcmd != nil {
			duration = fmt.Sprintf("%f", stat.rcmdCompleted.Time.Sub(stat.rcmd.Time).Seconds())
		}

		if stat.r.Time.After(start) {
			start = stat.r.Time
		}

		if stat.r.NextByThread.Time.After(end) {
			end = stat.r.NextByThread.Time
		}

		fmt.Fprintf(w, "%s\t%s\t%f\t%s\t%s\t%s\t%s\t%s\t\n", stat.r.Time.Format(utils.DateFormat), stat.tid, max.Seconds(), stat.r.NextByThread.Time.Format(utils.DateFormat), cmd, cmdTime, cmdCompleteTime, duration)

		if setWindow {
			window.Reset()
			window.SetStart(start)
			window.SetEnd(end)
		}

	}
	fmt.Fprintln(w)
	w.Flush()

}
コード例 #2
0
ファイル: main.go プロジェクト: dbenque/maglogparser
func main() {

	args := os.Args[1:]

	chanThreadID := make(chan *record.Record)
	chanTime := make(chan *record.Record)

	var wg sync.WaitGroup

	wg.Add(2)
	go func() {
		defer wg.Done()
		record.ScanThreadID(chanThreadID)
	}()
	go func() {
		defer wg.Done()
		window.ScanTime(chanTime)
	}()

	for _, files := range args {
		for s := range readLine(files) {
			r := record.NewRecord(s)
			if r != nil {
				chanThreadID <- r
				chanTime <- r
			}
		}
	}

	close(chanThreadID)
	close(chanTime)

	wg.Wait()

	shell.Register("setTime", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("set the time around which the log exploration should be done.\nTo retrieve logs and on going commands.\nSyntax: setTime " + utils.DateFormat)
			return "", nil
		}

		t, err := time.Parse(utils.DateFormat, line)
		if err != nil {
			return "", err
		}

		if err := window.SetTime(t); err != nil {
			return "", err
		}

		rt.SetTime(t)

		return "", nil
	})

	shell.Register("TID", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Show the number of command executed by each thread.\nSyntax: TID")
			return "", nil
		}

		TID.StatTID()
		return "", nil
	})

	shell.Register("log", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Display nbLine log lines around the time that was set (setTime) for a given TID.\nSyntax: log TID [nbLine=5]")
			fmt.Println("Display the log of the command for the time that was set (setTime) for a given TID.\nSyntax: log TID cmd")
			return "", nil
		}

		if len(args) < 1 {
			fmt.Println("Syntax error, missing arguments")
			fmt.Println("Display the log around the time that was set (setTime).\nSyntax: log TID [nbLine=5]")
			return "", nil
		}

		count := 0
		if len(args) == 2 {
			if c, err := strconv.Atoi(args[1]); err == nil {
				count = c
			} else if args[1] == "cmd" {
				count = -1
			}
		}

		logging.GetLog(args[0], count)
		return "", nil
	})

	shell.Register("queue", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Build statistic for queues (readonly pool or write).\nSyntax: queue [r|w]")
			return "", nil
		}

		queue.StatQueue(len(args) > 0 && args[0] == "w")
		return "", nil
	})

	shell.Register("cmd", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Show the commands statistics.\nSyntax: cmd")
			fmt.Println("Show the commands for a given thread in the time window.\nSyntax: cmd 'TID'")
			fmt.Println("Show the response time distribution in the time window.\nSyntax: cmd d 'CmdName'")
			return "", nil
		}

		if len(args) == 1 {
			if _, err := strconv.Atoi(args[0]); err == nil {
				cmd.StatCmdTID(args[0])
				return "", nil
			}
		}

		if len(args) == 2 {
			if args[0] == "d" {
				cmd.StatCmdDistribution(args[1])
				return "", nil
			}
		}

		cmd.StatCmdAll()

		return "", nil
	})

	shell.Register("lock", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Search for each thread the max hang time.\nSyntax: lock [cmd] [setWindow]\n\tcmd: Only display the theard that execute commands\n\tsetWindow: set the time window to the range of time returned by this lock exploration.")
			return "", nil
		}

		onlyCmd := false
		setWindow := false
		for _, a := range args {
			if a == "cmd" {
				onlyCmd = true
			}
			if a == "setWindow" {
				setWindow = true
			}
		}

		lock.StatLock(onlyCmd, setWindow)

		if setWindow {
			updatePromt()
		}

		return "", nil
	})

	shell.Register("window", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Display the time window of all the logs and the enclosed one used for the statistics.\nSyntax: window [reset]\n\treset: set the active window to the maximum (all logs)")
			return "", nil
		}

		if len(args) > 0 && args[0] == "reset" {
			window.Reset()
			updatePromt()
		}

		return window.GetWindow().Print(), nil
	})

	shell.Register("start", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Set the lower bound of the active time window.\nSyntax: start " + utils.DateFormat)
			return "", nil
		}

		if len(args) == 0 {
			return "", fmt.Errorf("start take 1 argument that must be a timestamp")
		}

		start, err := time.Parse(utils.DateFormat, strings.Join(args, " "))

		if err != nil {
			return "", err
		}
		if err = window.SetStart(start); err != nil {
			return "", err
		}
		updatePromt()

		return "", nil
	})

	shell.Register("end", func(args ...string) (string, error) {
		line := strings.Join(args, " ")
		if strings.Contains(line, "--help") {
			fmt.Println("Set the upper bound of the active time window.\nSyntax: end " + utils.DateFormat)
			return "", nil
		}

		if len(args) == 0 {
			return "", fmt.Errorf("start take 1 argument that must be a timestamp")
		}

		start, err := time.Parse(utils.DateFormat, strings.Join(args, " "))

		if err != nil {
			return "", err
		}
		if err = window.SetEnd(start); err != nil {
			return "", err
		}
		updatePromt()

		return "", nil
	})

	updatePromt()

	shell.Start()

}