]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - tools/perf/util/event.c
perf tools: Pre-check sample size before parsing
[karo-tx-linux.git] / tools / perf / util / event.c
index 1023f67633a4c16ada61dc8f69796016283dabd4..17c1c3c875c3714612a38cb3ef4c2201c33b70b5 100644 (file)
@@ -35,6 +35,22 @@ const char *perf_event__name(unsigned int id)
        return perf_event__names[id];
 }
 
+int perf_sample_size(u64 sample_type)
+{
+       u64 mask = sample_type & PERF_SAMPLE_MASK;
+       int size = 0;
+       int i;
+
+       for (i = 0; i < 64; i++) {
+               if ((mask << i) & 1)
+                       size++;
+       }
+
+       size *= sizeof(u64);
+
+       return size;
+}
+
 static struct perf_sample synth_sample = {
        .pid       = -1,
        .tid       = -1,