File tree Expand file tree Collapse file tree 3 files changed +50
-3
lines changed Expand file tree Collapse file tree 3 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 2
2
** /* .sqlite3
3
3
cinder
4
4
profile_data
5
- ** /prof_report.txt
5
+ ** /* prof_report. *
Original file line number Diff line number Diff line change 1
1
## Profiling
2
2
3
- Run the server with the following command:
3
+ Run the server with the following command.
4
4
5
5
``` bash
6
6
python ./manage.py runprofileserver --use-cprofile --prof-path=profile-data
7
7
```
8
8
9
- and proceed with the load testing as usual. Then run the following command to generate the profiling report in ` prof_report.txt ` :
9
+ and proceed with the load testing as usual. Then run the following command from ` testsite ` to generate the profiling report in ` prof_report.txt ` .
10
10
11
11
``` bash
12
12
python view_profile_stats.py
13
13
```
14
+
15
+ For a summary of total time spent inside each file of ` django ` , run the following command from ` testsite ` .
16
+
17
+ ``` bash
18
+ python django_profile_stats.py
19
+ ```
20
+
21
+ This will emit a JSON file ` django_prof_report.json ` .
Original file line number Diff line number Diff line change
1
+ import pstats
2
+ import os
3
+ import io
4
+ import json
5
+
6
+
7
+ data = {} # {filename: time}
8
+
9
+ # loop through all files in 'profile_data' directory
10
+ for file in os .listdir ("profile_data" ):
11
+ if file .endswith (".prof" ):
12
+ # print the file name
13
+ print (file )
14
+ buf = io .StringIO ()
15
+ # create a new instance of the Stats class
16
+ s = pstats .Stats ("profile_data/" + file , stream = buf )
17
+ # sort the stats by time and print all but first 8 lines
18
+ s .sort_stats ("time" ).print_stats (20 )
19
+
20
+ lines = buf .getvalue ().split ("\n " )[8 :]
21
+
22
+ # only retain lines with site-packages/django
23
+ lines = filter (lambda x : "site-packages/django" in x , lines )
24
+
25
+ # for each line, extract the filename (element 5) and time (element 1)
26
+ for line in lines :
27
+ line = line .split ()
28
+ filename = line [5 ].split ("site-packages/django/" , 2 )[1 ].split (":" )[0 ]
29
+ time = float (line [1 ])
30
+ if filename in data :
31
+ data [filename ] += time
32
+ else :
33
+ data [filename ] = time
34
+
35
+ # sort the data by time
36
+ data = dict (sorted (data .items (), key = lambda item : item [1 ], reverse = True ))
37
+
38
+ with open ("django_prof_report.json" , "w" ) as f :
39
+ f .write (json .dumps (data , indent = 4 ))
You can’t perform that action at this time.
0 commit comments