Help me improve my code metric visualizer

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Sagekilla
Posts: 382
Joined: Fri Aug 21, 2009 1:02 am UTC
Location: Long Island, NY

Help me improve my code metric visualizer

Postby Sagekilla » Wed Apr 11, 2012 12:19 pm UTC

I just spent 10 minutes writing up this post before and the forums decided to log out me out and
delete my post, so here's the short version until I write it up again.


Background
I wrote a tool for visualizing code metrics of a project that has some source control bindings. It's
geared towards .NET (uses the MSVC static code analyzer and only works on .sln files, etc.). The
first part is the static code analyzer which takes every single revision of a project (from subversion),
builds it, then performs the static code analysis via MS' tool.

The second part is a web interface for viewing the data. It basically just takes in all the xml analysis
files and lets you view the data in a time series (where time is the revision technically).

I did this because code metrics become interesting when you view them over the full history of a project.
For any one revision their kind of useless but in this context you can glean some useful information.

Question
I can display the values of any given code metric that's provided as a function of revision number. This is
possible on a per assembly, namespace, type, and method level. I can only display this for a single one
of those items though.

Anyone have any ideas for any other interesting ways I can visualize this data? The only other one I could think
of (too tired to think of more right now) is displaying a given metric for more than one object within the
same grouping (e.g. cyclomatic complexity of types A and B with respect to revision number).

I was thinking of adding more functionality, cleaning it up, and open sourcing the code. I just feel like I need to
add more functionality because you really can't do a lot with it in it's current state.


Other notes: I'll see if I can get a simple version of this online for people to gawk at. I still have to fix a lot of
stupid bugs that I kind of left in when I was prototyping the tool
http://en.wikipedia.org/wiki/DSV_Alvin#Sinking wrote:Researchers found a cheese sandwich which exhibited no visible signs of decomposition, and was in fact eaten.

User avatar
freakish777
Posts: 354
Joined: Wed Jul 13, 2011 2:14 pm UTC

Re: Help me improve my code metric visualizer

Postby freakish777 » Wed Apr 11, 2012 1:59 pm UTC

It sounds like you're doing something similar to a Continuous Integration/Automated Build project?

You could check out Hudson/Jenkins for some inspiration maybe? Or perhaps decide "Why not extend Jenkins with what I was working on instead?"

Other metrics to maybe keep track of (not necessarily from MS code analysis tool):

Time it takes to build (presumably this increases with each revision unless you have a specific refactoring project).
Time it takes to deploy (for websites, this could be helpful for businesses, it lets them know how long their IT people will need to get that version deployed to their production web servers).
Percentage of builds completed successfully for a given revision (stability of revision, graphed over time you want to see percentage go up so you know you have a stable product, this is probably more for Continuous Integration projects).
If you can tie into a Defect/Incident system (maybe TFS) and pull the number of bugs/defects reported against a release (again might be useful for businesses, if their first build of a revision has some large number of defects X, caught by the testers, then the manager knows "I need to let the business know that this release is in jeopardy of being delayed").
After it's built run appropriate unit tests for that revision and display number passed, failed, etc (TFS Build Services has a fairly easy way to do this if you're using it).
Percentage Code covered by unit tests over time.
Number of compiler warnings/errors over time.
Percentage of lines that are comments?



Basically put yourself in a manager's shoes and figure out, "If I'm responsible for my X person team delivering a quality product on time, what metrics help me do my job better?" I'm not sure I've done that very well with the suggestions I've given, but that's probably what would make your project the most useful.

Sagekilla
Posts: 382
Joined: Fri Aug 21, 2009 1:02 am UTC
Location: Long Island, NY

Re: Help me improve my code metric visualizer

Postby Sagekilla » Wed Apr 11, 2012 3:15 pm UTC

freakish777 wrote:It sounds like you're doing something similar to a Continuous Integration/Automated Build project?


I suppose it is some sort of CI system. It's ridiculously brute force though. You run it by hand and it tries to perform the SCA
for each revision:

Code: Select all

