SlideShare a Scribd company logo
Bug prediction
based on your code history
Alexey Tokar
VP of Engineering @ WorldAPP
SDLC
2
Software
Development
Life Cycle
PHASE 2
Design
PHASE 1
Requirements
analysis
PHASE 3
Development
PHASE 5
Maintenance
PHASE 4
Testing
Zoom in to quality control
● static code analyzers find non conceptual issues
● automated tests cover predefined scenarios
● code review are aimed on sharing and controlling best practices and less than
10% of the discussions discover logical issues.
● and, finally, QA has no idea which parts of a system could be affected by a
code change, neither do a programmer
3
20
bugs in a production environment
per week
4
Let's try to guess common patterns
● a tired engineer makes more mistakes
● the more an engineer knows about certain module the fewer bugs (s)he will
produce
● small changes have fewer bugs than long listings
● some parts of the system are more complicated than another, so the risk of get
a bug increases
● huge changes in a short period of time contains more bugs (done in a hurry)
5
What tools do we have across SDLC?
6
● ticket types
● action history
● exact code changes
● author of modifications
● class complexity
● code metrics
Hypothesis
If we know that certain commit has fixed a bug, than we know that a commit, when
the changed lines were introduced, did contain a bug.
7
Author: John
public int sum( int a, int b )
{
return a + b;
}
C
Author: Bob
public int sum( int a, int b )
{
return a * b;
}
BA
public int sum( int a, int b )
{
return a + b;
}
Algorithm of metrics collection
● Export all tasks from Jira to inmemory dictionary
● For each commit run a backtrace to mark it as buggy, fixing or regular
● Collect all meaningful data about the commit:
○ Month of year, Day of week, Hour of day, Who, How many lines and files, Which classes and
packages, Class complexity and amount of notices, How long a task is in progress
● Put a line with the data to Attribute-Relation File Format (ARFF) file
8
Getting educated. WEKA
Waikato Environment for Knowledge Analysis - is a suite of machine learning
software written in Java, developed at the University of Waikato, New Zealand.
● Parsers
● Classifiers
● Training/test splits
9
WEKA challenges
● Convert your data to corresponding vectors
● Choose proper data transformers
● Select and tweak desired Classifiers
● Run experiments and adjust your settings
Good materials about WEKA for beginners:
● How to Run Your First Classifier in Weka
● Data mining with WEKA, Part 2. Classification and clustering
● Document Classification using WEKA
10
Decision Tree
Ease of results interpretation
Any data can be fed to the method
Can work with scalars and intervals
11
Decision Tree
12
Changed less
than 300 lines?Changed more
than 50 lines?
Author is Bob?
Author is John?
Has no bugs :)
Has no bugs :)
Is it Friday?
Has no bugs :)
Has a bug :(
Has no bugs :)
Has a bug :(
● John never has bugs!
● Everybody except John and Bob has bugs on Friday.
● Bob has bugs only if he changed more than 300 lines of code.
Decision Tree
13
The simplest method for building a tree is ID3 (Iterative Dichotomiser 3*).
Build steps:
● Find an attribute with lowest entropy (or largest information gain)
● Split the data set by the found attribute
● Recursively build a tree for each of the subsets
* fates of ID2 and ID1 are lost in history
Naive Bayes
classifier
≈80% accuracy*
Simple implementation
Easy to understand
14
Naive Bayes classifier
15
Naive Bayes classifier
16
30% of all commits with bugs were done by Bob P(Bob|bug)
10% of all commits without bugs were done by Bob P(Bob|~bug)
40% of all commits have bugs P(bug)
60% of all commits have no bugs P(~bug)
What probability that next commit from Bob will have a bug?
P(bug|Bob)
Support Vector
Machine
Better quality of results
The model is based on relations in data
Sounds fancy :)
17
Support Vector Machine
18
Support Vector Machine
19
Kernel trick
http://mechanoid.kiev.ua/ml-svm.html
WEKA output
results 20
Output results example (Bayes)
Correctly Classified Instances 14381 77.4755 %
Incorrectly Classified Instances 4181 22.5245 %
Kappa statistic 0.3085
Mean absolute error 0.2637
Root mean squared error 0.3963
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure ROC Area Class
0.856 0.544 0.861 0.856 0.858 0.761 false
0.456 0.144 0.444 0.456 0.45 0.761 true
Weighted Avg. 0.775 0.463 0.777 0.775 0.776 0.761
=== Confusion Matrix ===
a b <-- classified as
12670 2140 | a = false
2041 1711 | b = true
21
Output results example (RandomTree)
form < 1
| Registration < 1
| | alexey.tokar@worldapp.com < 1
| | | tpl < 1
| | | | filters < 1
| | | | | frontend@worldapp.com < 1
| | | | | | middlejava@worldapp.com < 1 : false
| | | | | | middlejava@worldapp.com >= 1 : true
| | | | | frontend@worldapp.com >= 1
| | | | | | ObjectDesign < 1 : true
| | | | | | ObjectDesign >= 1 : false
| | | | filters >= 1 : false
| | | tpl >= 1 : true
| | alexey.tokar@worldapp.com >= 1
| | | bundle < 1
| | | | xmail < 1
| | | | | general < 1
| | | | | | dataimport < 1
| | | | | | | oracle < 1 : false
| | | | | | | oracle >= 1 : true
| | | | | | dataimport >= 1 : false
| | | | | general >= 1
| | | | | | filesedited < 2 : false
| | | | | | filesedited >= 2 : true
| | | | xmail >= 1 : false
| | | bundle >= 1 : true
| Registration >= 1 : true
22
Integration example
TL;DR: we use GitLab web-hooks and HipChat.
* a long story about SDLC improvements with help of IM bot and a set of
integrations will be available in a week at XPDays conference.
23
Summary
● we found that certain classes are too complex as almost every change will end
up with a bug
● some of engineers shouldn't open some packages at all (or at least we should
properly educate them)
● there are still many rooms for improvements (overlapping hiding commits,
another meaningful features, more accurate code history, etc)
● It does not show you where the error exists. But you will be able to analyze a
commit more carefully.
● It was fun! :)
24
Questions?
Alexey@Tokar.net.ua
VP of Engineering @ WorldAPP
25

