diff --git a/docs/Details_Usage.md b/docs/Details_Usage.md index a4d3c0797e8dc123e482ba54cf47dad770794deb..99175d86619051a2195c1a26d733c92778bdc22e 100644 --- a/docs/Details_Usage.md +++ b/docs/Details_Usage.md @@ -1588,7 +1588,12 @@ func main() { time.Sleep(time.Second) kperf.PmuDisable(pd) dataVo, err := kperf.PmuRead(pd) - file := kperf.PmuBeginWrite("/tmp/test.data", attr) + file, err := kperf.PmuBeginWrite("/tmp/test.data", attr) + if file == nil { + fmt.Printf("failed to write: %v\n", err) + return + } + kperf.PmuWriteData(file, dataVo) kperf.PmuEndWrite(file) } diff --git a/go/src/libkperf/kperf/kperf.go b/go/src/libkperf/kperf/kperf.go index 2d46d6d7d65b4c7f205f6d812ff4b85db2090b82..38345a93100b581c7ac6444315df22aafc75fd48 100644 --- a/go/src/libkperf/kperf/kperf.go +++ b/go/src/libkperf/kperf/kperf.go @@ -1306,16 +1306,16 @@ func (data *PmuData) appendBranchRecords(pmuData C.struct_PmuData) { // It is a simplified perf.data only include basic fields for perf sample, // including id, cpu, tid, pid, addr and branch stack. // It also includes sample like mmap, mmap2, comm, fork. -func PmuBeginWrite(path string, attr PmuAttr) C.PmuFile { +func PmuBeginWrite(path string, attr PmuAttr) (C.PmuFile, error) { cAttr, err := ToCPmuAttr(attr) defer FreePmuAttr(cAttr) if err != 0 { - return nil + return nil, errors.New(C.GoString(C.Perror())) } cFilePath := C.CString(path) file := C.PmuBeginWrite(cFilePath, cAttr) - return file + return file, errors.New(C.GoString(C.Perror())) } // brief Write PmuData list to file. @@ -1334,4 +1334,4 @@ func PmuWriteData(file C.PmuFile, dataVo PmuDataVo) error { // brief End to write file. func PmuEndWrite(file C.PmuFile) { C.PmuEndWrite(file) -} \ No newline at end of file +} diff --git a/pmu/dump_perf_data.cpp b/pmu/dump_perf_data.cpp index 5fdb04c9c005bb340ce444d6ceeff85505bcebbb..e6e16fdbbb7a044921afc70daa39afa6d15186be 100644 --- a/pmu/dump_perf_data.cpp +++ b/pmu/dump_perf_data.cpp @@ -499,7 +499,6 @@ private: attr.sample_type = GetSampleType(); // use attr in 5.10 attr.size = sizeof(perf_event_attr); - attr.sample_id_all = 1; PerfFileAttr fattr = {0}; fattr.attr = attr; // This is the offset of event id.