Adding oprofile_example
authorjlance <jlance@9a892ef4-8035-4e6e-bfcf-8e83c02283af>
Tue, 22 Nov 2011 00:07:46 +0000 (00:07 +0000)
committerjlance <jlance@9a892ef4-8035-4e6e-bfcf-8e83c02283af>
Tue, 22 Nov 2011 00:07:46 +0000 (00:07 +0000)
DIRS
Makefile
oprofile_example/makefile [new file with mode: 0644]
oprofile_example/signal_parent.c [new file with mode: 0644]

diff --git a/DIRS b/DIRS
index 96b52c76e2e1c0c8f6593181a242a92b8101a9bf..dd833e55a819d8fa4a124f463b0f696ddc0f9d61 100644 (file)
--- a/DIRS
+++ b/DIRS
@@ -1,5 +1,6 @@
 DIRS :=
 
 DIRS := mem_util
+DIRS += oprofile_example
 
 DESTDIR ?=
index 5e3f44ab3a3d7c72b47d39f3e3998e77cd125476..c717f2a06489be7d3e2b63cb7c980de918f4bebb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,4 +35,15 @@ install_debug:
        else \
                echo "mem_util debug version not built - nothing to install!"; \
        fi
-
+       @if [ -e oprofile_example/Debug1/signal_parent.opt ] ; then \
+               install oprofile_example/Debug1/signal_parent.opt $(DESTDIR)/usr/bin/signal_parent.opt ; \
+               echo "oprofile_example optimized debug version installed."; \
+       else \
+               echo "oprofile_example optimized debug version not built - nothing to install!"; \
+       fi
+       @if [ -e oprofile_example/Debug/signal_parent ] ; then \
+               install oprofile_example/Debug/signal_parent $(DESTDIR)/usr/bin/signal_parent ; \
+               echo "oprofile_example debug version installed."; \
+       else \
+               echo "oprofile_example debug version not built - nothing to install!"; \
+       fi
diff --git a/oprofile_example/makefile b/oprofile_example/makefile
new file mode 100644 (file)
index 0000000..c1ff3b2
--- /dev/null
@@ -0,0 +1,122 @@
+#   ----------------------------------------------------------------------------
+#  @file   Makefile
+#
+#  @path   
+#
+#  @desc   Makefile for oprofile_example (Debug and Release versions)
+#
+#  @ver    1.10
+#   ----------------------------------------------------------------------------
+#  Copyright (c) Texas Instruments Incorporated 2002-2009
+#
+#  Use of this software is controlled by the terms and conditions found in the
+#  license agreement under which this software has been supplied or provided.
+#
+
+#   ----------------------------------------------------------------------------
+#   Included defined variables
+#   ----------------------------------------------------------------------------
+include ../../../Rules.make
+
+#   ----------------------------------------------------------------------------
+#   Variables passed in externally
+#   ----------------------------------------------------------------------------
+PLATFORM ?=
+ARCH ?=
+CROSS_COMPILE ?=
+
+#   ----------------------------------------------------------------------------
+#   Name of the Linux compiler
+#   ----------------------------------------------------------------------------
+CC := $(CROSS_COMPILE)gcc
+
+#   ----------------------------------------------------------------------------
+#   General options, sources and libraries
+#   ----------------------------------------------------------------------------
+NAME := signal_parent
+SRCS :=  signal_parent.c
+HDRS := 
+OBJS :=
+DEBUG :=
+BIN := signal_parent
+
+#   ----------------------------------------------------------------------------
+#   Compiler and Linker flags for Debug
+#   ----------------------------------------------------------------------------
+OBJDIR_D := Debug
+BINDIR_D := $(OBJDIR_D)
+LIBS_D := $(LIBS)
+OBJS_D := $(SRCS:%.c=$(OBJDIR_D)/%.o)
+ALL_DEBUG := -g3 -gdwarf-2
+
+OBJDIR_D1 := Debug1
+BINDIR_D1 := $(OBJDIR_D1)
+OBJS_D1 := $(SRCS:%.c=$(OBJDIR_D1)/%.o)
+
+#   ----------------------------------------------------------------------------
+#   Compiler include directories 
+#   ----------------------------------------------------------------------------
+INCLUDES := 
+
+#   ----------------------------------------------------------------------------
+#   All compiler options to be passed to the command line
+#   ----------------------------------------------------------------------------
+ALL_CFLAGS := $(INCLUDES)                   \
+              -march=armv5te                \
+              -mtune=arm926ej-s             \
+              -static                       \
+              -c                            \
+              $(CFLAGS)
+
+LDFLAGS :=    -march=armv5te                \
+              -mtune=arm926ej-s
+
+#   ----------------------------------------------------------------------------
+#   Compiler symbol definitions 
+#   ----------------------------------------------------------------------------
+DEFS :=
+
+#   ----------------------------------------------------------------------------
+#   Compiler and Linker procedure
+#   From this point and on changes are very unlikely.
+#   ----------------------------------------------------------------------------
+.PHONY: all
+all: debug debug1 release
+
+#   ----------------------------------------------------------------------------
+#   Building Debug... 
+#   ----------------------------------------------------------------------------
+.PHONY: debug
+debug: $(BINDIR_D)/$(BIN)
+
+$(BINDIR_D)/$(BIN): $(OBJS_D)
+       @echo Compiling Debug...
+       $(CC) -o $@ $(OBJS_D) $(LIBS_D) $(LDFLAGS)  -Wl,-Map,$(BINDIR_D)/$(NAME).map 
+
+$(OBJDIR_D)/%.o : %.c $(HDRS)
+       $(CC) $(ALL_DEBUG) $(DEFS) $(ALL_CFLAGS) -o$@ $<
+
+#   ----------------------------------------------------------------------------
+#   Building Debug... 
+#   ----------------------------------------------------------------------------
+.PHONY: debug1
+debug: $(BINDIR_D1)/$(BIN).opt
+
+$(BINDIR_D1)/$(BIN).opt: $(OBJS_D1)
+       @echo Compiling Debug...
+       $(CC) -o $@ $(OBJS_D1) $(LIBS_D) $(LDFLAGS)  -Wl,-Map,$(BINDIR_D1)/$(NAME).map 
+
+$(OBJDIR_D1)/%.o : %.c $(HDRS)
+       $(CC) $(ALL_DEBUG) $(DEFS) -DUSE_SIGNALS $(ALL_CFLAGS) -o$@ $<
+#   ----------------------------------------------------------------------------
+#   Building Release... 
+#   ----------------------------------------------------------------------------
+
+.PHONY: release
+release:
+
+.PHONY: clean
+clean:
+       @rm -f $(OBJDIR_D)/*
+       @rm -f $(OBJDIR_D1)/*
+
diff --git a/oprofile_example/signal_parent.c b/oprofile_example/signal_parent.c
new file mode 100644 (file)
index 0000000..7cd55a0
--- /dev/null
@@ -0,0 +1,64 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h> 
+
+static int signal_parent = 0;
+
+void mysig(int sig)
+{
+    int status;
+    pid_t pid;
+        
+    printf("Signal %d \n", sig);
+
+    if (sig == SIGALRM)
+    {
+       signal_parent = 1;
+    }
+    if (sig == SIGCLD)
+    {
+       // harvest terminated DEFUNCT child process
+       pid = waitpid(-1, &status, WNOHANG); 
+       printf(" Child Process(%d) terminated with a status of %d\n",
+            pid, status); 
+    }
+}
+
+/*  In main, we tell the child process to wait for ten seconds
+    before sending a SIGALRM signal to its parent.  */
+
+int main()
+{
+    int pid;
+
+    printf("child signals parent application starting\n");
+
+    if((pid = fork()) == 0) {
+    // Child process
+        sleep(10);
+    // Wake up parent process with a SIGALRM
+        kill(getppid(), SIGALRM);
+        exit(0);
+    }
+
+/*  The parent process arranges to catch SIGALRM with a call to signal
+    and then waits for the inevitable.  */
+
+    (void) signal(SIGALRM, mysig);
+    (void) signal(SIGCLD, mysig);
+    do
+    {
+#ifdef USE_SIGNALS
+        printf("Parent blocks and waits for child\n");
+        pause(); // Wait for any signal call
+#endif
+    } while(!signal_parent);
+    
+    printf("Got signal from child\n");
+
+    printf("done\n");
+    exit(0);
+}