pahole and parsing data: --skip

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Em Wed, Jul 01, 2020 at 08:25:34AM -0300, Arnaldo Carvalho de Melo escreveu:
> 	The latest changeset shows what this is about, see its example
> below, please help testing and suggesting whatever needs you have
> regarding pretty printing.
> 
> 	Now to implement --skip.

Now to implement --seek, this time in bytes, so that we can, for
instance, pretty print perf.data records, looking at 'perf report -D'
and getting the offset of the start of a series of 'struct
perf_event_attr' or 'struct perf_event_header'.

- Arnaldo

commit 44af7c02b5d0a7f2b93fab9fda45907cd6fe0827
Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Date:   Wed Jul 1 08:36:28 2020 -0300

    pahole: Implement --skip, just like dd
    
      $ objcopy -O binary --only-section=__versions drivers/scsi/sg.ko versions
      $ pahole -C modversion_info drivers/scsi/sg.ko
      struct modversion_info {
            long unsigned int          crc;                  /*     0     8 */
            char                       name[56];             /*     8    56 */
    
            /* size: 64, cachelines: 1, members: 2 */
      };
      $ pahole --count 3 -C modversion_info drivers/scsi/sg.ko < versions
      {
            .crc = 0x8dabd84,
            .name = "module_layout",
      },
      {
            .crc = 0x45e4617b,
            .name = "no_llseek",
      },
      {
            .crc = 0xa23fae8c,
            .name = "param_ops_int",
      },
      $ pahole --skip 1 --count 2 -C modversion_info drivers/scsi/sg.ko < versions
      {
            .crc = 0x45e4617b,
            .name = "no_llseek",
      },
      {
            .crc = 0xa23fae8c,
            .name = "param_ops_int",
      },
      $
    
    Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

diff --git a/dwarves.h b/dwarves.h
index f224d05b28c3..24f9c7c37843 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -55,6 +55,7 @@ struct conf_load {
 /** struct conf_fprintf - hints to the __fprintf routines
  *
  * @count - Just like 'dd', stop pretty printing input after 'count' records
+ * @skip - Just like 'dd', skip 'count' records when pretty printing input
  * @flat_arrays - a->foo[10][2] becomes a->foo[20]
  * @classes_as_structs - class f becomes struct f, CTF doesn't have a "class"
  * @cachelinep - pointer to current cacheline, so that when expanding types we keep track of it,
@@ -71,6 +72,7 @@ struct conf_fprintf {
 	uint32_t   base_offset;
 	uint32_t   count;
 	uint32_t   *cachelinep;
+	uint32_t   skip;
 	uint8_t	   indent;
 	uint8_t	   expand_types:1;
 	uint8_t	   expand_pointers:1;
diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 7e8207756432..db820cca323f 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -78,6 +78,10 @@ Set cacheline size to SIZE bytes.
 .B \-\-count=COUNT
 Pretty print the first COUNT records from input.
 
+.TP
+.B \-\-skip=COUNT
+Skip COUNT input records.
+
 .TP
 .B \-E, \-\-expand_types
 Expand class members. Useful to find in what member of inner structs where an
@@ -502,6 +506,16 @@ $ pahole --count 3 -C modversion_info drivers/scsi/sg.ko < versions
       .name = "param_ops_int",
 },
 $
+$ pahole --skip 1 --count 2 -C modversion_info drivers/scsi/sg.ko < versions
+{
+      .crc = 0x45e4617b,
+      .name = "no_llseek",
+},
+{
+      .crc = 0xa23fae8c,
+      .name = "param_ops_int",
+},
+$
 .fi
 .P
 
diff --git a/pahole.c b/pahole.c
index 1b84f5c2fa4a..7d8431c64423 100644
--- a/pahole.c
+++ b/pahole.c
@@ -803,6 +803,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_just_unions	   309
 #define ARGP_just_structs	   310
 #define ARGP_count		   311
+#define ARGP_skip		   312
 
 static const struct argp_option pahole__options[] = {
 	{
@@ -829,6 +830,12 @@ static const struct argp_option pahole__options[] = {
 		.arg  = "COUNT",
 		.doc  = "Print only COUNT input records"
 	},
+	{
+		.name = "skip",
+		.key  = ARGP_skip,
+		.arg  = "COUNT",
+		.doc  = "Skip COUNT input records"
+	},
 	{
 		.name = "find_pointers_to",
 		.key  = 'f',
@@ -1154,6 +1161,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		just_structs = true;			break;
 	case ARGP_count:
 		conf.count = atoi(arg);			break;
+	case ARGP_skip:
+		conf.skip = atoi(arg);			break;
 	default:
 		return ARGP_ERR_UNKNOWN;
 	}
@@ -1325,11 +1334,17 @@ static int tag__stdio_fprintf_value(struct tag *type, struct cu *cu, FILE *fp)
 	int _sizeof = tag__size(type, cu), printed = 0;
 	void *instance = malloc(_sizeof);
 	uint32_t count = 0;
+	uint32_t skip = conf.skip;
 
 	if (instance == NULL)
 		return -ENOMEM;
 
 	while (fread(instance, _sizeof, 1, stdin) == 1) {
+		if (skip) {
+			--skip;
+			continue;
+		}
+
 		printed += tag__fprintf_value(type, cu, instance, _sizeof, fp);
 		printed += fprintf(fp, ",\n");
 



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux