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
=== added directory 'utils/apps/simple-mir-app'
=== added file 'utils/apps/simple-mir-app/CMakeLists.txt'
--- utils/apps/simple-mir-app/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/CMakeLists.txt 2016-05-18 01:15:36 +0000
@@ -0,0 +1,28 @@
1# Copyright © 2016 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License version 3 as
5# published by the Free Software Foundation.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#
15
16project(simple-mir-app)
17
18cmake_minimum_required(VERSION 3.0)
19
20set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
21set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -g -Werror -Wall -pedantic -Wextra -fPIC")
22set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -std=c++14 -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC")
23
24include(FindPkgConfig)
25#find_package(EGL REQUIRED)
26pkg_check_modules(MIRCLIENT mirclient REQUIRED)
27pkg_check_modules(PLATFORM_API ubuntu-platform-api REQUIRED)
28add_subdirectory(src/)
029
=== added directory 'utils/apps/simple-mir-app/debian'
=== added file 'utils/apps/simple-mir-app/debian/changelog'
--- utils/apps/simple-mir-app/debian/changelog 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/changelog 2016-05-18 01:15:36 +0000
@@ -0,0 +1,5 @@
1simple-mir-app (0.0.1) UNRELEASED; urgency=medium
2
3 * Initial release.
4
5 -- Alberto Aguirre <alberto.aguirre@canonical.com> Tue, 17 May 2016 17:19:11 -0500
06
=== added file 'utils/apps/simple-mir-app/debian/compat'
--- utils/apps/simple-mir-app/debian/compat 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/compat 2016-05-18 01:15:36 +0000
@@ -0,0 +1,1 @@
19
02
=== added file 'utils/apps/simple-mir-app/debian/control'
--- utils/apps/simple-mir-app/debian/control 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/control 2016-05-18 01:15:36 +0000
@@ -0,0 +1,19 @@
1Source: simple-mir-app
2Priority: optional
3Section: devel
4Maintainer: Alberto Aguirre <alberto.aguirre@canonical.com>
5Build-Depends: cmake,
6 debhelper (>= 9),
7 pkg-config,
8 libmirclient-dev,
9 libubuntu-application-api-dev,
10Standards-Version: 3.9.4
11Homepage: https://launchpad.net/ubuntu-performance-tests
12Vcs-Bzr: lp:ubuntu-performance-tests
13Vcs-Browser: https://code.launchpad.net/ubuntu-performance-tests
14
15Package: simple-mir-app
16Architecture: any
17Depends: ${misc:Depends},
18 ${shlibs:Depends}
19Description: Simple mir native app
020
=== added file 'utils/apps/simple-mir-app/debian/copyright'
--- utils/apps/simple-mir-app/debian/copyright 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/copyright 2016-05-18 01:15:36 +0000
@@ -0,0 +1,20 @@
1Format: http://dep.debian.net/deps/dep5/
2Upstream-Name: Simple Mir App
3Upstream-Contact: Alberto Aguirre <alberto.aguirre@canonical.com>
4Source: http://launchpad.net/ubuntu-performance-tests
5
6Files: *
7Copyright: 2016, Canonical Ltd.
8License: GPL-3
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3 as
11 published by the Free Software Foundation.
12 .
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 .
18 On Debian systems, the full text of the GNU General Public
19 License version 3 can be found in the file
20 `/usr/share/common-licenses/GPL-3'.
021
=== added file 'utils/apps/simple-mir-app/debian/rules'
--- utils/apps/simple-mir-app/debian/rules 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/rules 2016-05-18 01:15:36 +0000
@@ -0,0 +1,6 @@
1#!/usr/bin/make -f
2
3export DPKG_GENSYMBOLS_CHECK_LEVEL = 4
4
5%:
6 dh $@ --parallel --fail-missing
07
=== added directory 'utils/apps/simple-mir-app/debian/source'
=== added file 'utils/apps/simple-mir-app/debian/source/format'
--- utils/apps/simple-mir-app/debian/source/format 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/debian/source/format 2016-05-18 01:15:36 +0000
@@ -0,0 +1,1 @@
11.0
02
=== added file 'utils/apps/simple-mir-app/measure_startup.sh'
--- utils/apps/simple-mir-app/measure_startup.sh 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/measure_startup.sh 2016-05-18 01:15:36 +0000
@@ -0,0 +1,32 @@
1#!/bin/bash
2
3function seconds()
4{
5 echo "${1%%:*}"
6}
7
8function nanosecs()
9{
10 echo "${1##*:}"
11}
12
13function calc_launch_time()
14{
15 local start_secs=$(seconds ${1})
16 local start_nano=$(nanosecs ${1})
17 local end_secs=$(seconds ${2})
18 local end_nano=$(nanosecs ${2})
19
20 local secs_diff=$((${end_secs} - ${start_secs}))
21 local ms_diff=$(((${end_nano} - ${start_nano})/1000000))
22 local total_diff=$((${secs_diff}*1000 + ms_diff))
23 echo ${total_diff}
24}
25
26start_time=$(date +%s":"%N)
27echo "launched at ${start_time}"
28after_swap_time=$(simple-mir-app --desktop_file_hint=/usr/share/applications/dialer-app.desktop | grep swap | cut -c 32- )
29echo "Ended at ${after_swap_time}"
30echo "Took: $(calc_launch_time ${start_time} ${after_swap_time}) millisecs"
31
32
033
=== added directory 'utils/apps/simple-mir-app/src'
=== added file 'utils/apps/simple-mir-app/src/CMakeLists.txt'
--- utils/apps/simple-mir-app/src/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/src/CMakeLists.txt 2016-05-18 01:15:36 +0000
@@ -0,0 +1,18 @@
1include_directories(
2 ${MIRCLIENT_INCLUDE_DIRS}
3 ${PLATFORM_API_INCLUDE_DIRS}
4)
5
6add_executable(simple-mir-app simple.cpp)
7
8target_link_libraries(
9 simple-mir-app
10
11 ${MIRCLIENT_LDFLAGS}
12 ${PLATFORM_API_LDFLAGS}
13)
14
15install(TARGETS
16 simple-mir-app
17 DESTINATION bin
18)
019
=== added file 'utils/apps/simple-mir-app/src/simple.cpp'
--- utils/apps/simple-mir-app/src/simple.cpp 1970-01-01 00:00:00 +0000
+++ utils/apps/simple-mir-app/src/simple.cpp 2016-05-18 01:15:36 +0000
@@ -0,0 +1,169 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <ubuntu/application/id.h>
19#include <ubuntu/application/description.h>
20#include <ubuntu/application/options.h>
21#include <ubuntu/application/lifecycle_delegate.h>
22#include <ubuntu/application/instance.h>
23
24#include <memory>
25#include <iostream>
26
27#include <stdexcept>
28
29namespace
30{
31
32MirPixelFormat find_default_pixel_format(MirConnection* connection)
33{
34 MirPixelFormat pixel_format = mir_pixel_format_invalid;
35 unsigned int valid_formats = 0;
36 mir_connection_get_available_surface_formats(connection, &pixel_format, 1, &valid_formats);
37
38 if (pixel_format == mir_pixel_format_invalid || valid_formats < 1)
39 throw std::runtime_error("No pixel formats found!");
40
41 return pixel_format;
42}
43
44class NormalSpec
45{
46public:
47 NormalSpec(MirConnection *connection, int width, int height, MirPixelFormat pixel_format) :
48 spec{mir_connection_create_spec_for_normal_surface(connection, width, height, pixel_format), mir_surface_spec_release}
49 {
50 mir_surface_spec_set_name(spec.get(), "Basic Surface");
51 }
52 operator MirSurfaceSpec*() { return spec.get(); }
53
54private:
55 std::unique_ptr<MirSurfaceSpec, void(*)(MirSurfaceSpec *)> spec;
56};
57
58MirSurface* make_surface(MirConnection* connection)
59{
60 auto pixel_format = find_default_pixel_format(connection);
61 NormalSpec spec(connection, 640, 480, pixel_format);
62 return mir_surface_create_sync(spec);
63}
64
65class Surface
66{
67public:
68 Surface(MirConnection* connection) :
69 surface{make_surface(connection), mir_surface_release_sync}
70 {
71 if (!mir_surface_is_valid(surface.get()))
72 {
73 throw std::runtime_error(mir_surface_get_error_message(surface.get()));
74 }
75 }
76
77 void swap_buffers()
78 {
79 auto stream = mir_surface_get_buffer_stream(surface.get());
80 if (!mir_buffer_stream_is_valid(stream))
81 {
82 throw std::runtime_error(mir_buffer_stream_get_error_message(stream));
83 }
84 mir_buffer_stream_swap_buffers_sync(stream);
85 }
86
87private:
88 std::unique_ptr<MirSurface, void(*)(MirSurface*)> surface;
89};
90
91class Application
92{
93public:
94 Application(int argc, char *argv[]) :
95 delegate{u_application_lifecycle_delegate_new()}
96 {
97 u_application_lifecycle_delegate_set_application_resumed_cb(delegate, &Application::resume);
98 u_application_lifecycle_delegate_set_application_about_to_stop_cb(delegate, &Application::stop);
99 u_application_lifecycle_delegate_set_context(delegate, this);
100
101 std::string name{"Simple Native App"};
102 auto id = u_application_id_new_from_stringn(name.c_str(), name.length());
103 auto description = u_application_description_new();
104 u_application_description_set_application_id(description, id);
105 u_application_description_set_application_lifecycle_delegate(description, delegate);
106
107 auto options = u_application_options_new_from_cmd_line(argc, argv);
108 instance = u_application_instance_new_from_description_with_options(description, options);
109
110 u_application_options_destroy(options);
111 u_application_description_destroy(description);
112
113 if (instance == nullptr)
114 throw std::runtime_error("Could not create ubuntu app instance!");
115 }
116
117 ~Application()
118 {
119 //FIXME: The symbol below is not exposed in papi library
120 //u_application_instance_unref(instance);
121 u_application_lifecycle_delegate_unref(delegate);
122 }
123
124 auto make_surface()
125 {
126 auto connection = u_application_instance_get_mir_connection(instance);
127 return std::make_unique<Surface>(connection);
128 }
129
130 static void resume(UApplicationOptions const*, void*)
131 {
132 std::cout << "Resuming" << std::endl;
133 }
134
135 static void stop(UApplicationArchive*, void*)
136 {
137 std::cout << "Stopping" << std::endl;
138 }
139
140private:
141 UApplicationLifecycleDelegate* delegate;
142 UApplicationInstance* instance;
143};
144
145void print_current_time(void)
146{
147 struct timespec spec;
148 clock_gettime(CLOCK_REALTIME, &spec);
149 std::cout << "time after swap(sec:nanosec) - " << spec.tv_sec;
150 std::cout << ":" << spec.tv_nsec << std::endl;
151}
152}
153
154int main(int argc, char *argv[])
155try
156{
157 Application app(argc, argv);
158
159 auto surface = app.make_surface();
160 surface->swap_buffers();
161
162 print_current_time();
163 std::cout << "Done." << std::endl;
164}
165catch(std::exception const& e)
166{
167 std::cerr << "Failed: " << e.what() << std::endl;
168}
169

Subscribers

People subscribed via source and target branches