[PATCH 1/5] CodeSamples: Remove gprof-helper.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From 5d81fb381768463ac02881edb5e8caf3896e9c48 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@xxxxxxxxx>
Date: Tue, 6 Jun 2017 00:06:44 +0900
Subject: [PATCH 1/5] CodeSamples: Remove gprof-helper.c

Paul confirmed that he no longer needs this.
Also remove its entry in .gitignore.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 CodeSamples/.gitignore     |   1 -
 CodeSamples/gprof-helper.c | 118 ---------------------------------------------
 2 files changed, 119 deletions(-)
 delete mode 100644 CodeSamples/gprof-helper.c

diff --git a/CodeSamples/.gitignore b/CodeSamples/.gitignore
index e116055..042e44d 100644
--- a/CodeSamples/.gitignore
+++ b/CodeSamples/.gitignore
@@ -1,3 +1,2 @@
-/gprof-helper.c
 /Makefile.arch
 /api.h
diff --git a/CodeSamples/gprof-helper.c b/CodeSamples/gprof-helper.c
deleted file mode 100644
index e413b17..0000000
--- a/CodeSamples/gprof-helper.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* gprof-helper.c -- preload library to profile pthread-enabled programs 
- * 
- * Authors: Sam Hocevar <sam at zoy dot org> 
- *          Daniel Jönsson <danieljo at fagotten dot org> 
- * 
- *  This program is free software; you can redistribute it and/or 
- *  modify it under the terms of the Do What The Fuck You Want To 
- *  Public License as published by Banlu Kemiyatorn. See 
- *  http://sam.zoy.org/projects/COPYING.WTFPL for more details. 
- * 
- * Compilation example: 
- * gcc -shared -fPIC gprof-helper.c -o gprof-helper.so -lpthread -ldl 
- * 
- * Usage example: 
- * LD_PRELOAD=./gprof-helper.so your_program 
- */ 
- 
-#define _GNU_SOURCE 
-#include <sys/time.h> 
-#include <stdio.h> 
-#include <stdlib.h> 
-#include <dlfcn.h> 
-#include <pthread.h> 
- 
-static void * wrapper_routine(void *); 
- 
-/* Original pthread function */ 
-static int (*pthread_create_orig)(pthread_t *__restrict,
-				  __const pthread_attr_t *__restrict,
-				  void *(*)(void *), void *__restrict) = NULL; 
- 
-/* Library initialization function */ 
-void wooinit(void) __attribute__((constructor)); 
- 
-void wooinit(void) 
-{ 
-	pthread_create_orig = dlsym(RTLD_NEXT, "pthread_create"); 
-	fprintf(stderr, "pthreads: using profiling hooks for gprof\n"); 
-	if(pthread_create_orig == NULL) { 
-		char *error = dlerror(); 
-		if(error == NULL) { 
-			error = "pthread_create is NULL"; 
-		} 
-		fprintf(stderr, "%s\n", error); 
-		exit(EXIT_FAILURE); 
-	} 
-} 
- 
-/* Our data structure passed to the wrapper */ 
-typedef struct wrapper_s 
-{ 
-	void * (*start_routine)(void *); 
-	void * arg; 
-
-	pthread_mutex_t lock; 
-	pthread_cond_t  wait; 
-
-	struct itimerval itimer; 
-
-} wrapper_t; 
- 
-/* The wrapper function in charge for setting the itimer value */ 
-static void * wrapper_routine(void * data) 
-{ 
-	/* Put user data in thread-local variables */ 
-	void * (*start_routine)(void *) = ((wrapper_t*)data)->start_routine; 
-	void * arg = ((wrapper_t*)data)->arg; 
-
-	/* Set the profile timer value */ 
-	setitimer(ITIMER_PROF, &((wrapper_t*)data)->itimer, NULL); 
-
-	/* Tell the calling thread that we don't need its data anymore */ 
-	pthread_mutex_lock(&((wrapper_t*)data)->lock); 
-	pthread_cond_signal(&((wrapper_t*)data)->wait); 
-	pthread_mutex_unlock(&((wrapper_t*)data)->lock); 
-
-	/* Call the real function */ 
-	return start_routine(arg); 
-} 
- 
-/* Our wrapper function for the real pthread_create() */ 
-int pthread_create(pthread_t *__restrict thread,
-		   __const pthread_attr_t *__restrict attr,
-		   void * (*start_routine)(void *),
-		   void *__restrict arg) 
-{
-	wrapper_t wrapper_data; 
-	int i_return; 
-
-	/* Initialize the wrapper structure */ 
-	wrapper_data.start_routine = start_routine; 
-	wrapper_data.arg = arg; 
-	getitimer(ITIMER_PROF, &wrapper_data.itimer); 
-	pthread_cond_init(&wrapper_data.wait, NULL); 
-	pthread_mutex_init(&wrapper_data.lock, NULL); 
-	pthread_mutex_lock(&wrapper_data.lock); 
-
-	/* The real pthread_create call */ 
-	i_return = pthread_create_orig(thread,
-				       attr,
-				       &wrapper_routine,
-				       &wrapper_data); 
-
-	/*
-	 * If the thread was successfully spawned, wait for the data
-	 * to be released
-	 */ 
-
-	if(i_return == 0) { 
-		pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock); 
-	} 
-
-	pthread_mutex_unlock(&wrapper_data.lock); 
-	pthread_mutex_destroy(&wrapper_data.lock); 
-	pthread_cond_destroy(&wrapper_data.wait); 
-
-	return i_return; 
-} 
-- 
2.7.4


--
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux