func analyzeProfilingInfo()

in pkg/tools/process/process.go [96:146]


func analyzeProfilingInfo(context *analyzeContext, pid int32) (*profiling.Info, error) {
	// analyze process mapping
	mapFile, _ := os.Open(host2.GetHostProcInHost(fmt.Sprintf("%d/maps", pid)))
	scanner := bufio.NewScanner(mapFile)
	modules := make(map[string]*profiling.Module)
	for scanner.Scan() {
		submatch := mapFileContentRegex.FindStringSubmatch(scanner.Text())
		if len(submatch) != 6 {
			continue
		}
		if len(submatch[3]) > 2 && submatch[3][2] != 'x' {
			continue
		}
		moduleName := submatch[5]
		if isIgnoreModuleName(moduleName) {
			continue
		}

		// parsing range
		var err error
		moduleRange := &profiling.ModuleRange{}
		moduleRange.StartAddr, err = parseUInt64InModule(err, moduleName, "start address", submatch[1])
		moduleRange.EndAddr, err = parseUInt64InModule(err, moduleName, "end address", submatch[2])
		moduleRange.FileOffset, err = parseUInt64InModule(err, moduleName, "file offset", submatch[4])
		if err != nil {
			return nil, err
		}

		module := modules[moduleName]
		if module != nil {
			module.Ranges = append(module.Ranges, moduleRange)
			continue
		}
		modulePath := host2.GetHostProcInHost(fmt.Sprintf("%d/root%s", pid, moduleName))
		if !path.Exists(modulePath) {
			log.Debugf("could not found the module, ignore. name: %s, path: %s", moduleName, modulePath)
			continue
		}

		module, err = context.GetFinder(modulePath).ToModule(pid, moduleName, modulePath, []*profiling.ModuleRange{moduleRange})
		if err != nil {
			if err == profiling.ErrNotSupport {
				log.Warnf("not support the module in process(%d): %s, path: %s", pid, moduleName, modulePath)
				continue
			}
			return nil, fmt.Errorf("could not init the module: %s, error: %v", moduleName, err)
		}
		modules[moduleName] = module
	}
	return profiling.NewInfo(modules), nil
}