cat_tree 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/README.md +25 -0
- data/cat_tree.gemspec +1 -1
- data/lib/cat_tree.rb +1 -0
- data/lib/cat_tree/config.rb +7 -0
- data/lib/cat_tree/observer.rb +18 -11
- data/lib/cat_tree/version.rb +1 -1
- data/spec/db_dump.sql +102 -0
- data/spec/prepare.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca667a9a4b6bdef6808ca2a251b4e0d38e2279a5
|
4
|
+
data.tar.gz: 990e3a9e31282d8a1dafc49dbfc9cd9bca9af7aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef6bc7eb67daa6b4e1c0a8cebadd44e9024ba6e2be3157b7e7253404fa56c5f936112089682b10c7492abc7b09ad4a893e0ff957226d252c5ebeb2635c537eb
|
7
|
+
data.tar.gz: 14e749d0d9771f6b43f2386f3909d5e2fa5f6ceddab2a8fa88fa15b46dfd07b725448ad753eed0b7b732e6eb26227471580942c748ce35ae76615540d12907b1
|
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script:
|
3
|
+
- mysql -e 'create database cat_tree_test;'
|
4
|
+
- "bundle exec ruby spec/prepare.rb"
|
5
|
+
rvm:
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- 2.1.2
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/rails3.gemfile
|
11
|
+
- gemfiles/rails40.gemfile
|
12
|
+
- gemfiles/rails41.gemfile
|
13
|
+
notifications:
|
14
|
+
emails:
|
15
|
+
- tsukasa.oishi@gmail.com
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# CatTree
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/cat_tree.svg)](http://badge.fury.io/rb/cat_tree) [![Build Status](https://travis-ci.org/tsukasaoishi/cat_tree.svg?branch=master)](https://travis-ci.org/tsukasaoishi/cat_tree) [![Code Climate](https://codeclimate.com/github/tsukasaoishi/cat_tree/badges/gpa.svg)](https://codeclimate.com/github/tsukasaoishi/cat_tree)
|
4
|
+
|
3
5
|
CatTree monitors ActiveRecord objects in development environment the number of objects and the number of same objects.
|
4
6
|
It helps you decrease waste of memory and increase application performance.
|
5
7
|
|
@@ -11,6 +13,29 @@ It helps you decrease waste of memory and increase application performance.
|
|
11
13
|
You can be used by simply installing.
|
12
14
|
CatTree notifies the result analyzing ActiveRecord objects. Look at the Rails log when Rails action finished.
|
13
15
|
|
16
|
+
```
|
17
|
+
Started GET "/top" for xxx.xxx.xxx.xxx at yyyy
|
18
|
+
Processing by TopController#index as HTML
|
19
|
+
Parameters: {}
|
20
|
+
....
|
21
|
+
|
22
|
+
[CatTree]
|
23
|
+
ActiveRecord::Base: 102
|
24
|
+
Same objects:
|
25
|
+
User(id:12): 2
|
26
|
+
|
27
|
+
Completed 200 OK in 1121.8ms (Views: 899.0ms | ActiveRecord: 222.8ms)
|
28
|
+
```
|
29
|
+
|
30
|
+
If you need backtrace of same objects,
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
CatTree::Config.backtrace = true
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
then
|
38
|
+
|
14
39
|
```
|
15
40
|
Started GET "/top" for xxx.xxx.xxx.xxx at yyyy
|
16
41
|
Processing by TopController#index as HTML
|
data/cat_tree.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'activerecord', '>= 3.2.0', '< 4.2'
|
22
22
|
spec.add_dependency 'activesupport', '>= 3.2.0', '< 4.2'
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
24
|
+
spec.add_development_dependency "bundler", "< 1.8", ">= 1.6"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", '~> 2.14'
|
27
27
|
spec.add_development_dependency 'appraisal', '~> 1.0'
|
data/lib/cat_tree.rb
CHANGED
data/lib/cat_tree/observer.rb
CHANGED
@@ -16,14 +16,7 @@ module CatTree
|
|
16
16
|
key = "#{object.class.name}(id:#{object.id})"
|
17
17
|
@ar_base[key] ||= {:count => 0, :callers => []}
|
18
18
|
@ar_base[key][:count] += 1
|
19
|
-
if
|
20
|
-
root_path = Rails.root.to_s
|
21
|
-
root_path += "/" unless root_path.last == "/"
|
22
|
-
cal = caller.select{|c| c =~ %r!#{root_path}(app|lib)/!}
|
23
|
-
@ar_base[key][:callers] << cal unless cal.empty?
|
24
|
-
else
|
25
|
-
@ar_base[key][:callers] << caller
|
26
|
-
end
|
19
|
+
record_backtrace(@ar_base[key][:callers]) if Config.backtrace
|
27
20
|
end
|
28
21
|
|
29
22
|
def ar_base_count
|
@@ -44,6 +37,17 @@ module CatTree
|
|
44
37
|
|
45
38
|
private
|
46
39
|
|
40
|
+
def record_backtrace(callers)
|
41
|
+
if defined?(Rails)
|
42
|
+
root_path = Rails.root.to_s
|
43
|
+
root_path += "/" unless root_path.last == "/"
|
44
|
+
cal = caller.select{|c| c =~ %r!#{root_path}(app|lib)/!}
|
45
|
+
callers << cal unless cal.empty?
|
46
|
+
else
|
47
|
+
callers << caller
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
47
51
|
def output_message
|
48
52
|
return if @ar_base.empty?
|
49
53
|
|
@@ -54,9 +58,12 @@ module CatTree
|
|
54
58
|
msg << " Same objects:"
|
55
59
|
same_objects.keys.sort_by{|k| same_objects[k][:count]}.reverse.each do |key|
|
56
60
|
msg << " #{key}:\t#{same_objects[key][:count]}"
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
|
62
|
+
if Config.backtrace
|
63
|
+
same_objects[key][:callers].each do |cal|
|
64
|
+
cal.each{|c| msg << " #{c}"}
|
65
|
+
msg << ""
|
66
|
+
end
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
data/lib/cat_tree/version.rb
CHANGED
data/spec/db_dump.sql
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
-- MySQL dump 10.13 Distrib 5.6.19, for osx10.9 (x86_64)
|
2
|
+
--
|
3
|
+
-- Host: localhost Database: cat_tree_test
|
4
|
+
-- ------------------------------------------------------
|
5
|
+
-- Server version 5.6.19
|
6
|
+
|
7
|
+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
8
|
+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
9
|
+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
10
|
+
/*!40101 SET NAMES utf8 */;
|
11
|
+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
12
|
+
/*!40103 SET TIME_ZONE='+00:00' */;
|
13
|
+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
14
|
+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
15
|
+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
16
|
+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
17
|
+
|
18
|
+
--
|
19
|
+
-- Table structure for table `articles`
|
20
|
+
--
|
21
|
+
|
22
|
+
DROP TABLE IF EXISTS `articles`;
|
23
|
+
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
24
|
+
/*!40101 SET character_set_client = utf8 */;
|
25
|
+
CREATE TABLE `articles` (
|
26
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
27
|
+
`user_id` int(11) DEFAULT NULL,
|
28
|
+
`title` varchar(255) DEFAULT NULL,
|
29
|
+
`body` text,
|
30
|
+
`created_at` datetime NOT NULL,
|
31
|
+
`updated_at` datetime NOT NULL,
|
32
|
+
PRIMARY KEY (`id`)
|
33
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
34
|
+
/*!40101 SET character_set_client = @saved_cs_client */;
|
35
|
+
|
36
|
+
--
|
37
|
+
-- Dumping data for table `articles`
|
38
|
+
--
|
39
|
+
|
40
|
+
LOCK TABLES `articles` WRITE;
|
41
|
+
/*!40000 ALTER TABLE `articles` DISABLE KEYS */;
|
42
|
+
/*!40000 ALTER TABLE `articles` ENABLE KEYS */;
|
43
|
+
UNLOCK TABLES;
|
44
|
+
|
45
|
+
--
|
46
|
+
-- Table structure for table `schema_migrations`
|
47
|
+
--
|
48
|
+
|
49
|
+
DROP TABLE IF EXISTS `schema_migrations`;
|
50
|
+
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
51
|
+
/*!40101 SET character_set_client = utf8 */;
|
52
|
+
CREATE TABLE `schema_migrations` (
|
53
|
+
`version` varchar(255) NOT NULL,
|
54
|
+
UNIQUE KEY `unique_schema_migrations` (`version`)
|
55
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
56
|
+
/*!40101 SET character_set_client = @saved_cs_client */;
|
57
|
+
|
58
|
+
--
|
59
|
+
-- Dumping data for table `schema_migrations`
|
60
|
+
--
|
61
|
+
|
62
|
+
LOCK TABLES `schema_migrations` WRITE;
|
63
|
+
/*!40000 ALTER TABLE `schema_migrations` DISABLE KEYS */;
|
64
|
+
INSERT INTO `schema_migrations` VALUES ('20140918010600'),('20140918010659');
|
65
|
+
/*!40000 ALTER TABLE `schema_migrations` ENABLE KEYS */;
|
66
|
+
UNLOCK TABLES;
|
67
|
+
|
68
|
+
--
|
69
|
+
-- Table structure for table `users`
|
70
|
+
--
|
71
|
+
|
72
|
+
DROP TABLE IF EXISTS `users`;
|
73
|
+
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
74
|
+
/*!40101 SET character_set_client = utf8 */;
|
75
|
+
CREATE TABLE `users` (
|
76
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
77
|
+
`name` varchar(255) DEFAULT NULL,
|
78
|
+
`created_at` datetime NOT NULL,
|
79
|
+
`updated_at` datetime NOT NULL,
|
80
|
+
PRIMARY KEY (`id`)
|
81
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
82
|
+
/*!40101 SET character_set_client = @saved_cs_client */;
|
83
|
+
|
84
|
+
--
|
85
|
+
-- Dumping data for table `users`
|
86
|
+
--
|
87
|
+
|
88
|
+
LOCK TABLES `users` WRITE;
|
89
|
+
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
|
90
|
+
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
|
91
|
+
UNLOCK TABLES;
|
92
|
+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
93
|
+
|
94
|
+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
95
|
+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
96
|
+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
97
|
+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
98
|
+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
99
|
+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
100
|
+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
101
|
+
|
102
|
+
-- Dump completed on 2014-09-19 12:11:03
|
data/spec/prepare.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
system("mysql -uroot cat_tree_test < spec/db_dump.sql")
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cat_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsukasa OISHI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -54,16 +54,22 @@ dependencies:
|
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- - "
|
57
|
+
- - "<"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.8'
|
60
|
+
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
59
|
-
version: '1.
|
62
|
+
version: '1.6'
|
60
63
|
type: :development
|
61
64
|
prerelease: false
|
62
65
|
version_requirements: !ruby/object:Gem::Requirement
|
63
66
|
requirements:
|
64
|
-
- - "
|
67
|
+
- - "<"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.8'
|
70
|
+
- - ">="
|
65
71
|
- !ruby/object:Gem::Version
|
66
|
-
version: '1.
|
72
|
+
version: '1.6'
|
67
73
|
- !ruby/object:Gem::Dependency
|
68
74
|
name: rake
|
69
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +134,7 @@ extensions: []
|
|
128
134
|
extra_rdoc_files: []
|
129
135
|
files:
|
130
136
|
- ".gitignore"
|
137
|
+
- ".travis.yml"
|
131
138
|
- Appraisals
|
132
139
|
- Gemfile
|
133
140
|
- LICENSE.txt
|
@@ -138,6 +145,7 @@ files:
|
|
138
145
|
- gemfiles/rails40.gemfile
|
139
146
|
- gemfiles/rails41.gemfile
|
140
147
|
- lib/cat_tree.rb
|
148
|
+
- lib/cat_tree/config.rb
|
141
149
|
- lib/cat_tree/initializer.rb
|
142
150
|
- lib/cat_tree/logger.rb
|
143
151
|
- lib/cat_tree/observer.rb
|
@@ -145,6 +153,8 @@ files:
|
|
145
153
|
- lib/cat_tree/railtie.rb
|
146
154
|
- lib/cat_tree/version.rb
|
147
155
|
- spec/cat_tree_test.sqlite3
|
156
|
+
- spec/db_dump.sql
|
157
|
+
- spec/prepare.rb
|
148
158
|
- spec/spec_helper.rb
|
149
159
|
- spec/unit/observer_spec.rb
|
150
160
|
homepage: ''
|
@@ -173,5 +183,7 @@ specification_version: 4
|
|
173
183
|
summary: CatTree monitors ActiveRecord objects in development environment
|
174
184
|
test_files:
|
175
185
|
- spec/cat_tree_test.sqlite3
|
186
|
+
- spec/db_dump.sql
|
187
|
+
- spec/prepare.rb
|
176
188
|
- spec/spec_helper.rb
|
177
189
|
- spec/unit/observer_spec.rb
|