Re: [Lxr-general] Finding unreferenced functions
Brought to you by:
ajlittoz
|
From: Michael O'C. <moc...@ya...> - 2005-01-11 13:07:02
|
Here goes:
1st query ('indexes_count'):
select i2.symid, count(*)
from ${prefix}files f, ${prefix}indexes i1, ${prefix}indexes i2
where f.filename like ?
and f.fileid = i1.fileid
and i2.symid = i1.symid
group by i2.symid
2nd query ('usages_count'):
select u.symid, count(*)
from ${prefix}files f, ${prefix}indexes i, ${prefix}useage u
where f.filename like ?
and f.fileid = i.fileid
and u.symid = i.symid
group by u.symid
The bind variable in both cases is a source-code tree path (e.g.
'/src/c/api/%'), this is in order to limit the hit on the database. I also
added an abort before performing the 2nd query if the no. of results from the
1st query is too large for the same reason (I used a limit of 10000).
I guess a join to the releases table is also needed (I'm only storing one
release so I got away without it).
Simultaneous iteration through the results of the 2 queries (stored in separate
perl hashes as symbol => no. of occurrances) allows a check for symbols that
are not referenced other than where they're declared or defined.
Michael
--- Malcolm Box <ma...@br...> wrote:
> Michael O'Connor wrote:
> > Hi,
> >
> > Apologies if this has been asked before. I'm wondering if anyone's tried
> using
> > lxr on a codebase to find unreferenced / unused functions. I tried this on
> a C
> > / C++ codebase I've been working in and found it very useful as part of a
> > clean-up exercise.
>
> I haven't heard of anyone doing this - sounds like a good idea, and a
> possibly useful extension to LXR.
>
> <snip description of method>
>
> > I guess there are better ways of achieving the same result, I'd like to
> hear
> > what people think.
>
> Might be, but I can't think of one off the top of my head. If you could
> send me the SQL you were using I can look to see if it can be built into
> LXR in some way - perhaps by adding a "find unused symbols" search, or
> by showing unused symbols in the ident search?
>
> Cheers,
>
> Malcolm
>
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
|