Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ffd14c4
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
VERSION = 0.0.0 | ||
|
||
TEMPLATE = lib | ||
TARGET = systrace | ||
CONFIG -= qt | ||
|
||
SOURCES = \ | ||
src/systrace.c | ||
|
||
HEADERS = \ | ||
src/systrace.h | ||
|
||
headers.path = $$[QT_INSTALL_PREFIX]/include | ||
headers.files += $$HEADERS | ||
INSTALLS += headers | ||
|
||
target.path = $$[QT_INSTALL_LIBS] | ||
INSTALLS += target | ||
|
||
CONFIG += create_pc create_prl no_install_prl | ||
QMAKE_PKGCONFIG_DESTDIR = pkgconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Name: libsystrace | ||
Version: 0.0.0 | ||
Release: 1 | ||
Summary: A library for logging systrace data. | ||
Group: System/Libraries | ||
License: BSD | ||
URL: https://github.com/mer-packages/ | ||
Source0: %{name}-%{version}.tar.bz2 | ||
BuildRequires: qt5-qmake | ||
Requires(post): /sbin/ldconfig | ||
Requires(postun): /sbin/ldconfig | ||
|
||
%description | ||
%summary. | ||
|
||
%package devel | ||
Summary: Development files for %{name} | ||
Group: System/Libraries | ||
|
||
%description devel | ||
%{summary}. | ||
|
||
%prep | ||
%setup -q -n %{name}-%{version} | ||
|
||
%build | ||
%qmake5 | ||
make %{?_smp_mflags} | ||
|
||
%install | ||
rm -rf %{buildroot} | ||
%qmake5_install | ||
|
||
%clean | ||
rm -rf %{buildroot} | ||
|
||
%files | ||
%defattr(-,root,root,-) | ||
%{_libdir}/libsystrace.so.* | ||
|
||
%files devel | ||
%defattr(-,root,root,-) | ||
%{_libdir}/libsystrace.so | ||
%{_libdir}/pkgconfig/systrace.pc | ||
%{_includedir}/systrace.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2014 Jolla Ltd. <robin.burchell@jollamobile.com> | ||
* | ||
* You may use this file under the terms of the BSD license as follows: | ||
* | ||
* "Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Nemo Mobile nor the names of its contributors | ||
* may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "systrace.h" | ||
|
||
pthread_mutex_t systrace_trace_mutex; | ||
FILE *systrace_trace_target; | ||
|
||
__attribute__((constructor)) void systrace_init() | ||
{ | ||
pthread_mutex_init(&systrace_trace_mutex, NULL); | ||
systrace_trace_target = fopen("/sys/kernel/debug/tracing/trace_marker", "a"); | ||
if (!systrace_trace_target) | ||
perror("can't open /sys/kernel/debug/tracing/trace_marker"); | ||
} | ||
|
||
__attribute__((destructor)) void systrace_deinit() { | ||
pthread_mutex_destroy(&systrace_trace_mutex); | ||
if (systrace_trace_target) | ||
fclose(systrace_trace_target); | ||
} | ||
|
||
static char systrace_got_areas = 0; | ||
static char *systrace_areas = NULL; | ||
|
||
int systrace_should_trace(const char *module, const char *tracepoint) | ||
{ | ||
(void)tracepoint; /* not used at present */ | ||
if (!systrace_got_areas) { | ||
systrace_got_areas = 1; | ||
systrace_areas = getenv("SYSTRACE_AREA"); | ||
} | ||
|
||
if (!systrace_areas || !module) { | ||
/* no areas enabled */ | ||
return 0; | ||
} | ||
|
||
/* TODO: caching of areas would prevent constant rescanning, if we care. */ | ||
return strstr(systrace_areas, module) != NULL; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2014 Jolla Ltd. <robin.burchell@jollamobile.com> | ||
* | ||
* You may use this file under the terms of the BSD license as follows: | ||
* | ||
* "Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Nemo Mobile nor the names of its contributors | ||
* may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | ||
*/ | ||
|
||
#ifndef SYSTRACE_H | ||
|
||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
extern pthread_mutex_t systrace_trace_mutex; | ||
extern FILE *systrace_trace_target; | ||
extern int systrace_should_trace(const char *module, const char *tracepoint); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#define SYSTRACE_RECORD(module, what, tracepoint, message, ...) do { \ | ||
if (systrace_should_trace(module, tracepoint)) { \ | ||
pthread_mutex_lock(&systrace_trace_mutex); \ | ||
if (what == 'B') \ | ||
fprintf(systrace_trace_target, "B|%i|%s::%s" message "", \ | ||
getpid(), tracepoint, module, ##__VA_ARGS__); \ | ||
else if (what == 'E') \ | ||
fprintf(systrace_trace_target, "E"); \ | ||
else \ | ||
fprintf(systrace_trace_target, "C|%i|%s::%s-%i|" message "", \ | ||
getpid(), tracepoint, module, getpid(), ##__VA_ARGS__); \ | ||
fflush(systrace_trace_target); \ | ||
pthread_mutex_unlock(&systrace_trace_mutex); \ | ||
} \ | ||
} while(0) | ||
#define SYSTRACE_BEGIN(module, tracepoint, message, ...) SYSTRACE_RECORD(module, 'B', tracepoint, message, ##__VA_ARGS__) | ||
#define SYSTRACE_END(module, tracepoint, message, ...) SYSTRACE_RECORD(module, 'E', tracepoint, message, ##__VA_ARGS__) | ||
#define SYSTRACE_COUNTER(module, tracepoint, message, ...) SYSTRACE_RECORD(module, 'C', tracepoint, message, ##__VA_ARGS__) | ||
|
||
#endif // SYSTRACE_H |