Skip to content

Conversation

douglas-raillard-arm
Copy link
Collaborator

Allows collecting dmesg output and parses it for easy filtering.

"""

def parse_ts_msg(line):
ts_msg_regex = r'\[(.*?)\] (.*)'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-compile the regex and reuse instead of compiling for each line?

ts, msg = parse_ts_msg(line)
except ValueError:
facility, level, remainder = line.split(':', 2)
ts, msg = parse_ts_msg(remainder)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this in a try catch as well in case the second parsing attempt also fails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this one fails, that means the parser is broken so we want to know about it to fix it. The 1st failure is somehow expected and should always detect correctly what it is supposed to detect (i.e. something before the timestamp [42.4242] or not).

:param level: log level
:type level: str

:param ts: Timestamp of the entry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it wouldn't hurt to name this "timestamp"

"debug", # debug-level messages
]

def __init__(self, target, level=LOG_LEVELS[-1], facility='kern'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a check for that facility being available (other than the dmesg exit code check) ?

I don't know how much you can rely on the output of dmesg -h but you could parse facilities (and log levels BTW) from there. Sort of something like this (but as a static/classmethod maybe) https://github.com/ARM-software/devlib/blob/master/devlib/trace/systrace.py#L61

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the busybox's dmesg help :-)

# dmesg -h
dmesg: invalid option -- 'h'
BusyBox v1.29.2 (2018-12-18 16:55:05 GMT) multi-call binary.

Usage: dmesg [-c] [-n LEVEL] [-s SIZE]

Print or control the kernel ring buffer

	-c		Clear ring buffer after printing
	-n LEVEL	Set console logging level
	-s SIZE		Buffer size
	-r		Print raw message buffer

Note that there isn't even a --help option, so we can safely forget about any "introspection" capabilities being always available.

There is also relatively little value in practice, since 99% of devlib users will probably restrict that to kern. I had to get the list of log levels for another reason: util-linux dmesg wants an explicit list of all levels to show, i.e. it will not show "levels above X", it will show "level X". Since we usually want the "levels above X" behavior, I had to get the ordered list of levels.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

Allows collecting dmesg output and parses it for easy filtering.
)


class DmesgCollector(TraceCollector):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your problem, but I find this hierarchy confusing. Could the base class be named something different like BufferCollector? I appreciate this is probably outside the scope of this patch by the way. But dmesg and tracing has no relationship at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devlib's notion of tracing != Ftrace. Here it's just something you can start, stop, and get a log/trace/item/<find name you like> containing something that happening during this start & stop.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing doesn't have to be ftrace. But tracing implies a step by step break down of something. Again it seems you stared at this code for too long.

Anyways. This comment was directed towards the maintainers if they'd like to consider renaming following Douglas suggestion.


self.dmesg_out = self.target.execute(cmd)

def get_trace(self, outfile):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: get_log() or get_buffer() makes more sense here if it can be changed. I appreciate this is overriding a similarly named method though. So again out of the scope of this patch probably.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_trace() is part of the TraceCollector API (https://github.com/ARM-software/devlib/blob/master/devlib/trace/__init__.py), so we have to provide it.

In the end dmesg is a trace itself (you get events at given timestamps), so it's not too outlandish if you look at it the right way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know. I did say that in my comment that I appreciate it's overriding a similarly named function and that it's probably outside the scope of this patch.

n the end dmesg is a trace itself (you get events at given timestamps), so it's not too outlandish if you look at it the right way.

I think you stared at these stuff for too long. A dmesg is not a trace. Not even remotely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on the usage of printk: sometimes the order does not hugely matter and it's just a way to log stuff to show to the user (some boot-time messages). Sometimes printk can be treated as timestamped events, like when enabling cpufreq debugging, in which case it is very much like a basic trace system (and I intend to mix that with other actual ftrace events on a timeline, so they can definitely be treated as equivalent).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, I agree that TraceCollector is not the best name for the collector's base. Something agnostic like CollectorBase may be more appropriate, but that would mean rename + alias on the old name.

Copy link
Collaborator

@marcbonnici marcbonnici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it might be worth looking into doing a organisational rename now we are getting more varied Collectors, however for now I'm happy to merge this PR as it is and update it later if required.

@setrofim
Copy link
Collaborator

however for now I'm happy to merge this PR as it is and update it later if required.

Agreed. The naming issue is orthogonal to the particulars of this PR, and is worth putting some thought into to get right; there is no point in blocking this PR on that.

I agree that "trace" is not an appropriate term for everything that's currently being collected via the TraceCollector API. The intention for this is to provide an interface for collection of everything that is not purely numeric measurements.

@qais-yousef
Copy link

In case my comment was seeing as an objection. I'm okay with this change. As I mentioned my comments are probably outside the scope of this patch, so certainly shouldn't block this PR :)

@setrofim setrofim mentioned this pull request Mar 19, 2019
@marcbonnici marcbonnici merged commit 8512f11 into ARM-software:master Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants