Example #1
0
func updatePromt() {
	shell.SetPrompt("\n" + window.GetWindow().PrintCurrent() + " >> ")
}
Example #2
0
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()

}
Example #3
0
func GetLog(tid string, count int) {

	records, ok := record.RecordByThread[tid]
	if !ok {
		fmt.Printf("Unknown TID: %s\n", tid)
		return
	}

	if len(records) == 0 {
		fmt.Printf("No records for the given thread\n", tid)
		return
	}

	t := window.GetWindow().Current

	index := 0
	if t.Before(records[0].Time) {
		index = 0
	} else if t.After(records[len(records)-1].Time) {
		index = len(records) - 1
	} else {

		for i, r := range records {
			if r.Time.After(t) || r.Time.Equal(t) {
				index = i
				break
			}
		}
	}

	if count == 0 {
		count = 5
	}

	if count > 0 {
		start := index - count
		end := index + count + 1
		if start < 0 {
			start = 0
		}
		if end > len(records) {
			end = len(records)
		}

		for i := start; i < end; i++ {
			prefix := "   "
			if t.Equal(records[i].Time) {
				prefix = " * "
			}
			fmt.Println(prefix + records[i].Raw)
		}
	} else {

		nCmd := records[index].GetCurrentCommand()

		if nCmd == nil {
			fmt.Printf("No command found for the given thread %s, at timestamp %s", tid, records[index].Time.Format(utils.DateFormat))
			return
		}

		for nCmd.NextByThread != nil && !nCmd.IsEndCommand() {
			fmt.Println(nCmd.Raw)
			nCmd = nCmd.NextByThread
		}

		if nCmd.IsEndCommand() {
			fmt.Println(nCmd.Raw)
		}
	}
	return
}