More Related Content

PPTX
Bug prediction + sdlc automation
PPTX
Resource Leaks in Java
PPTX
OSS Java Analysis - What You Might Be Missing
PPTX
Finding Defects in C#: Coverity vs. FxCop
PPTX
Understanding software engineering with equations
ODP
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
PPTX
The Psychology of C# Analysis
PPTX
Random testing
Bug prediction + sdlc automation
Resource Leaks in Java
OSS Java Analysis - What You Might Be Missing
Finding Defects in C#: Coverity vs. FxCop
Understanding software engineering with equations
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
The Psychology of C# Analysis
Random testing

What's hot (20)

PPTX
Utility of Test Coverage Metrics in TDD
PDF
Static Analysis of Your OSS Project with Coverity
PPTX
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
PPTX
Generating unit tests based on user logs
PPTX
Static Analysis Primer
PPTX
Google, quality and you
PPTX
DockerCon SF 2019 - Observability Workshop
PDF
Test Smarter: Efficient Coverage Metrics That Won't Leave You Exposed
PPTX
Continous testing for grails
PPTX
DockerCon SF 2019 - TDD is Dead
PPT
Crowd debugging (FSE 2015)
PPT
Automated Unit Testing and TDD
PDF
Improving the accuracy and reliability of data analysis code
PPTX
DevBeat 2013 - Developer-first Security
PPTX
Random testing & prototyping
PDF
Random testing
PPTX
Static analysis tools as the best friend of QA
PDF
qe_camp_17
PPTX
Code Coverage and Test Suite Effectiveness: Empirical Study with Real Bugs in...
PPTX
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Utility of Test Coverage Metrics in TDD
Static Analysis of Your OSS Project with Coverity
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
Generating unit tests based on user logs
Static Analysis Primer
Google, quality and you
DockerCon SF 2019 - Observability Workshop
Test Smarter: Efficient Coverage Metrics That Won't Leave You Exposed
Continous testing for grails
DockerCon SF 2019 - TDD is Dead
Crowd debugging (FSE 2015)
Automated Unit Testing and TDD
Improving the accuracy and reliability of data analysis code
DevBeat 2013 - Developer-first Security
Random testing & prototyping
Random testing
Static analysis tools as the best friend of QA
qe_camp_17
Code Coverage and Test Suite Effectiveness: Empirical Study with Real Bugs in...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Ad

Similar to Bug prediction based on your code history (20)

PPTX
"Making .NET Application Even Faster", Sergey Teplyakov.pptx
PDF
Triantafyllia Voulibasi
PPTX
Test Drive Dirven Driver HAHAahhaha.pptx
PDF
Making Strongly-typed NETCONF Usable
PPT
Nag software For Finance
PPT
The Magic Of Application Lifecycle Management In Vs Public
PPTX
API automation with JMeter + Bamboo CI
PDF
Become Jythonic in FDMEE (KSCOPE15)
PDF
End-end tests as first class citizens - SeleniumConf 2020
PDF
Workshop: Delivering chnages for applications and databases
DOC
Netw 208 Success Begins / snaptutorial.com
PPTX
Ship code like a keptn
DOCX
Cnd labguide
PPT
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
PPTX
Software cost estimation
PDF
Keeping code clean
PDF
Extreme programming talk wise consulting - www.talkwiseconsulting
PDF
Extreme Programming Talk Wise Consulting Www.Talkwiseconsulting
PPTX
Bots on guard of sdlc
PPTX
Issre2014 test defectprediction
"Making .NET Application Even Faster", Sergey Teplyakov.pptx
Triantafyllia Voulibasi
Test Drive Dirven Driver HAHAahhaha.pptx
Making Strongly-typed NETCONF Usable
Nag software For Finance
The Magic Of Application Lifecycle Management In Vs Public
API automation with JMeter + Bamboo CI
Become Jythonic in FDMEE (KSCOPE15)
End-end tests as first class citizens - SeleniumConf 2020
Workshop: Delivering chnages for applications and databases
Netw 208 Success Begins / snaptutorial.com
Ship code like a keptn
Cnd labguide
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Software cost estimation
Keeping code clean
Extreme programming talk wise consulting - www.talkwiseconsulting
Extreme Programming Talk Wise Consulting Www.Talkwiseconsulting
Bots on guard of sdlc
Issre2014 test defectprediction
Ad

More from Alexey Tokar (7)

PPTX
Graph theory basics
PPTX
Fantastic caches and where to find them
PPTX
Conway's transformation
PPTX
Extend your REST API
PPTX
Найти иглоку в стоге сена
PPTX
MongoDB в продакшен - миф или реальность?
PPTX
когда тексты не только слова
Graph theory basics
Fantastic caches and where to find them
Conway's transformation
Extend your REST API
Найти иглоку в стоге сена
MongoDB в продакшен - миф или реальность?
когда тексты не только слова

Recently uploaded (20)

PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PPTX
Welding lecture in detail for understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Mechanical Engineering MATERIALS Selection
PPTX
web development for engineering and engineering
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Construction Project Organization Group 2.pptx
PDF
composite construction of structures.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CH1 Production IntroductoryConcepts.pptx
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing
Welding lecture in detail for understanding
Foundation to blockchain - A guide to Blockchain Tech
Lecture Notes Electrical Wiring System Components
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mechanical Engineering MATERIALS Selection
web development for engineering and engineering
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CYBER-CRIMES AND SECURITY A guide to understanding
R24 SURVEYING LAB MANUAL for civil enggi
Construction Project Organization Group 2.pptx
composite construction of structures.pdf

Bug prediction based on your code history

  • 1. Bug prediction based on your code history Alexey Tokar VP of Engineering @ WorldAPP
  • 2. SDLC 2 Software Development Life Cycle PHASE 2 Design PHASE 1 Requirements analysis PHASE 3 Development PHASE 5 Maintenance PHASE 4 Testing
  • 3. Zoom in to quality control ● static code analyzers find non conceptual issues ● automated tests cover predefined scenarios ● code review are aimed on sharing and controlling best practices and less than 10% of the discussions discover logical issues. ● and, finally, QA has no idea which parts of a system could be affected by a code change, neither do a programmer 3
  • 4. 20 bugs in a production environment per week 4
  • 5. Let's try to guess common patterns ● a tired engineer makes more mistakes ● the more an engineer knows about certain module the fewer bugs (s)he will produce ● small changes have fewer bugs than long listings ● some parts of the system are more complicated than another, so the risk of get a bug increases ● huge changes in a short period of time contains more bugs (done in a hurry) 5
  • 6. What tools do we have across SDLC? 6 ● ticket types ● action history ● exact code changes ● author of modifications ● class complexity ● code metrics
  • 7. Hypothesis If we know that certain commit has fixed a bug, than we know that a commit, when the changed lines were introduced, did contain a bug. 7 Author: John public int sum( int a, int b ) { return a + b; } C Author: Bob public int sum( int a, int b ) { return a * b; } BA public int sum( int a, int b ) { return a + b; }
  • 8. Algorithm of metrics collection ● Export all tasks from Jira to inmemory dictionary ● For each commit run a backtrace to mark it as buggy, fixing or regular ● Collect all meaningful data about the commit: ○ Month of year, Day of week, Hour of day, Who, How many lines and files, Which classes and packages, Class complexity and amount of notices, How long a task is in progress ● Put a line with the data to Attribute-Relation File Format (ARFF) file 8
  • 9. Getting educated. WEKA Waikato Environment for Knowledge Analysis - is a suite of machine learning software written in Java, developed at the University of Waikato, New Zealand. ● Parsers ● Classifiers ● Training/test splits 9
  • 10. WEKA challenges ● Convert your data to corresponding vectors ● Choose proper data transformers ● Select and tweak desired Classifiers ● Run experiments and adjust your settings Good materials about WEKA for beginners: ● How to Run Your First Classifier in Weka ● Data mining with WEKA, Part 2. Classification and clustering ● Document Classification using WEKA 10
  • 11. Decision Tree Ease of results interpretation Any data can be fed to the method Can work with scalars and intervals 11
  • 12. Decision Tree 12 Changed less than 300 lines?Changed more than 50 lines? Author is Bob? Author is John? Has no bugs :) Has no bugs :) Is it Friday? Has no bugs :) Has a bug :( Has no bugs :) Has a bug :( ● John never has bugs! ● Everybody except John and Bob has bugs on Friday. ● Bob has bugs only if he changed more than 300 lines of code.
  • 13. Decision Tree 13 The simplest method for building a tree is ID3 (Iterative Dichotomiser 3*). Build steps: ● Find an attribute with lowest entropy (or largest information gain) ● Split the data set by the found attribute ● Recursively build a tree for each of the subsets * fates of ID2 and ID1 are lost in history
  • 14. Naive Bayes classifier ≈80% accuracy* Simple implementation Easy to understand 14
  • 16. Naive Bayes classifier 16 30% of all commits with bugs were done by Bob P(Bob|bug) 10% of all commits without bugs were done by Bob P(Bob|~bug) 40% of all commits have bugs P(bug) 60% of all commits have no bugs P(~bug) What probability that next commit from Bob will have a bug? P(bug|Bob)
  • 17. Support Vector Machine Better quality of results The model is based on relations in data Sounds fancy :) 17
  • 19. Support Vector Machine 19 Kernel trick http://mechanoid.kiev.ua/ml-svm.html
  • 21. Output results example (Bayes) Correctly Classified Instances 14381 77.4755 % Incorrectly Classified Instances 4181 22.5245 % Kappa statistic 0.3085 Mean absolute error 0.2637 Root mean squared error 0.3963 === Detailed Accuracy By Class === TP Rate FP Rate Precision Recall F-Measure ROC Area Class 0.856 0.544 0.861 0.856 0.858 0.761 false 0.456 0.144 0.444 0.456 0.45 0.761 true Weighted Avg. 0.775 0.463 0.777 0.775 0.776 0.761 === Confusion Matrix === a b <-- classified as 12670 2140 | a = false 2041 1711 | b = true 21
  • 22. Output results example (RandomTree) form < 1 | Registration < 1 | | alexey.tokar@worldapp.com < 1 | | | tpl < 1 | | | | filters < 1 | | | | | frontend@worldapp.com < 1 | | | | | | middlejava@worldapp.com < 1 : false | | | | | | middlejava@worldapp.com >= 1 : true | | | | | frontend@worldapp.com >= 1 | | | | | | ObjectDesign < 1 : true | | | | | | ObjectDesign >= 1 : false | | | | filters >= 1 : false | | | tpl >= 1 : true | | alexey.tokar@worldapp.com >= 1 | | | bundle < 1 | | | | xmail < 1 | | | | | general < 1 | | | | | | dataimport < 1 | | | | | | | oracle < 1 : false | | | | | | | oracle >= 1 : true | | | | | | dataimport >= 1 : false | | | | | general >= 1 | | | | | | filesedited < 2 : false | | | | | | filesedited >= 2 : true | | | | xmail >= 1 : false | | | bundle >= 1 : true | Registration >= 1 : true 22
  • 23. Integration example TL;DR: we use GitLab web-hooks and HipChat. * a long story about SDLC improvements with help of IM bot and a set of integrations will be available in a week at XPDays conference. 23
  • 24. Summary ● we found that certain classes are too complex as almost every change will end up with a bug ● some of engineers shouldn't open some packages at all (or at least we should properly educate them) ● there are still many rooms for improvements (overlapping hiding commits, another meaningful features, more accurate code history, etc) ● It does not show you where the error exists. But you will be able to analyze a commit more carefully. ● It was fun! :) 24

Editor's Notes

  • #5: Having all these activities we still get up to 20 bugs during a week in production environments reported by our customers
  • #7: (it is worth to mention that accuracy is a must have for future improvements) crossreferences
  • #8: Боб изменил функцию Джон прислал коммит с текстом fixed Отмечаем такой коммит как Fixing Находим измененные строки Делаем Blame и находим когда они были представлены Отмечаем такой коммит как Buggy
  • #10: As it is a Java conference I should took a java based library for that ;)
  • #15: classifier based on applying Bayes' theorem with strong (naive) independence assumptions between the features.
  • #19: An SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall.