Skip to content

Commit d6b0404

Browse files
Update README.md
1 parent d68cdd1 commit d6b0404

File tree

1 file changed

+94
-15
lines changed

1 file changed

+94
-15
lines changed

README.md

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,112 @@
1-
1+
Below are steps to run Panorama to analyze and improve your own Rails application.
22

3-
* Basically, to get the statistics and anti-patterns detection results:
3+
### Modify your app
4+
Since Panorama changes the webpage layout and monitors then code change, you need to modify your app to enable such functionality.
45

5-
```$./ana.sh app_name $DIR```
6+
* Add the following to your Gemfile
7+
```
8+
gem 'will_paginate'
9+
gem 'bootstrap-sass'
10+
gem 'sass-rails'
11+
gem 'render_async'
12+
gem 'react-rails-hot-loader'
13+
gem 'active_record_query_trace'
14+
```
15+
You can also do this by
16+
```
17+
cd panorama-static-analyzer
18+
ruby add_gems.rb path-to-app/
19+
```
620

7-
$DIR is the path of your app as application/app/
21+
* Add the following to `app/assets/javascripts/application.js` or `app/assets/javascripts/application.js.erb` (if such files exist, otherwise create the file):
22+
```
23+
//= require bootstrap-sprockets
24+
//= require react-rails-hot-loader
25+
//= require_tree ./interact
26+
```
827

9-
For example, if you want to run a single action,
28+
* Create a folder `interact/`:
1029
```
11-
$./single_action.sh forem PostsController,index /home/forem/app/
30+
$ mkdir app/assets/javascripts/interact
1231
```
1332

14-
Results will stored in the ../application/forem/results/PostsController_index/*.xml.
33+
* Add the following to `app/assets/stylesheets/application.scss` (create this file if not exists):
34+
```
35+
@import "bootstrap-sprockets";
36+
@import "bootstrap";
37+
```
1538

16-
* If you wish to run sin actions from an application, do:
39+
* Create new `active_query_trace.rb`:
40+
```
41+
$ touch config/initializer/active_query_trace.rb
1742
```
18-
$./ana.sh app_name /home/forem/app/
43+
and add the following to this file:
1944
```
45+
ActiveRecordQueryTrace.enabled = true
46+
ActiveRecordQueryTrace.lines = 0
47+
ActiveRecordQueryTrace.level = :rails
48+
```
2049

21-
Results will be saved to the folder under the app directory.
22-
The folder name is defined under global.rb, and by default is /result/.
50+
* Add the following to the body of your view file (e.g., `app/views/layouts/application.html.erb`):
51+
```
52+
<%= content_for :render_async %>
53+
```
54+
For instance,<br/>
55+
<img src="https://hyperloop-rails.github.io/panorama/screenshots/contentfor.png" width="200"><br/>
2356

24-
For you application, we need a calls.txt file, which you can achieve as follows:
57+
* Add the following to the head of your application_controller.rb:
58+
```
59+
require 'will_paginate/array'
60+
```
61+
For instance,<br/>
62+
<img src="https://hyperloop-rails.github.io/panorama/screenshots/application_controller.png"><br/>
63+
64+
* create `calls.txt`<br/>
65+
The tool needs to know all entrance controller actions from your application. It assumes them to be stored in a file called `calls.txt`. You can generate that file by running:
66+
```
67+
$rake routes | tail -n +2 | awk '{ for (i=1;i<=NF;i++) if (match($i, /.#./)) print $i}' | sed -e 's/#/,/g' | sort | uniq
68+
```
69+
in your app, and then copying it to `<APPDIR>/calls.txt`.
70+
71+
### Download Panorama and install related packages
72+
* Clone the [Panorama source code](https://github.com/hyperloop-rails) from github.
73+
74+
* The following packages need to be installed in order to run Panorama:
75+
```
76+
$ gem install yard
77+
$ gem install activesupport
78+
$ gem install work_queue
79+
```
80+
81+
### Use Panorama for your app
82+
* First run the application server and generate the log file that records the queries issued when visiting pages (i.e., `./log/development.log`).
83+
84+
* Update PATH environment:
85+
```
86+
$ export PATH=$PATH:path-to-panorama/compiled-jruby/bin
87+
```
88+
89+
* Generate dataflow files:
90+
```
91+
cd path-to-panorama/
92+
./perf_action.sh app-name path-to-app/
93+
```
94+
`./perf_action.sh` takes two parameters, the first is the application name, which is used to create a folder to store dataflow information; the second is the path to the application souce code.
2595

26-
* in your app, run:
96+
* Monitor an action in your app:
2797
```
28-
$rake routes | tail -n +2 | awk '{ for (i=1;i<=NF;i++) if (match($i, /.#./)) print $i}' | sed -e 's/#/,/g' | sort | uniq
98+
cd path-to-panorama/controller_model_analysis/
99+
./compute_performance.sh app-name path-to-app/ controller-action
29100
```
30-
to get the list of entrance controller actions that can be invoked by the app, copy it to APPDIR/calls.txt
101+
`./compute_performance.sh` takes three parameters. The third `controller-action` is the name of the action that you want to monitor, for instance, `BlogsController,index`.
31102

103+
* Start the app server, and visit the corresponding webpage (i.e., the page generated from the action you wish to monitor).
104+
You will see the page with heatmap showing the cost of each element:<br/>
105+
![heatmap](https://hyperloop-rails.github.io/panorama/screenshots/heatmap.png)<br/>
32106

107+
* When you move the cursor to an element and click, it will show patches that Panorama can generate to accelerate the element:<br/>
108+
<img src="https://hyperloop-rails.github.io/panorama/screenshots/choices2.png" width="300"><br/>
109+
When you click the patch (e.g., pagination), the patch will be automatically added to your source code.<br/>
110+
Then you can refresh the page and see the new webpage:
111+
![newpage](https://hyperloop-rails.github.io/panorama/screenshots/newpage.png)<br/>
33112

0 commit comments

Comments
 (0)