]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/profiling.py
Reformat lyx2lyx code using ruff
[lyx.git] / lib / lyx2lyx / profiling.py
1 #! /usr/bin/python3
2 # Copyright (C) 2004 José Matos <jamatos@lyx.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
18 # We need all this because lyx2lyx does not have the .py termination
19 import imp
20
21 lyx2lyx = imp.load_source("lyx2lyx", "lyx2lyx", open("lyx2lyx"))
22
23 # Profiler used in the study
24 import hotshot, hotshot.stats
25
26 import sys
27 import os
28
29 """
30 This program profiles lyx2lyx.
31 Usage:
32         ./profiling.py option_to_lyx2lyx
33
34 Example:
35         ./profiling.py -ou.lyx ../doc/UserGuide.lyx
36 """
37
38
39 def main():
40     # This will only work with python >= 2.2, the version where this module was added
41     prof = hotshot.Profile("lyx2lyx.prof")  # Use temporary file, here?
42     benchtime = prof.runcall(lyx2lyx.main)
43     prof.close()
44
45     # After the tests, show the profile analysis.
46     stats = hotshot.stats.load("lyx2lyx.prof")
47     stats.strip_dirs()
48     stats.sort_stats("time", "calls")
49     stats.print_stats(20)
50
51     os.unlink("lyx2lyx.prof")
52
53
54 if __name__ == "__main__":
55     main()