Merging gst-devtools
[platform/upstream/gstreamer.git] / debug-viewer / GstDebugViewer / tests / performance.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8; mode: python; -*-
3 #
4 #  GStreamer Debug Viewer - View and analyze GStreamer debug log files
5 #
6 #  Copyright (C) 2007 RenĂ© Stadler <mail@renestadler.de>
7 #
8 #  This program is free software; you can redistribute it and/or modify it
9 #  under the terms of the GNU General Public License as published by the Free
10 #  Software Foundation; either version 3 of the License, or (at your option)
11 #  any later version.
12 #
13 #  This program is distributed in the hope that it will be useful, but WITHOUT
14 #  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 #  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16 #  more details.
17 #
18 #  You should have received a copy of the GNU General Public License along with
19 #  this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 """GStreamer Debug Viewer performance test program."""
22
23 import sys
24 import os
25 import os.path
26 from glob import glob
27 import time
28
29 import gi
30
31 from gi.repository import GObject
32
33 from .. import Common, Data, GUI
34
35
36 class TestParsingPerformance (object):
37
38     def __init__(self, filename):
39
40         self.main_loop = GObject.MainLoop()
41         self.log_file = Data.LogFile(filename, Common.Data.DefaultDispatcher())
42         self.log_file.consumers.append(self)
43
44     def start(self):
45
46         self.log_file.start_loading()
47
48     def handle_load_started(self):
49
50         self.start_time = time.time()
51
52     def handle_load_finished(self):
53
54         diff = time.time() - self.start_time
55         print("line cache built in %0.1f ms" % (diff * 1000.,))
56
57         start_time = time.time()
58         model = GUI.LazyLogModel(self.log_file)
59         for row in model:
60             pass
61         diff = time.time() - start_time
62         print("model iterated in %0.1f ms" % (diff * 1000.,))
63         print("overall time spent: %0.1f s" % (time.time() - self.start_time,))
64
65         import resource
66         rusage = resource.getrusage(resource.RUSAGE_SELF)
67         print("time spent in user mode: %.2f s" % (rusage.ru_utime,))
68         print("time spent in system mode: %.2f s" % (rusage.ru_stime,))
69
70
71 def main():
72
73     if len(sys.argv) > 1:
74         test = TestParsingPerformance(sys.argv[1])
75         test.start()
76
77
78 if __name__ == "__main__":
79     main()