示例#1
0
//一个目录不支持嵌套
func OneDirDump2Json(in, out string) {
	util.PrepareDir(out)

	walk := func(path string, info os.FileInfo, err error) error {
		if info.IsDir() == false && strings.HasSuffix(path, ".dmp") {
			index := strings.LastIndex(path, "\\")
			filename := path[index+1 : len(path)-4]
			filename += ".json"
			outname := out
			outname += "\\" + filename
			fmt.Println(outname)
			OneDumpStack2Json(path, outname)
		}
		return nil
	}

	err := filepath.Walk(in, walk)
	if err != nil {
		fmt.Println("no error expected, found: %s", err)
	}
}
示例#2
0
func WorkOnce(ini Config) {

	//-dump
	if strings.Contains(ini.WorkParams, "AnalyzeDumpFile") {
		fmt.Println("begin AnalyzeDumpFile")
		util.PrepareDir(ini.DumpOutputPath)
		re := Analyze(
			ini.DumpInputPath, ini.DumpOutputPath, ini.MoveDumpFile, ini.AnalyzeLevel,
			ini.DumpNum)
		fmt.Println("the num of dumps: ", re)
		fmt.Println("end AnalyzeDumpFile")
	}

	//-json
	if strings.Contains(ini.WorkParams, "GenJsonFile") {
		fmt.Println("begin GenJsonFile")
		util.PrepareDir(ini.JsonOutputPath)
		//pkg.GenDumpJsonFileByDump(ini.JsonInputPath, ini.JsonOutputPath, ini.JsonOutputMaxNum)
		GenDumpJsonFileByJson(ini.JsonInputPath, ini.JsonOutputPath, ini.JsonOutputMaxNum,
			ini.JsonModuleFilter)
		fmt.Println("end GenJsonFile")
	}

	//-tar
	if strings.Contains(ini.WorkParams, "DoTarPakage") {
		fmt.Println("begin DoTarPakage")
		//pkg.util.PrepareDir(ini.TarOutputPath)
		TarJsonAndDmp(ini)
		fmt.Println("end DoTarPakage")
	}

	//-send tar
	if strings.Contains(ini.WorkParams, "SendTarPakage") {
		fmt.Println("begin SendTarPakage")
		TcpSendFile(ini)
		fmt.Println("end SendTarPakage")
	}

	//-recv tar
	if strings.Contains(ini.WorkParams, "ReceiveTarPakage") {
		fmt.Println("begin ReceiveTarPakage")
		ReceiveTarPakage(ini)
		fmt.Println("end ReceiveTarPakage")
	}

	//-untar
	if strings.Contains(ini.WorkParams, "UntarPakage") {
		fmt.Println("begin UntarPakage")
		UntarFile(ini.UntarInputPath, ini.UntarOutputPath)
		fmt.Println("end UntarPakage")
	}

	//-callstack
	if strings.Contains(ini.WorkParams, "GenCallStackFile") {
		fmt.Println("begin GenCallStackFile")
		GenAllDirCallStack(ini.GenCallStackInputPath, ini.GenCallStackCmd, ini.GenCallStackParams,
			ini.GenCallStackVersionFilter)
		fmt.Println("end GenCallStackFile")
	}

	//-ondeir2json
	if strings.Contains(ini.WorkParams, "OneDirDump2Json") {
		fmt.Println("begin OneDirDump2Json")
		OneDirDump2Json(ini.OneDirDump2JsonInPath, ini.OneDirDump2JsonOutPath)
		fmt.Println("end OneDirDump2Json")
	}

	//-CallStackDistributed
	if strings.Contains(ini.WorkParams, "CallStackDistributed") {
		fmt.Println("begin CallStackDistributed")
		CallStackDistributed(ini.CallStackDistributedInPath, ini.CallStackDistributedOutPath,
			ini.CallStackDistributedMaxLevel, ini.CallStackDistributedMinNumber)
		fmt.Println("end CallStackDistributed")
	}
}
示例#3
0
func GenDumpJsonFileByJson(dirin, dirout string, max int, JsonModuleFilter string) {

	fmt.Print("GenDumpJsonFileByJson begin \r\n", dirin, dirout)
	var in_jsonfile map[string]OneVersionResultJsonList
	in_jsonfile = make(map[string]OneVersionResultJsonList)
	json_file_slice := make([]string, 20)

	walk := func(path string, info os.FileInfo, err error) error {
		if info.IsDir() == false && strings.HasSuffix(path, ".json") {
			json_file_slice = append(json_file_slice, path)

			index := strings.LastIndex(path, "\\")
			parent := path[:index]
			fmt.Print(parent, "\r\n", dirin)
			if parent == dirin {
				filename := path[index+1:]
				file_part := strings.Split(filename, "_")
				fmt.Print("\r\n", file_part[0], file_part[len(file_part)-1], "\r\n")
				if file_part[len(file_part)-1] == "4golang.json" {
					var content OneVersionResultJsonList
					if ReadJsonFile(path, &content) == nil {
						in_jsonfile[file_part[0]] = content
					} else {
						fmt.Println("read file failed: %s", path)
					}
				}
			}
		}
		return err
	}

	err := filepath.Walk(dirin, walk)
	if err != nil {
		fmt.Println("no error expected, found: %s", err)
	}
	//fmt.Println("the visited")
	//fmt.Println(visited)
	//fmt.Println("the visited after")

	//gen json file
	fmt.Println(in_jsonfile)

	//copy to json dir
	s0 := fmt.Sprintf("%s\\%s\\", dirout, "total")
	util.PrepareDir(s0)
	for _, v := range json_file_slice {
		index := strings.LastIndex(v, "\\")
		filename := v[index+1:]
		dst := s0 + filename
		CopyFile(v, dst)
	}

	for k, v := range in_jsonfile {

		s := fmt.Sprintf("%s\\%s\\%s", dirout, k, "json")
		s2 := fmt.Sprintf("%s\\%s\\%s", dirout, k, "dmp")
		//fmt.Println(v.dumppath)
		//fmt.Println(s)
		fmt.Println(s)
		util.PrepareDir(s)
		util.PrepareDir(s2)

		for index, v2 := range v.List {
			module := v2.MoudleAndOffset[:strings.LastIndex(v2.MoudleAndOffset, "\\")]
			if len(JsonModuleFilter) != 0 && strings.Contains(JsonModuleFilter, module) == false {
				continue
			}

			offset := strings.Replace(v2.MoudleAndOffset, "\\", "_", -1)
			file_head := fmt.Sprintf("%s\\%03d_%d_%s", s, index, v2.Number, offset)
			file_head2 := fmt.Sprintf("%s\\%03d_%d_%s", s2, index, v2.Number, offset)
			for i, v3 := range v2.SrcFile {
				file := fmt.Sprintf("%s_%02d.json", file_head, i)
				file2 := fmt.Sprintf("%s_%02d.dmp", file_head2, i)
				OneDump2Json(v3, file)
				//callstack
				//copy file
				CopyFile(v3, file2)

			}

			if index >= max {
				break
			}
		}

	}

}