[PATCH weston v2 2/2] compositor: Implement JSON-timeline logging

sardemff7+wayland at sardemff7.net sardemff7+wayland at sardemff7.net
Thu Dec 4 03:46:33 PST 2014


On 2014-12-04 12:23, Pekka Paalanen wrote:
> On Tue, 02 Dec 2014 12:12:28 -0800
> Bill Spitzak <spitzak at gmail.com> wrote:
>> I think you should make an emit(FILE*, const char*) function that prints
>> a quoted string or null, instead of doing this repeatedly. Such a
>> function could also convert non-printable characters to escape sequences.
>
> Yeah, not a bad idea.

I think you better use a streaming JSON library (yajl is quite good at 
that). If this feature is for debugging, there is no harm making it 
optional with a little dependency. Even better, could it be a private 
debug protocol (always there) with a demo client outputting JSON? This 
way, we could see graphical clients providing graphs in real time, which 
would be nice too.


>> I think also you should ignore strict JSON and not put quotes around the
>> keywords. It makes the output a lot easier to read and most libraries
>> handle it.
>
> Oh, I did hate those quotes, but assumed they were necessary as per
> <http://www.json.org/>.

They are necessary. The fact that the format is stricter than parsers is 
just for robustness (and for JavaScript too probably, where these quotes 
are optional). If you want to output JSON, please output real JSON.


 > OTOH, I'm not so sure my outmost JSON structure
> is that valid either, since I'm emitting multiple separate objects
> instead of a huge array enclosing it or something.

You can define that you are printing objects one after another, without 
any relation between them. In this case, you can use a parser with 
“ignore trailing garbage” option (think of it as e.g. the endptr of strtol).
If you want to be able to parse the whole thing in one go, you should 
put them in a big array. You can end your array with an empty object so 
that you can always put a comma after each object. You will get 
something like this (using "{…}" for complete objects):

[
{…},
{…},
{…},
{}]

Or you can use a JSON library that will manage it for you.

-- 

Quentin “Sardem FF7” Glidic


More information about the wayland-devel mailing list