aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/ui/buildinfohelper.py11
-rw-r--r--bitbake/lib/toaster/orm/database_writer.py69
2 files changed, 76 insertions, 4 deletions
diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index eb5332bf1fa..8df66eb1ed7 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -43,6 +43,7 @@ from orm.models import Package, Package_File, Target_Installed_Package, Target_F
from orm.models import Task_Dependency, Package_Dependency
from orm.models import Recipe_Dependency, Provides
from orm.models import Project, CustomImagePackage, CustomImageRecipe
+from orm.database_writer import DatabaseWriter
from bldcontrol.models import BuildEnvironment, BuildRequest
@@ -74,18 +75,18 @@ class ORMWrapper(object):
self.layer_version_built = []
self.task_objects = {}
self.recipe_objects = {}
+ self.database_writer = DatabaseWriter()
####### START: methods which write to the database
def get_or_create_default_project(self):
- return Project.objects.get_or_create_default_project()
+ return self.database_writer.get_or_create_default_project()
def save_object(self, obj):
- method_to_call = getattr(obj, 'save')
- return method_to_call()
+ return self.database_writer.save_object(obj)
def bulk_create(self, clazz, data):
- clazz.objects.bulk_create(data)
+ return self.database_writer.bulk_create(clazz, data)
####### END: methods which write to the database
@@ -1615,3 +1616,5 @@ class BuildInfoHelper(object):
# being incorrectly attached to the previous Toaster-triggered build;
# see https://bugzilla.yoctoproject.org/show_bug.cgi?id=9021
self.brbe = None
+
+ logger.info('********************* DATABASE WRITER STATS: %s' % self.orm_wrapper.database_writer.method_calls)
diff --git a/bitbake/lib/toaster/orm/database_writer.py b/bitbake/lib/toaster/orm/database_writer.py
new file mode 100644
index 00000000000..c35c02abc17
--- /dev/null
+++ b/bitbake/lib/toaster/orm/database_writer.py
@@ -0,0 +1,69 @@
+#
+# Toaster database access
+#
+# Copyright (C) 2013-2016 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import collections
+import logging
+logger = logging.getLogger("ToasterLogger")
+
+from orm.models import Project
+
+class DatabaseWriter(object):
+ """
+ Object which abstracts database writes so that they are not done
+ directly on Django models.
+
+ The purpose of this is to allow database write actions to be queued,
+ preventing multiple concurrent writes against the database.
+ """
+
+ def __init__(self):
+ self.method_calls = {}
+
+ def record_method_call(self, method_call, data=None):
+ if not method_call in self.method_calls:
+ self.method_calls[method_call] = 0
+ if data and isinstance(data, collections.Iterable):
+ self.method_calls[method_call] += len(data)
+ else:
+ self.method_calls[method_call] += 1
+
+ def get_or_create_default_project(self):
+ """
+ Get or create the default Project model instance
+ """
+ logger.info('DATABASE WRITER: get_or_create_default_project()')
+ self.record_method_call('get_or_create_default_project')
+ return Project.objects.get_or_create_default_project()
+
+ def save_object(self, obj):
+ """
+ Call save() on the Django Model object obj
+ """
+ logger.info('DATABASE WRITER: save_object(); class: %s' % obj.__class__.__name__)
+ self.record_method_call('save_object')
+ method_to_call = getattr(obj, 'save')
+ return method_to_call()
+
+ def bulk_create(self, clazz, data):
+ """
+ Call bulk_create() on the Django Model class clazz, passing data
+ (list of model instances)
+ """
+ logger.info('DATABASE WRITER: bulk_create(); class: %s' % clazz.__name__)
+ self.record_method_call('bulk_create', data)
+ return clazz.objects.bulk_create(data) \ No newline at end of file