for (int revision = start; revision < end; revision++)
{
    UpdateToRevision(revision);
    InstallPackages();
    BuildProjects();
    PerformAnalysis(revision);
}


I mostly wrote it because I was curious how various aspects of the change in time. Granted, it's a fairly limited set of things.

You could check out Hudson/Jenkins for some inspiration maybe? Or perhaps decide "Why not extend Jenkins with what I was working on instead?"


Well, that's new to me. I never heard of this before.

Time it takes to build (presumably this increases with each revision unless you have a specific refactoring project).

I think I can actually do this. I can easily time the checkout process too.

Time it takes to deploy (for websites, this could be helpful for businesses, it lets them know how long their IT people will need to get that version deployed to their production web servers).

A little tricky, but I can give a rough metric if I set up a local IIS sever and script it to publish to the server for each build.

Percentage of builds completed successfully for a given revision (stability of revision, graphed over time you want to see percentage go up so you know you have a stable product, this is probably more for Continuous Integration projects).

This would be easy to do because the Build function actually returns whether the build was a success :)

If you can tie into a Defect/Incident system (maybe TFS) and pull the number of bugs/defects reported against a release (again might be useful for businesses, if their first build of a revision has some large number of defects X, caught by the testers, then the manager knows "I need to let the business know that this release is in jeopardy of being delayed").

Interesting idea but I don't have any data points to try this one out.

After it's built run appropriate unit tests for that revision and display number passed, failed, etc (TFS Build Services has a fairly easy way to do this if you're using it).

I can do this via NUnit for some of my projects. Would probably be easier if I was using TFS like you said though.

Percentage Code covered by unit tests over time.

Same as above

Number of compiler warnings/errors over time.

No idea how I can get access to this. I actually wanted to gain access to this so I could display this information. No idea how yet though.

Percentage of lines that are comments?

I think I can write a powershell script to do this

Neat ideas though, thanks! I'll try some of the easier ones out in the mean time. I need to see if I can also make the actual report front end
a bit general -- all it can do is show a plot of one metric for one subsystem of a project. On it's own, not very useful. Plotting arbitrary things
would probably come in handy though.
http://en.wikipedia.org/wiki/DSV_Alvin#Sinking wrote:Researchers found a cheese sandwich which exhibited no visible signs of decomposition, and was in fact eaten.

User avatar
freakish777
Posts: 354
Joined: Wed Jul 13, 2011 2:14 pm UTC

Re: Help me improve my code metric visualizer

Postby freakish777 » Wed Apr 11, 2012 6:17 pm UTC

Hudson/Jenkins is some company's automated build project. One is the (I think) open source project (or at the very least free version) that has since been left to "community support" and the other is the now supported (I think paid) version.

I think the story is that it was an Open Source project, and some company purchased the source code from the people who had been creating it up until that point. As a result, the original is still open source (since it was on an open source license), and the paid version is a newer branch.

It's got some functionality for viewing a dashboard with graphs and statistics on different things. I'm not responsible for builds at the moment, so I haven't looked into it that much (we use it at my current employer), when I was responsible for builds (for a former employer) we used TFS Build Services.

Speaking of TFS Builds Services, if your school's MSDN license they give you (that you mentioned from the Creating Web Sites thread) covers VS Ultimate, you should be able to download TFS, I'd highly recommend trying it out (when you've got some free time). It does take a while to get used to TFS's Build Definition "structure/language" (sorry can't think of a better term), but it's actually pretty powerful in what it allows you to do (like calling any executable you want to, whenever you want, before, during or after, the build occurs). You could also potentially get rid of some of the "by hand" stuff, like specifying a job that says "execute the following Build Definition for each and every revision each night at 1am, then push data to my dashboard site to display it" instead of requiring a user to pick/specify which revision they want.

Even if TFS doesn't mesh well in your current project, having some experience with it will look good to employers. Almost every Microsoft shop uses, has used, or is considering using, it in some capacity (whether it's for Source Control, Automated Builds, Work Assignments, Bug Tracking, Design, Analysis, etc is a different story though, I'm mostly familiar with developing automated builds, and just using it for Source Control).


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests