Merge lp:~albaguirre/ubuntu-performance-tests/add-simple-native-mir-app into lp:ubuntu-performance-tests

Proposed by Alberto Aguirre
Status: Merged
Merged at revision: 19
Proposed branch: lp:~albaguirre/ubuntu-performance-tests/add-simple-native-mir-app
Merge into: lp:ubuntu-performance-tests
Diff against target: 352 lines (+299/-0)
10 files modified
utils/apps/simple-mir-app/CMakeLists.txt (+28/-0)
utils/apps/simple-mir-app/debian/changelog (+5/-0)
utils/apps/simple-mir-app/debian/compat (+1/-0)
utils/apps/simple-mir-app/debian/control (+19/-0)
utils/apps/simple-mir-app/debian/copyright (+20/-0)
utils/apps/simple-mir-app/debian/rules (+6/-0)
utils/apps/simple-mir-app/debian/source/format (+1/-0)
utils/apps/simple-mir-app/measure_startup.sh (+32/-0)
utils/apps/simple-mir-app/src/CMakeLists.txt (+18/-0)
utils/apps/simple-mir-app/src/simple.cpp (+169/-0)
To merge this branch: bzr merge lp:~albaguirre/ubuntu-performance-tests/add-simple-native-mir-app
Reviewer Review Type Date Requested Status
Sergio Cazzolato Pending
Review via email: mp+295001@code.launchpad.net

Commit message

Add a simple native mir app

Simple mir app that obtains a mir connection through platform-api, creates a surface and swaps.
This can be used to establish a baseline for startup performance.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'utils/apps/simple-mir-app'
2=== added file 'utils/apps/simple-mir-app/CMakeLists.txt'
3--- utils/apps/simple-mir-app/CMakeLists.txt 1970-01-01 00:00:00 +0000
4+++ utils/apps/simple-mir-app/CMakeLists.txt 2016-05-18 01:15:36 +0000
5@@ -0,0 +1,28 @@
6+# Copyright © 2016 Canonical Ltd.
7+#
8+# This program is free software: you can redistribute it and/or modify
9+# it under the terms of the GNU General Public License version 3 as
10+# published by the Free Software Foundation.
11+#
12+# This program is distributed in the hope that it will be useful,
13+# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+# GNU General Public License for more details.
16+#
17+# You should have received a copy of the GNU General Public License
18+# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+#
20+
21+project(simple-mir-app)
22+
23+cmake_minimum_required(VERSION 3.0)
24+
25+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
26+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -g -Werror -Wall -pedantic -Wextra -fPIC")
27+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -std=c++14 -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC")
28+
29+include(FindPkgConfig)
30+#find_package(EGL REQUIRED)
31+pkg_check_modules(MIRCLIENT mirclient REQUIRED)
32+pkg_check_modules(PLATFORM_API ubuntu-platform-api REQUIRED)
33+add_subdirectory(src/)
34
35=== added directory 'utils/apps/simple-mir-app/debian'
36=== added file 'utils/apps/simple-mir-app/debian/changelog'
37--- utils/apps/simple-mir-app/debian/changelog 1970-01-01 00:00:00 +0000
38+++ utils/apps/simple-mir-app/debian/changelog 2016-05-18 01:15:36 +0000
39@@ -0,0 +1,5 @@
40+simple-mir-app (0.0.1) UNRELEASED; urgency=medium
41+
42+ * Initial release.
43+
44+ -- Alberto Aguirre <alberto.aguirre@canonical.com> Tue, 17 May 2016 17:19:11 -0500
45
46=== added file 'utils/apps/simple-mir-app/debian/compat'
47--- utils/apps/simple-mir-app/debian/compat 1970-01-01 00:00:00 +0000
48+++ utils/apps/simple-mir-app/debian/compat 2016-05-18 01:15:36 +0000
49@@ -0,0 +1,1 @@
50+9
51
52=== added file 'utils/apps/simple-mir-app/debian/control'
53--- utils/apps/simple-mir-app/debian/control 1970-01-01 00:00:00 +0000
54+++ utils/apps/simple-mir-app/debian/control 2016-05-18 01:15:36 +0000
55@@ -0,0 +1,19 @@
56+Source: simple-mir-app
57+Priority: optional
58+Section: devel
59+Maintainer: Alberto Aguirre <alberto.aguirre@canonical.com>
60+Build-Depends: cmake,
61+ debhelper (>= 9),
62+ pkg-config,
63+ libmirclient-dev,
64+ libubuntu-application-api-dev,
65+Standards-Version: 3.9.4
66+Homepage: https://launchpad.net/ubuntu-performance-tests
67+Vcs-Bzr: lp:ubuntu-performance-tests
68+Vcs-Browser: https://code.launchpad.net/ubuntu-performance-tests
69+
70+Package: simple-mir-app
71+Architecture: any
72+Depends: ${misc:Depends},
73+ ${shlibs:Depends}
74+Description: Simple mir native app
75
76=== added file 'utils/apps/simple-mir-app/debian/copyright'
77--- utils/apps/simple-mir-app/debian/copyright 1970-01-01 00:00:00 +0000
78+++ utils/apps/simple-mir-app/debian/copyright 2016-05-18 01:15:36 +0000
79@@ -0,0 +1,20 @@
80+Format: http://dep.debian.net/deps/dep5/
81+Upstream-Name: Simple Mir App
82+Upstream-Contact: Alberto Aguirre <alberto.aguirre@canonical.com>
83+Source: http://launchpad.net/ubuntu-performance-tests
84+
85+Files: *
86+Copyright: 2016, Canonical Ltd.
87+License: GPL-3
88+ This program is free software: you can redistribute it and/or modify
89+ it under the terms of the GNU General Public License version 3 as
90+ published by the Free Software Foundation.
91+ .
92+ This program is distributed in the hope that it will be useful,
93+ but WITHOUT ANY WARRANTY; without even the implied warranty of
94+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95+ GNU General Public License for more details.
96+ .
97+ On Debian systems, the full text of the GNU General Public
98+ License version 3 can be found in the file
99+ `/usr/share/common-licenses/GPL-3'.
100
101=== added file 'utils/apps/simple-mir-app/debian/rules'
102--- utils/apps/simple-mir-app/debian/rules 1970-01-01 00:00:00 +0000
103+++ utils/apps/simple-mir-app/debian/rules 2016-05-18 01:15:36 +0000
104@@ -0,0 +1,6 @@
105+#!/usr/bin/make -f
106+
107+export DPKG_GENSYMBOLS_CHECK_LEVEL = 4
108+
109+%:
110+ dh $@ --parallel --fail-missing
111
112=== added directory 'utils/apps/simple-mir-app/debian/source'
113=== added file 'utils/apps/simple-mir-app/debian/source/format'
114--- utils/apps/simple-mir-app/debian/source/format 1970-01-01 00:00:00 +0000
115+++ utils/apps/simple-mir-app/debian/source/format 2016-05-18 01:15:36 +0000
116@@ -0,0 +1,1 @@
117+1.0
118
119=== added file 'utils/apps/simple-mir-app/measure_startup.sh'
120--- utils/apps/simple-mir-app/measure_startup.sh 1970-01-01 00:00:00 +0000
121+++ utils/apps/simple-mir-app/measure_startup.sh 2016-05-18 01:15:36 +0000
122@@ -0,0 +1,32 @@
123+#!/bin/bash
124+
125+function seconds()
126+{
127+ echo "${1%%:*}"
128+}
129+
130+function nanosecs()
131+{
132+ echo "${1##*:}"
133+}
134+
135+function calc_launch_time()
136+{
137+ local start_secs=$(seconds ${1})
138+ local start_nano=$(nanosecs ${1})
139+ local end_secs=$(seconds ${2})
140+ local end_nano=$(nanosecs ${2})
141+
142+ local secs_diff=$((${end_secs} - ${start_secs}))
143+ local ms_diff=$(((${end_nano} - ${start_nano})/1000000))
144+ local total_diff=$((${secs_diff}*1000 + ms_diff))
145+ echo ${total_diff}
146+}
147+
148+start_time=$(date +%s":"%N)
149+echo "launched at ${start_time}"
150+after_swap_time=$(simple-mir-app --desktop_file_hint=/usr/share/applications/dialer-app.desktop | grep swap | cut -c 32- )
151+echo "Ended at ${after_swap_time}"
152+echo "Took: $(calc_launch_time ${start_time} ${after_swap_time}) millisecs"
153+
154+
155
156=== added directory 'utils/apps/simple-mir-app/src'
157=== added file 'utils/apps/simple-mir-app/src/CMakeLists.txt'
158--- utils/apps/simple-mir-app/src/CMakeLists.txt 1970-01-01 00:00:00 +0000
159+++ utils/apps/simple-mir-app/src/CMakeLists.txt 2016-05-18 01:15:36 +0000
160@@ -0,0 +1,18 @@
161+include_directories(
162+ ${MIRCLIENT_INCLUDE_DIRS}
163+ ${PLATFORM_API_INCLUDE_DIRS}
164+)
165+
166+add_executable(simple-mir-app simple.cpp)
167+
168+target_link_libraries(
169+ simple-mir-app
170+
171+ ${MIRCLIENT_LDFLAGS}
172+ ${PLATFORM_API_LDFLAGS}
173+)
174+
175+install(TARGETS
176+ simple-mir-app
177+ DESTINATION bin
178+)
179
180=== added file 'utils/apps/simple-mir-app/src/simple.cpp'
181--- utils/apps/simple-mir-app/src/simple.cpp 1970-01-01 00:00:00 +0000
182+++ utils/apps/simple-mir-app/src/simple.cpp 2016-05-18 01:15:36 +0000
183@@ -0,0 +1,169 @@
184+/*
185+ * Copyright © 2016 Canonical Ltd.
186+ *
187+ * This program is free software: you can redistribute it and/or modify
188+ * it under the terms of the GNU General Public License version 3 as
189+ * published by the Free Software Foundation.
190+ *
191+ * This program is distributed in the hope that it will be useful,
192+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
193+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
194+ * GNU General Public License for more details.
195+ *
196+ * You should have received a copy of the GNU General Public License
197+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
198+ *
199+ */
200+
201+#include <ubuntu/application/id.h>
202+#include <ubuntu/application/description.h>
203+#include <ubuntu/application/options.h>
204+#include <ubuntu/application/lifecycle_delegate.h>
205+#include <ubuntu/application/instance.h>
206+
207+#include <memory>
208+#include <iostream>
209+
210+#include <stdexcept>
211+
212+namespace
213+{
214+
215+MirPixelFormat find_default_pixel_format(MirConnection* connection)
216+{
217+ MirPixelFormat pixel_format = mir_pixel_format_invalid;
218+ unsigned int valid_formats = 0;
219+ mir_connection_get_available_surface_formats(connection, &pixel_format, 1, &valid_formats);
220+
221+ if (pixel_format == mir_pixel_format_invalid || valid_formats < 1)
222+ throw std::runtime_error("No pixel formats found!");
223+
224+ return pixel_format;
225+}
226+
227+class NormalSpec
228+{
229+public:
230+ NormalSpec(MirConnection *connection, int width, int height, MirPixelFormat pixel_format) :
231+ spec{mir_connection_create_spec_for_normal_surface(connection, width, height, pixel_format), mir_surface_spec_release}
232+ {
233+ mir_surface_spec_set_name(spec.get(), "Basic Surface");
234+ }
235+ operator MirSurfaceSpec*() { return spec.get(); }
236+
237+private:
238+ std::unique_ptr<MirSurfaceSpec, void(*)(MirSurfaceSpec *)> spec;
239+};
240+
241+MirSurface* make_surface(MirConnection* connection)
242+{
243+ auto pixel_format = find_default_pixel_format(connection);
244+ NormalSpec spec(connection, 640, 480, pixel_format);
245+ return mir_surface_create_sync(spec);
246+}
247+
248+class Surface
249+{
250+public:
251+ Surface(MirConnection* connection) :
252+ surface{make_surface(connection), mir_surface_release_sync}
253+ {
254+ if (!mir_surface_is_valid(surface.get()))
255+ {
256+ throw std::runtime_error(mir_surface_get_error_message(surface.get()));
257+ }
258+ }
259+
260+ void swap_buffers()
261+ {
262+ auto stream = mir_surface_get_buffer_stream(surface.get());
263+ if (!mir_buffer_stream_is_valid(stream))
264+ {
265+ throw std::runtime_error(mir_buffer_stream_get_error_message(stream));
266+ }
267+ mir_buffer_stream_swap_buffers_sync(stream);
268+ }
269+
270+private:
271+ std::unique_ptr<MirSurface, void(*)(MirSurface*)> surface;
272+};
273+
274+class Application
275+{
276+public:
277+ Application(int argc, char *argv[]) :
278+ delegate{u_application_lifecycle_delegate_new()}
279+ {
280+ u_application_lifecycle_delegate_set_application_resumed_cb(delegate, &Application::resume);
281+ u_application_lifecycle_delegate_set_application_about_to_stop_cb(delegate, &Application::stop);
282+ u_application_lifecycle_delegate_set_context(delegate, this);
283+
284+ std::string name{"Simple Native App"};
285+ auto id = u_application_id_new_from_stringn(name.c_str(), name.length());
286+ auto description = u_application_description_new();
287+ u_application_description_set_application_id(description, id);
288+ u_application_description_set_application_lifecycle_delegate(description, delegate);
289+
290+ auto options = u_application_options_new_from_cmd_line(argc, argv);
291+ instance = u_application_instance_new_from_description_with_options(description, options);
292+
293+ u_application_options_destroy(options);
294+ u_application_description_destroy(description);
295+
296+ if (instance == nullptr)
297+ throw std::runtime_error("Could not create ubuntu app instance!");
298+ }
299+
300+ ~Application()
301+ {
302+ //FIXME: The symbol below is not exposed in papi library
303+ //u_application_instance_unref(instance);
304+ u_application_lifecycle_delegate_unref(delegate);
305+ }
306+
307+ auto make_surface()
308+ {
309+ auto connection = u_application_instance_get_mir_connection(instance);
310+ return std::make_unique<Surface>(connection);
311+ }
312+
313+ static void resume(UApplicationOptions const*, void*)
314+ {
315+ std::cout << "Resuming" << std::endl;
316+ }
317+
318+ static void stop(UApplicationArchive*, void*)
319+ {
320+ std::cout << "Stopping" << std::endl;
321+ }
322+
323+private:
324+ UApplicationLifecycleDelegate* delegate;
325+ UApplicationInstance* instance;
326+};
327+
328+void print_current_time(void)
329+{
330+ struct timespec spec;
331+ clock_gettime(CLOCK_REALTIME, &spec);
332+ std::cout << "time after swap(sec:nanosec) - " << spec.tv_sec;
333+ std::cout << ":" << spec.tv_nsec << std::endl;
334+}
335+}
336+
337+int main(int argc, char *argv[])
338+try
339+{
340+ Application app(argc, argv);
341+
342+ auto surface = app.make_surface();
343+ surface->swap_buffers();
344+
345+ print_current_time();
346+ std::cout << "Done." << std::endl;
347+}
348+catch(std::exception const& e)
349+{
350+ std::cerr << "Failed: " << e.what() << std::endl;
351+}
352+

Subscribers

People subscribed via source and target branches