From: "viktor.prutyanov" <viktor.prutyanov@virtuozzo.com>
To: Martin Mares <mj@ucw.cz>
Cc: <linux-pci@vger.kernel.org>, dmonakhov@openvz.org
Subject: Re: [PATCH v2 0/2] lspci: Add support of JSON output format
Date: Mon, 19 Feb 2018 00:45:40 +0300 [thread overview]
Message-ID: <20180219004540.47d0fa1f@virtuozzo.com> (raw)
In-Reply-To: <mj+md-20180215.103138.21596.nikam@ucw.cz>
=D0=92 Thu, 15 Feb 2018 11:32:55 +0100
Martin Mares <mj@ucw.cz> =D0=BF=D0=B8=D1=88=D0=B5=D1=82:
> Hello!
>=20
> > This collection of patches adds support of printing PCI info in
> > JSON format =20
>=20
> First of all, I would really like to hear the reasons behind that --
> especially why the current machine-readable format is not sufficient.
>=20
> Generally, adding 1000 lines of code which duplicate a lot of existing
> logic should have a strong reason.
>=20
> Have a nice fortnight
Hello!
Because current machine-readable format is very limited and it is
difficult to extend it to support verbosity options.
JSON is defacto standard structured format. The key JSON's advantage is
good portability and extensibility and rich toolchain support. Almost
every modern utility has JSON format support for output, for example
lsblk and lscpu.
For example here is how structured -vv output looks like:
$ ./lspci -Jvv | python -m json.tool
JSON has nice tool called 'jq' which is basically Swiss-knife parser.
For example you can output some fields you need as tsv:
$ ./lspci -J -vv | jq -r '.[][] | [.Slot, .Device, .IRQ] | @tsv'
...
00:14.0 8 Series USB xHCI HC 41
03:00.0 RTL8411B PCI Express Card Reader 43
04:00.0 GK107M [GeForce GT 750M] 255
...
Or let's reformat part of input structure to another structure you need:
$ ./lspci -Jvv | jq '.[][3] | {dev:.Device, class:.Class, irq:.IRQ}'
{
"dev": "Haswell-ULT HD Audio Controller",
"class": "Audio device",
"irq": "48"
}
The patch is large mostly because current lspci use add-hoc output
approach. So patch add skeleton which construct structured object
separately from printing. Objects can later be easily extended to
support new fields and output formats (not only JSON).
next prev parent reply other threads:[~2018-02-18 21:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-14 16:07 [PATCH v2 0/2] lspci: Add support of JSON output format Viktor Prutyanov
2018-02-14 16:07 ` [PATCH v2 1/2] lspci: Add printing info in JSON format Viktor Prutyanov
2018-02-14 16:07 ` [PATCH v2 2/2] lspci: Add PCI info output " Viktor Prutyanov
2018-02-15 10:32 ` [PATCH v2 0/2] lspci: Add support of JSON output format Martin Mares
2018-02-18 21:45 ` viktor.prutyanov [this message]
2018-03-16 16:57 ` Martin Mares
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180219004540.47d0fa1f@virtuozzo.com \
--to=viktor.prutyanov@virtuozzo.com \
--cc=dmonakhov@openvz.org \
--cc=linux-pci@vger.kernel.org \
--cc=mj@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).