Skip to content

Commit

Permalink
Update makefile and add license
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurkki14 committed May 4, 2019
1 parent fd256ee commit b843a70
Show file tree
Hide file tree
Showing 10 changed files with 796 additions and 22 deletions.
620 changes: 620 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -6,8 +6,8 @@ BINDIR=/usr/local/bin
all: perflogger

perflogger:
gcc $(SOURCES) -fpic -shared -DHOOK_DLSYM -o libperflogger.so
gcc $(SOURCES) -fpic -shared -DHOOK_DLSYM -m32 -o libperflogger32.so
gcc $(SOURCES) -fpic -shared -fvisibility=hidden -DHOOK_DLSYM -o libperflogger.so
gcc $(SOURCES) -fpic -shared -fvisibility=hidden -DHOOK_DLSYM -m32 -o libperflogger32.so

install: all
install -m 0644 -D -T libperflogger.conf /etc/ld.so.conf.d/libperflogger.conf
Expand Down
25 changes: 22 additions & 3 deletions src/glx_hooker.c
@@ -1,8 +1,27 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE

#include "libperflogger.h"
#include "symbol_resolver.h"

#include <dlfcn.h>
#include <string.h>
#include <stddef.h>
Expand All @@ -20,11 +39,11 @@ void* glXGetProcAddress(const unsigned char*);
void* glXGetProcAddressARB(const unsigned char*);

void *get_real_glx_function(const char *name) {
void *(*real_glXGetProcAddress)(const unsigned char*) =
void *(*real_glXGetProcAddress)(const unsigned char*) =
get_real_function(RTLD_NEXT, "glXGetProcAddress");
void *(*real_glXGetProcAddressARB)(const unsigned char*) =
get_real_function(RTLD_NEXT, "glXGetProcAddressARB");

void (*real_func)() = real_glXGetProcAddress((const unsigned char*) name);
if (real_func != NULL) {
return real_func;
Expand Down
19 changes: 19 additions & 0 deletions src/glx_hooker.h
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef GLX_HOOKER_H_
#define GLX_HOOKER_H_

Expand Down
46 changes: 31 additions & 15 deletions src/libperflogger.c
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
Expand All @@ -23,7 +42,7 @@ unsigned short frames = 0;
static uint64_t tot_frames = 0;
uint64_t start_time = 0;
uint64_t prev_utime = 0;
uint64_t avg_frametime = 0;
uint64_t avg_frametime = 0;

FILE *logfile;

Expand Down Expand Up @@ -69,7 +88,7 @@ void on_terminate() {
// Optional launch of gnuplot with the logfile
if (getenv(env_launch_plot) != NULL && atoi(getenv(env_launch_plot)) == 1) {
printf("Launch plot\n");
char* args[] = { "/bin/vlc"};
char* args[] = { "/bin/vlc"};
pid_t launch_pid;
extern char **environ;
//posix_spawnp(&launch_pid, "vlc", NULL, NULL, args, environ);
Expand All @@ -81,10 +100,10 @@ void on_terminate() {
sleep(5);
exit(EXIT_SUCCESS);*/
}

//wait(NULL);
}


/*char plot_launch_cmd[512];
sprintf(plot_launch_cmd, "gnuplot -p -e 'set ylabel \"%s\";set xlabel \"frames\";set yrange [0:100]; plot \"%s\" with lines' ", frametime_unit, log_location);
Expand Down Expand Up @@ -120,7 +139,7 @@ void fps_logger() {
//fclose(testf);


prev_utime = cur_utime;
prev_utime = cur_utime;

// Show the fps in stdout based on an env variable
if (cur_time > prev_time && use_stdout) {
Expand All @@ -129,7 +148,7 @@ void fps_logger() {
avg_frametime = 0;
// Print the fps to a file
//printf("%s\n", lod_dir);

frames = 0;
}
}
Expand All @@ -142,7 +161,7 @@ void init() {
// Get the startup time
start_time = time(NULL);
struct tm tm = *localtime((const long int*) &start_time);

struct timeval tv;
gettimeofday(&tv, NULL);
prev_utime = (tv.tv_sec * 1000000) + tv.tv_usec;
Expand All @@ -162,24 +181,24 @@ void init() {
// Set the signal handler
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = on_terminate;
action.sa_handler = on_terminate;
sigaction(SIGTERM, &action, NULL);
sigaction(SIGINT, &action, NULL);

//fprintf(stdout, "\n\nPerflogger starting...\n\n");
log_dir = getenv(env_log_dir);

pid = getpid();

//Get the process name
char proc_path[256] = "/proc/";
sprintf(proc_path, "/proc/%d/comm", pid);

FILE *proc_file = fopen(proc_path, "r");
char prog_name_tmp[128];
fscanf(proc_file, "%s", prog_name_tmp);
strcpy(prog_name, prog_name_tmp);

fscanf(proc_file, "%s", prog_name_tmp);
strcpy(prog_name, prog_name_tmp);

//printf("%s\n", prog_name);

Expand All @@ -202,6 +221,3 @@ void init() {
} else printf("Not logging to a file\n");
}
}



19 changes: 19 additions & 0 deletions src/libperflogger.h
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef LIBPERFLOGGER_H_
#define LIBPERFLOGGER_H_
#define PERFLOGGER_EXPORT __attribute__((__visibility__("default")))
Expand Down
19 changes: 19 additions & 0 deletions src/symbol_resolver.c
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE

#include "symbol_resolver.h"
Expand Down
24 changes: 24 additions & 0 deletions src/symbol_resolver.h
@@ -1 +1,25 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef SYMBOL_RESOLVER_H_
#define SYMBOL_RESOLVER_H_

void *get_real_function(void *handle, const char *name);

#endif
23 changes: 21 additions & 2 deletions src/vulkan_hooker.c
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE

#include "libperflogger.h"
Expand Down Expand Up @@ -40,7 +59,7 @@ void *get_hooked_vk_function(const char *name) {

PERFLOGGER_EXPORT
void *vkQueueSubmit(void *queue, void *submitCount, void *submits, void *fence) {
void *(*real_func)(void*, void*, void*, void*) =
void *(*real_func)(void*, void*, void*, void*) =
get_real_vk_function(__func__);
fps_logger();
return real_func(queue, submitCount, submits, fence);
Expand All @@ -49,7 +68,7 @@ void *vkQueueSubmit(void *queue, void *submitCount, void *submits, void *fence)
PERFLOGGER_EXPORT
void *vkGetInstanceProcAddr(void *instance, void *pName) {
void *(*real_func)(void*, void*) = get_real_vk_function(__func__);

void *hooked_func = get_hooked_vk_function((const char*) pName);
if (hooked_func != NULL) {
return hooked_func;
Expand Down
19 changes: 19 additions & 0 deletions src/vulkan_hooker.h
@@ -1,3 +1,22 @@
/*
This file is part of libperflogger.
Copyright (c) 2019 Jussi Kuokkanen
Libperflogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Libperflogger 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 libperflogger. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef VULKAN_HOOKER_H_
#define VULKAN_HOOKER_H_

Expand Down

0 comments on commit b843a70

Please sign in to comment.