summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/Child.cpp')
-rw-r--r--daemon/Child.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/daemon/Child.cpp b/daemon/Child.cpp
index ca33561..1901ecc 100644
--- a/daemon/Child.cpp
+++ b/daemon/Child.cpp
@@ -26,13 +26,13 @@
26#include "Driver.h" 26#include "Driver.h"
27#include "PerfSource.h" 27#include "PerfSource.h"
28#include "DriverSource.h" 28#include "DriverSource.h"
29#include "UserSpaceSource.h"
30#include "ExternalSource.h" 29#include "ExternalSource.h"
30#include "UserSpaceSource.h"
31 31
32static sem_t haltPipeline, senderThreadStarted, startProfile, senderSem; // Shared by Child and spawned threads 32static sem_t haltPipeline, senderThreadStarted, startProfile, senderSem; // Shared by Child and spawned threads
33static Source *primarySource = NULL; 33static Source *primarySource = NULL;
34static Source *userSpaceSource = NULL;
35static Source *externalSource = NULL; 34static Source *externalSource = NULL;
35static Source *userSpaceSource = NULL;
36static Sender* sender = NULL; // Shared by Child.cpp and spawned threads 36static Sender* sender = NULL; // Shared by Child.cpp and spawned threads
37Child* child = NULL; // shared by Child.cpp and main.cpp 37Child* child = NULL; // shared by Child.cpp and main.cpp
38 38
@@ -147,16 +147,16 @@ static void *senderThread(void *) {
147 prctl(PR_SET_NAME, (unsigned long)&"gatord-sender", 0, 0, 0); 147 prctl(PR_SET_NAME, (unsigned long)&"gatord-sender", 0, 0, 0);
148 sem_wait(&haltPipeline); 148 sem_wait(&haltPipeline);
149 149
150 while (!primarySource->isDone() || (userSpaceSource != NULL && !userSpaceSource->isDone()) || (externalSource != NULL && !externalSource->isDone())) { 150 while (!primarySource->isDone() ||
151 !externalSource->isDone() ||
152 (userSpaceSource != NULL && !userSpaceSource->isDone())) {
151 sem_wait(&senderSem); 153 sem_wait(&senderSem);
152 154
153 primarySource->write(sender); 155 primarySource->write(sender);
156 externalSource->write(sender);
154 if (userSpaceSource != NULL) { 157 if (userSpaceSource != NULL) {
155 userSpaceSource->write(sender); 158 userSpaceSource->write(sender);
156 } 159 }
157 if (externalSource != NULL) {
158 externalSource->write(sender);
159 }
160 } 160 }
161 161
162 // write end-of-capture sequence 162 // write end-of-capture sequence
@@ -202,6 +202,10 @@ void Child::initialization() {
202void Child::endSession() { 202void Child::endSession() {
203 gSessionData->mSessionIsActive = false; 203 gSessionData->mSessionIsActive = false;
204 primarySource->interrupt(); 204 primarySource->interrupt();
205 externalSource->interrupt();
206 if (userSpaceSource != NULL) {
207 userSpaceSource->interrupt();
208 }
205 sem_post(&haltPipeline); 209 sem_post(&haltPipeline);
206} 210}
207 211
@@ -227,9 +231,9 @@ void Child::run() {
227 231
228 // Set up the driver; must be done after gSessionData->mPerfCounterType[] is populated 232 // Set up the driver; must be done after gSessionData->mPerfCounterType[] is populated
229 if (!gSessionData->perf.isSetup()) { 233 if (!gSessionData->perf.isSetup()) {
230 primarySource = new DriverSource(&senderSem, &startProfile); 234 primarySource = new DriverSource(&senderSem, &startProfile);
231 } else { 235 } else {
232 primarySource = new PerfSource(&senderSem, &startProfile); 236 primarySource = new PerfSource(&senderSem, &startProfile);
233 } 237 }
234 238
235 // Initialize all drivers 239 // Initialize all drivers
@@ -280,11 +284,18 @@ void Child::run() {
280 thread_creation_success = false; 284 thread_creation_success = false;
281 } else if (socket && pthread_create(&stopThreadID, NULL, stopThread, NULL)) { 285 } else if (socket && pthread_create(&stopThreadID, NULL, stopThread, NULL)) {
282 thread_creation_success = false; 286 thread_creation_success = false;
283 } else if (pthread_create(&senderThreadID, NULL, senderThread, NULL)){ 287 } else if (pthread_create(&senderThreadID, NULL, senderThread, NULL)) {
284 thread_creation_success = false; 288 thread_creation_success = false;
285 } 289 }
286 290
287 if (gSessionData->hwmon.countersEnabled()) { 291 externalSource = new ExternalSource(&senderSem);
292 if (!externalSource->prepare()) {
293 logg->logError(__FILE__, __LINE__, "Unable to prepare for capture");
294 handleException();
295 }
296 externalSource->start();
297
298 if (gSessionData->hwmon.countersEnabled() || gSessionData->fsDriver.countersEnabled()) {
288 userSpaceSource = new UserSpaceSource(&senderSem); 299 userSpaceSource = new UserSpaceSource(&senderSem);
289 if (!userSpaceSource->prepare()) { 300 if (!userSpaceSource->prepare()) {
290 logg->logError(__FILE__, __LINE__, "Unable to prepare for capture"); 301 logg->logError(__FILE__, __LINE__, "Unable to prepare for capture");
@@ -292,14 +303,6 @@ void Child::run() {
292 } 303 }
293 userSpaceSource->start(); 304 userSpaceSource->start();
294 } 305 }
295 if (access("/tmp/gator", F_OK) == 0) {
296 externalSource = new ExternalSource(&senderSem);
297 if (!externalSource->prepare()) {
298 logg->logError(__FILE__, __LINE__, "Unable to prepare for capture");
299 handleException();
300 }
301 externalSource->start();
302 }
303 306
304 if (!thread_creation_success) { 307 if (!thread_creation_success) {
305 logg->logError(__FILE__, __LINE__, "Failed to create gator threads"); 308 logg->logError(__FILE__, __LINE__, "Failed to create gator threads");
@@ -312,12 +315,10 @@ void Child::run() {
312 // Start profiling 315 // Start profiling
313 primarySource->run(); 316 primarySource->run();
314 317
315 if (externalSource != NULL) {
316 externalSource->join();
317 }
318 if (userSpaceSource != NULL) { 318 if (userSpaceSource != NULL) {
319 userSpaceSource->join(); 319 userSpaceSource->join();
320 } 320 }
321 externalSource->join();
321 322
322 // Wait for the other threads to exit 323 // Wait for the other threads to exit
323 pthread_join(senderThreadID, NULL); 324 pthread_join(senderThreadID, NULL);
@@ -337,8 +338,8 @@ void Child::run() {
337 338
338 logg->logMessage("Profiling ended."); 339 logg->logMessage("Profiling ended.");
339 340
340 delete externalSource;
341 delete userSpaceSource; 341 delete userSpaceSource;
342 delete externalSource;
342 delete primarySource; 343 delete primarySource;
343 delete sender; 344 delete sender;
344 delete localCapture; 345 delete localCapture;