| 179 | } |
| 180 | |
| 181 | func (this *Module) getExtraOptions(em *ebpf.Map) perf.ExtraPerfOptions { |
| 182 | // 这里可以考虑在一开始的时候就完成初始化 |
| 183 | map_value := reflect.ValueOf(em) |
| 184 | map_name := map_value.Elem().FieldByName("name") |
| 185 | IsMmapEvent := map_name.String() == "fake_events" |
| 186 | |
| 187 | // http://aospxref.com/android-11.0.0_r21/xref/system/extras/simpleperf/perf_regs.cpp#82 |
| 188 | var RegMask uint64 |
| 189 | if this.mconf.Is32Bit { |
| 190 | RegMask = (1 << PERF_REG_ARM_MAX) - 1 |
| 191 | } else { |
| 192 | RegMask = (1 << PERF_REG_ARM64_MAX) - 1 |
| 193 | } |
| 194 | var ShowRegs bool |
| 195 | if this.mconf.RegName != "" { |
| 196 | ShowRegs = true |
| 197 | } else { |
| 198 | ShowRegs = this.mconf.ShowRegs |
| 199 | } |
| 200 | BrkPid := this.mconf.BrkPid |
| 201 | // 对内核地址断点的时候无法指定pid为用户进程的pid |
| 202 | if this.mconf.BrkKernel { |
| 203 | this.logger.Printf("do brk kernel addr:%x, filter pid for %d", this.mconf.BrkAddr, this.mconf.BrkPid) |
| 204 | BrkPid = -1 |
| 205 | } |
| 206 | return perf.ExtraPerfOptions{ |
| 207 | UnwindStack: this.mconf.UnwindStack, |
| 208 | ShowRegs: ShowRegs, |
| 209 | PerfMmap: IsMmapEvent, |
| 210 | BrkPid: BrkPid, |
| 211 | BrkAddr: this.mconf.BrkAddr, |
| 212 | BrkLen: this.mconf.BrkLen, |
| 213 | BrkType: this.mconf.BrkType, |
| 214 | Sample_regs_user: RegMask, |
| 215 | Sample_stack_user: this.mconf.StackSize, |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func (this *Module) getPerCPUBuffer() int { |
| 220 | return os.Getpagesize() * (int(this.mconf.Buffer) * 1024 / 4) |