Coder Social home page Coder Social logo

sglebs / srccheck Goto Github PK

View Code? Open in Web Editor NEW
42.0 42.0 12.0 744 KB

Command-line utilities to check source code for metrics (via SciTools Understand) and fail the build and/or publish trends in SONAR and/or publish histograms, kiviats and scatter plots of these metrics.

Python 100.00%

srccheck's People

Contributors

niclarcipretti avatar sglebs avatar tanquetav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

srccheck's Issues

pls make srccheck generate histograms like srcplot

We have a very large system (6MLOC) which Understand takes many minutes to open. Running srccheck takes 40 minutes on the build machine. Running both srccheck and srcplot will double this time. Is it possible to allow srccheck to also generate these histograms?

handle stats exceptions

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1580, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 964, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 340, in <module>
    main()
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 313, in main
    [violation_count, class_tracked_metrics] = process_class_metrics(db, arguments)
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 222, in process_class_metrics
    return process_generic_metrics(db,cmdline_arguments,"--maxClassMetrics", cmdline_arguments["--classQuery"], _print_class_violation, cmdline_arguments.get("--regexIgnoreClasses", None))
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 197, in process_generic_metrics
    stats_value = lambda_stats(metric_values())
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/statistics.py", line 434, in mode
    'no unique mode; found %d equally common values' % len(table)
statistics.StatisticsError: no unique mode; found 2 equally common values

javascript output does not show locations

====== Routine Metrics that failed the filters ==========
CountLineCode	116	(unnamed_function_1)
CountLineCode	173	(unnamed_function_1)
CountLineCode	166	(unnamed_function_1).nxThemingGenerator
CountLineCode	106	(unnamed_function_1).Route
...........................................
INFO: HIGHEST CountLineCode violator found (violation threshold is 92):CountLineCode	173	(unnamed_function_1)
...........................................
CountParams	15	(unnamed_function_1).(unnamed_function_2)
...........................................
INFO: HIGHEST CountParams violator found (violation threshold is 12):CountParams	15	(unnamed_function_1).(unnamed_function_2)
...........................................
...........................................
INFO: HIGHEST CyclomaticModified non violator found (violation threshold is 5):CyclomaticModified	5	(unnamed_function_1).nxThemingGenerator.rgba
...........................................
...........................................
INFO: HIGHEST MaxNesting non violator found (violation threshold is 2):MaxNesting	2	(unnamed_function_1).nxThemingGenerator.applyContrast
...........................................

AVG, STDDEV etc?

It would be nice to cap not only on absolute maximum values of metrics, but also on other properties that better characterize the whole: average, standard deviation, etc. For example, you may have a Class with 90 as lack of cohesion but it is an outlier. You may want to cap on the Average or the Mean instead.

Metrics with stats cannot be posted to SONAR

*** Response error connecting to http://sonarunj/api/manual_measures: b'{"err_code":400,"err_msg":"Unknown metric: routine_mode:cyclomaticmodified"}'
*** Response error connecting to http://sonarunj/api/manual_measures: b'{"err_code":400,"err_msg":"Unknown metric: class_median:maxinheritancetree"}'
*** Response error connecting to http://sonarunj/api/manual_measures: b'{"err_code":400,"err_msg":"Unknown metric: file_mode:countdeclclass"}'
*** Response error connecting to http://sonarunj/api/manual_measures: b'{"err_code":400,"err_msg":"Unknown metric: file_mode:countdeclsubprogram"}'

Understand metrics

Hi

It is possible to use the metrics files from und as parameters of your application?

fabricating zeroes

the tool is producing metric datapoints with value zero when the metric is absent.

Pls add synthetic metric to count non-stub methods

On Wed, Dec 7, 2016 at 5:20 AM, Marcio Marchini <[email protected]> wrote:
Hi,

   At Nexxera we would like to cap the maximum number of methods in C# classes with my srccheck program. But in the case of C# classes, we want to ignore the Stub methods (automatically generated for properties). Unfortunately CountDeclMethod is also counting the Stub methods generated for setters and getters.

  So… is there a way to count the non-stub methods?

  I see I can check CountDeclPropertyAuto (would count the Stub ones) but what I need is the “NOT Stub ones”.  I believe it would be:  CountDeclMethod - CountDeclPropertyAuto

  Is there such a metric and I am missing it?

  If not… is it possible to add it? Or do I need to add a new synthetic one to srccheck like I did with CountParams at https://github.com/sglebs/srccheck/blob/master/utilities/utils.py#L44 ?

  Thanks!
Hi Marcio,
You would need to write your own for this. Sorry not to have a better answer.

2 : in metric name causes exception

====== Class Metrics that failed the filters  ==========
MEDIAN:MaxInheritanceTree	5	
MODE:MaxInheritanceTree	5	
Traceback (most recent call last):
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 412, in <module>
    main()
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 376, in main
    [violation_count, class_tracked_metrics] = process_class_metrics(db, arguments)
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 301, in process_class_metrics
    return process_generic_metrics(db,cmdline_arguments,"--maxClassMetrics", cmdline_arguments["--classQuery"], _print_class_violation, cmdline_arguments.get("--regexIgnoreClasses", None), "Class")
  File "/Users/mqm/git/srccheck/utilities/srccheck.py", line 197, in process_generic_metrics
    lambda_name, adjusted_metric = metric.split(":")
ValueError: too many values to unpack (expected 2)

json:

{"CountDeclMethod":374,"MODE:CountDeclMethod":10,"MEDIAN:CountDeclMethod":10,"MaxInheritanceTree":11,"MODE:MaxInheritanceTree":4,"MEDIAN:MaxInheritanceTree":4,"AVG:PercentLackOfCohesion":50,"STDDEV:PercentLackOfCohesion:PercentLackOfCohesion":50}

Running from Linux shell without X11 raises exception

Traceback (most recent call last):
File "/usr/bin/srccheck", line 9, in <module>
load_entry_point('srccheck==0.0.7', 'console_scripts', 'srccheck')()
File "/usr/lib/python3.4/site-packages/utilities/srccheck.py", line 358, in main
[violation_count, file_tracked_metrics] = process_file_metrics(db, arguments)
File "/usr/lib/python3.4/site-packages/utilities/srccheck.py", line 287, in process_file_metrics
return process_generic_metrics(db,cmdline_arguments,"--maxFileMetrics", cmdline_arguments["--fileQuery"], _print_file_violation, cmdline_arguments.get("--regexIgnoreFiles", None), "File")
File "/usr/lib/python3.4/site-packages/utilities/srccheck.py", line 261, in process_generic_metrics
scope_name)
File "/usr/lib/python3.4/site-packages/utilities/utils.py", line 83, in save_histogram
plt.figure() # new one, or they will be mixed
File "/usr/lib64/python3.4/site-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/usr/lib64/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib64/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib64/python3.4/tkinter/__init__.py", line 1856, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

pls sort the output by metric name

Currently we traverse the json as a dict. This means unordered (hash map). It would be nice to sort by metric name (process in alphabetical order).

there are 2 kiviat graphs

The code has 2 kiviat implementations. One can't plot negative numbers. How about a single kiviat that can plot negative numbers?

pls add support to skip zeroes

Now with #8 we can see that many datapoints are zero. We would like to compute mean etc discarding these datapoints that are zero.

Predeclared routine prevents scatter plot form being generated

I am trying to generate a scatter plot for pascal routines on a pascal UDB file. At one point, while traversing the routines, it is failing:

ERROR. Missing metric CountLineCode for X Axis (entity=Predeclared Routine (Assigned), file=None)

This is what I use for the query: --routineQuery: 'function ~Unknown ~Unresolved,method ~Unknown ~Unresolved,procedure ~Unknown ~Unresolved,routine ~Unknown ~Unresolved,classmethod ~Unknown ~Unresolved’

Interestingly my query to fetch the container file yields None, so I am in the dark:

entity.ref("definein, declarein")

I don’t have access to the sources. So, I’d like to know what exactly Predeclared means, so that I can decide if I can safely skip everything that is Predeclared in the query.

Thanks a lot in advance!!!

Printing project metrics is very slow

It takes 55 seconds to get project metrics for a UDB from the django sources. I emailed SciTools and got this as answer:

Hi Marcio,
I sent this to the engineers to look at, but I don't know how long it will be before they can look at it. I ran a few tests and there are a few specific metrics that are significantly slower than the others. If you limit it to the ones you need it might speed things up until they can get to this.

Here are the metric retrieval times from a 2.6MLOC Fuzzt C++ project:
AltAvgLineBlank : 0s
AltAvgLineCode : 0s
AltAvgLineComment : 0s
AltCountLineBlank : 0s
AltCountLineCode : 1s
AltCountLineComment : 0s
AvgCyclomatic : 1s
AvgCyclomaticModified : 1s
AvgCyclomaticStrict : 1s
AvgEssential : 1s
AvgLine : 0s
AvgLineBlank : 1s
AvgLineCode : 0s
AvgLineComment : 0s
CountDeclClass : 0s
CountDeclClassMethod : 1s
CountDeclClassVariable : 0s
CountDeclFile : 0s
CountDeclFileCode : 1s
CountDeclFileHeader : 0s
CountDeclFunction : 0s
CountDeclInstanceMethod : 1s
CountDeclInstanceVariable: 0s
CountDeclInstanceVariablePrivate: 1s
CountDeclInstanceVariableProtected: 1s
CountDeclInstanceVariablePublic: 0s
CountDeclMethod : 1s
CountDeclMethodAll : 24s
CountDeclMethodConst : 1s
CountDeclMethodFriend : 1s
CountDeclMethodPrivate : 0s
CountDeclMethodProtected : 1s
CountDeclMethodPublic : 0s
CountLine : 1s
CountLineBlank : 0s
CountLineCode : 0s
CountLineCodeDecl : 0s
CountLineCodeExe : 0s
CountLineComment : 0s
CountLineInactive : 1s
CountLinePreprocessor : 0s
CountPath : 1s
CountPathLog : 0s
CountSemicolon : 0s
CountStmt : 0s
CountStmtDecl : 1s
CountStmtEmpty : 0s
CountStmtExe : 0s
Cyclomatic : 1s
CyclomaticModified : 1s
CyclomaticStrict : 1s
Essential : 2s
Knots : 1s
MaxCyclomatic : 1s
MaxCyclomaticModified : 1s
MaxCyclomaticStrict : 1s
MaxEssential : 3s
MaxEssentialKnots : 2s
MaxInheritanceTree : 12s
MaxNesting : 6s
MinEssentialKnots : 1s
RatioCommentToCode : 0s
SumCyclomatic : 3s
SumCyclomaticModified : 4s
SumCyclomaticStrict : 3s
SumEssential : 3s
Total Run Time: 89 seconds

Maybe we need to support a flag to pass names of project metrics to skip when printing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.