Index: branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
===================================================================
--- branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs	(revision 12584)
+++ branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs	(revision 12691)
@@ -68,19 +68,21 @@
     public Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds) {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      return trans.UseTransaction(() => {
-        var t = DT.Convert.ToEntity(task);
-        t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId }));
-
-        t.JobData = DT.Convert.ToEntity(taskData);
-        t.JobData.LastUpdate = DateTime.Now;
-
-        optimizedDao.AddTask(t);
-
-        dao.AssignJobToResource(t.TaskId, resourceIds);
-
-        optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
-
-        return t.TaskId;
-      }, false, true);
+      using (new PerformanceLogger("Old_AddTask")) {
+        return trans.UseTransaction(() => {
+          var t = DT.Convert.ToEntity(task);
+          t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId }));
+
+          t.JobData = DT.Convert.ToEntity(taskData);
+          t.JobData.LastUpdate = DateTime.Now;
+
+          optimizedDao.AddTask(t);
+
+          dao.AssignJobToResource(t.TaskId, resourceIds);
+
+          optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
+
+          return t.TaskId;
+        }, false, true);
+      }
     }
 
@@ -88,5 +90,9 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
       task.ParentTaskId = parentTaskId;
-      return AddTask(task, taskData, optimizedDao.GetAssignedResourceIds(parentTaskId).ToList());
+      List<Guid> list = null;
+      using (new PerformanceLogger("Old_AddChildTask")) {
+        list = optimizedDao.GetAssignedResourceIds(parentTaskId).ToList();
+      }
+      return AddTask(task, taskData, list);
     }
 
@@ -94,7 +100,9 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
       author.AuthorizeForTask(taskId, Permission.Read);
-      return trans.UseTransaction(() => {
-        return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId));
-      }, false, false);
+      using (new PerformanceLogger("Old_GetTask")) {
+        return trans.UseTransaction(() => {
+          return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId));
+        }, false, false);
+      }
     }
 
@@ -134,8 +142,9 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
       author.AuthorizeForJob(jobId, Permission.Read);
-
-      return trans.UseTransaction(() => {
-        return optimizedDao.GetLightweightTasks(jobId).ToArray();
-      }, false, true);
+      using (new PerformanceLogger("Old_GetLightweightJobTasks")) {
+        return trans.UseTransaction(() => {
+          return optimizedDao.GetLightweightTasks(jobId).ToArray();
+        }, false, true);
+      }
     }
 
@@ -143,8 +152,9 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
       author.AuthorizeForJob(jobId, Permission.Read);
-
-      return trans.UseTransaction(() => {
-        return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
-      }, false, false);
+      using (new PerformanceLogger("Old_GetLightweightJobTasksWithoutStateLog")) {
+        return trans.UseTransaction(() => {
+          return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
+        }, false, false);
+      }
     }
 
@@ -153,7 +163,9 @@
       author.AuthorizeForTask(taskId, Permission.Read);
 
-      return trans.UseTransaction(() => {
-        return dao.GetTaskData(taskId);
-      });
+      using (new PerformanceLogger("Old_GetTaskData")) {
+        return trans.UseTransaction(() => {
+          return dao.GetTaskData(taskId);
+        });
+      }
     }
 
@@ -162,8 +174,10 @@
       author.AuthorizeForTask(taskDto.Id, Permission.Full);
 
-      trans.UseTransaction(() => {
-        var task = optimizedDao.GetTaskByDto(taskDto);
-        optimizedDao.UpdateTask(task);
-      });
+      using (new PerformanceLogger("Old_UpdateTask")) {
+        trans.UseTransaction(() => {
+          var task = optimizedDao.GetTaskByDto(taskDto);
+          optimizedDao.UpdateTask(task);
+        });
+      }
     }
 
@@ -172,14 +186,16 @@
       author.AuthorizeForTask(task.Id, Permission.Full);
 
-      trans.UseTransaction(() => {
-        var t = optimizedDao.GetTaskByDto(task);
-        optimizedDao.UpdateTask(t);
-      });
-
-      trans.UseTransaction(() => {
-        var data = optimizedDao.GetTaskDataByDto(taskData);
-        data.LastUpdate = DateTime.Now;
-        optimizedDao.UpdateTaskData(data);
-      });
+      using (new PerformanceLogger("Old_UpdateTaskData")) {
+        trans.UseTransaction(() => {
+          var t = optimizedDao.GetTaskByDto(task);
+          optimizedDao.UpdateTask(t);
+        });
+
+        trans.UseTransaction(() => {
+          var data = optimizedDao.GetTaskDataByDto(taskData);
+          data.LastUpdate = DateTime.Now;
+          optimizedDao.UpdateTaskData(data);
+        });
+      }
     }
 
@@ -207,21 +223,22 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
       author.AuthorizeForTask(taskId, Permission.Full);
-
-      return trans.UseTransaction(() => {
-        var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);
-
-        if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) {
-          task.Command = null;
-        } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) {
-          task.Command = null;
-        } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) {
-          task.Command = null;
-        } else if (taskState == TaskState.Paused && !task.Command.HasValue) {
-          // slave paused and uploaded the task (no user-command) -> set waiting.
-          task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);
-        }
-
-        return DT.Convert.ToDto(task);
-      });
+      using (new PerformanceLogger("Old_UpdateTaskState")) {
+        return trans.UseTransaction(() => {
+          var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);
+
+          if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) {
+            task.Command = null;
+          } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) {
+            task.Command = null;
+          } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) {
+            task.Command = null;
+          } else if (taskState == TaskState.Paused && !task.Command.HasValue) {
+            // slave paused and uploaded the task (no user-command) -> set waiting.
+            task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);
+          }
+
+          return DT.Convert.ToDto(task);
+        });
+      }
     }
 
@@ -281,28 +298,32 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
       author.AuthorizeForJob(id, Permission.Read);
-      return trans.UseTransaction(() => {
-        var job = dao.GetJobs(x =>
-              x.JobId == id
-              && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0)
-            ).FirstOrDefault();
-        if (job != null) {
-          job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
-          job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
-        }
-        return job;
-      });
+      using (new PerformanceLogger("Old_GetJob")) {
+        return trans.UseTransaction(() => {
+          var job = dao.GetJobs(x =>
+                x.JobId == id
+                && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0)
+              ).FirstOrDefault();
+          if (job != null) {
+            job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
+            job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
+          }
+          return job;
+        });
+      }
     }
 
     public IEnumerable<Job> GetJobs() {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      return trans.UseTransaction(() => {
-        var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
-        foreach (var job in jobs) {
-          author.AuthorizeForJob(job.Id, Permission.Read);
-          job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
-          job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
-        }
-        return jobs;
-      });
+      using (new PerformanceLogger("Old_GetJobs")) {
+        return trans.UseTransaction(() => {
+          var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
+          foreach (var job in jobs) {
+            author.AuthorizeForJob(job.Id, Permission.Read);
+            job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
+            job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
+          }
+          return jobs;
+        });
+      }
     }
 
@@ -321,9 +342,11 @@
     public Guid AddJob(Job jobDto) {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      return trans.UseTransaction(() => {
-        jobDto.OwnerUserId = userManager.CurrentUserId;
-        jobDto.DateCreated = DateTime.Now;
-        return dao.AddJob(jobDto);
-      });
+      using (new PerformanceLogger("Old_AddJob")) {
+        return trans.UseTransaction(() => {
+          jobDto.OwnerUserId = userManager.CurrentUserId;
+          jobDto.DateCreated = DateTime.Now;
+          return dao.AddJob(jobDto);
+        });
+      }
     }
 
@@ -370,9 +393,12 @@
     public IEnumerable<JobPermission> GetJobPermissions(Guid jobId) {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      return trans.UseTransaction(() => {
-        DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId);
-        if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment"));
-        return dao.GetJobPermissions(x => x.JobId == jobId);
-      });
+      using (new PerformanceLogger("GetJobPermissions")) {
+        return trans.UseTransaction(() => {
+          DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId);
+          if (currentUserPermission != DA.Permission.Full)
+            throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment"));
+          return dao.GetJobPermissions(x => x.JobId == jobId);
+        });
+      }
     }
 
@@ -389,41 +415,45 @@
         slaveInfo.OwnerUserId = userManager.CurrentUserId;
 
-      trans.UseTransaction(() => {
-        var slave = dao.GetSlave(slaveInfo.Id);
-
-        if (slave == null) {
-          dao.AddSlave(slaveInfo);
-        } else {
-          slave.Name = slaveInfo.Name;
-          slave.Description = slaveInfo.Description;
-          slave.OwnerUserId = slaveInfo.OwnerUserId;
-
-          slave.Cores = slaveInfo.Cores;
-          slave.CpuArchitecture = slaveInfo.CpuArchitecture;
-          slave.CpuSpeed = slaveInfo.CpuSpeed;
-          slave.FreeCores = slaveInfo.FreeCores;
-          slave.FreeMemory = slaveInfo.FreeMemory;
-          slave.Memory = slaveInfo.Memory;
-          slave.OperatingSystem = slaveInfo.OperatingSystem;
-
-          slave.LastHeartbeat = DateTime.Now;
-          slave.SlaveState = SlaveState.Idle;
-
-          // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 
-
-          dao.UpdateSlave(slave);
-        }
-      });
+      using (new PerformanceLogger("Old_Hello")) {
+        trans.UseTransaction(() => {
+          var slave = dao.GetSlave(slaveInfo.Id);
+
+          if (slave == null) {
+            dao.AddSlave(slaveInfo);
+          } else {
+            slave.Name = slaveInfo.Name;
+            slave.Description = slaveInfo.Description;
+            slave.OwnerUserId = slaveInfo.OwnerUserId;
+
+            slave.Cores = slaveInfo.Cores;
+            slave.CpuArchitecture = slaveInfo.CpuArchitecture;
+            slave.CpuSpeed = slaveInfo.CpuSpeed;
+            slave.FreeCores = slaveInfo.FreeCores;
+            slave.FreeMemory = slaveInfo.FreeMemory;
+            slave.Memory = slaveInfo.Memory;
+            slave.OperatingSystem = slaveInfo.OperatingSystem;
+
+            slave.LastHeartbeat = DateTime.Now;
+            slave.SlaveState = SlaveState.Idle;
+
+            // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId 
+
+            dao.UpdateSlave(slave);
+          }
+        });
+      }
     }
 
     public void GoodBye(Guid slaveId) {
       authen.AuthenticateForAnyRole(HiveRoles.Slave);
-      trans.UseTransaction(() => {
-        var slave = dao.GetSlave(slaveId);
-        if (slave != null) {
-          slave.SlaveState = SlaveState.Offline;
-          dao.UpdateSlave(slave);
-        }
-      });
+      using (new PerformanceLogger("Old_GoodBye")) {
+        trans.UseTransaction(() => {
+          var slave = dao.GetSlave(slaveId);
+          if (slave != null) {
+            slave.SlaveState = SlaveState.Offline;
+            dao.UpdateSlave(slave);
+          }
+        });
+      }
     }
     #endregion
@@ -435,10 +465,11 @@
       List<MessageContainer> result = new List<MessageContainer>();
       try {
-        result = heartbeatManager.ProcessHeartbeat(heartbeat);
+        using (new PerformanceLogger("Old_ProcessHeartbeat")) {
+          result = heartbeatManager.ProcessHeartbeat(heartbeat);
+        }
       }
       catch (Exception ex) {
         DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Exception processing Heartbeat: " + ex.ToString());
       }
-
       if (HeuristicLab.Services.Hive.Properties.Settings.Default.TriggerEventManagerInHeartbeat) {
         TriggerEventManager(false);
@@ -489,7 +520,9 @@
     public IEnumerable<Plugin> GetPlugins() {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
-      return trans.UseTransaction(() => {
-        return dao.GetPlugins(x => x.Hash != null);
-      });
+      using (new PerformanceLogger("Old_GetPlugins")) {
+        return trans.UseTransaction(() => {
+          return dao.GetPlugins(x => x.Hash != null);
+        });
+      }
     }
 
@@ -497,10 +530,12 @@
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
       var pluginDatas = new List<PluginData>();
-      return trans.UseTransaction(() => {
-        foreach (Guid guid in pluginIds) {
-          pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList());
-        }
-        return pluginDatas;
-      });
+      using (new PerformanceLogger("Old_GetPluginData")) {
+        return trans.UseTransaction(() => {
+          foreach (Guid guid in pluginIds) {
+            pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList());
+          }
+          return pluginDatas;
+        });
+      }
     }
 
@@ -654,12 +689,14 @@
     public Guid GetResourceId(string resourceName) {
       authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      return trans.UseTransaction(() => {
-        var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
-        if (resource != null) {
-          return resource.Id;
-        } else {
-          return Guid.Empty;
-        }
-      });
+      using (new PerformanceLogger("Old_GetResourceId")) {
+        return trans.UseTransaction(() => {
+          var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
+          if (resource != null) {
+            return resource.Id;
+          } else {
+            return Guid.Empty;
+          }
+        });
+      }
     }
 
