Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to get the filename without parsing spans #384

Closed
thedrow opened this issue Jul 3, 2016 · 10 comments
Closed

Add an API to get the filename without parsing spans #384

thedrow opened this issue Jul 3, 2016 · 10 comments

Comments

@thedrow
Copy link
Contributor

thedrow commented Jul 3, 2016

Is it possible to get the filename without parsing spans?
If it is, can we expose an API that does that?

@raphink
Copy link
Member

raphink commented Jul 3, 2016

You can get that info without parsing spans if you look in /augeas/files, find a matching path node by removing /files in front.

@thedrow
Copy link
Contributor Author

thedrow commented Jul 4, 2016

Let's document it then 😄

@thedrow
Copy link
Contributor Author

thedrow commented Jul 4, 2016

While useful that doesn't fit my usecase (unless I'm doing something wrong).
I need to get the filename from any path expression that returns a single item.

match /augeas/files//*[path = "/files/etc/hosts/1/ipaddr"]
(no matches)

but

match /augeas/files//*[path = "/files/etc/hosts"]
/augeas/files/etc/hosts = (none)

@raphink
Copy link
Member

raphink commented Jul 4, 2016

That's right, it's not very simple indeed.

@thedrow
Copy link
Contributor Author

thedrow commented Jul 4, 2016

I see that the info struct has a filename char*. Can we use it if we're not enabling spans?
The problem is that parsing spans takes more CPU which isn't always needed.

@lutter
Copy link
Member

lutter commented Jul 21, 2016

The problem with spans is that they make the entire tree take quite a bit more memory; that's the reason why they are disabled by default. How much additional CPU usage do you see ? This will most likely be due to additional allocation (the information that goes into spans is not very hard to collect internally)

If you really can't use spans for your purpose, and since querying the tree directly will be pretty hairy, we could add a call to the API, something like aug_source_file(augeas *, const char *path, char **filename)

How often do you need to query the filename for a node ?

@thedrow
Copy link
Contributor Author

thedrow commented Jul 23, 2016

I query it once per node (and then cache) since I want users to be able to filter by filenames as well.
I see roughly 10% more CPU usage when using spans and when parsing every single file we're already at the 60-90% range.

@lutter
Copy link
Member

lutter commented Feb 23, 2017

I just looked at this again, and thought about how this would be implemented; it occurred to me that adding the XSLT function starts-with would let you do what you want; i.e., you could then say

match /augeas/files//path[starts-with("/files/etc/hosts/1/ipaddr", self::path)]

If you need to do that for every node though, no matter what we do (including the aug_source_file I mentioned above) will not be terribly performant, and you might be better off building an index from match /augeas/files//path and checking nodes against that. That might in the end be the fastest way to achieve that, especially if you traverse the tree top-down, and use that fact that once you found the root for a file, all its children will also be from that file.

@thedrow
Copy link
Contributor Author

thedrow commented Feb 23, 2017

I can cache the function call very easily so it won't be called the next time.
I guess I can also extract the file name from the path.

I think that aug_source_file is missing from the API regardless of my use-case. It'd be useful to add it for others as well.

@lutter
Copy link
Member

lutter commented Feb 24, 2017

Have a look at the PR I just posted and let me know if that would work for you - it introduces a new aug_source API call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants