Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1359 from MartinNowak/profilegc
Browse files Browse the repository at this point in the history
follow up for -profile=gc
  • Loading branch information
MartinNowak committed Sep 2, 2015
2 parents 281bf60 + 89d836e commit ba9ea9e
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 121 deletions.
145 changes: 34 additions & 111 deletions changelog.dd
@@ -1,129 +1,52 @@
$(VERSION 060, mmm dd, 2012, =================================================,
Ddoc

$(WHATSNEW
$(LI core.time: Non-generic aliases for dur have been added (i.e seconds(),
minutes(), etc.))
$(LI For functions which have a version which takes a core.time.Duration
and another version which takes an integral value, the version which
takes an integral value has now been deprecated.)
$(LI clear() has been renamed to destroy(). clear() remains as an alias to
destroy() but has been scheduled for deprecation. Please use destroy()
instead.)
$(LI Exception backtracing has been implemented for FreeBSD.)
$(LI A FreeBSD-specific module (core.sys.freebsd.dlfcn) has been added for
the dlfcn.h C header for that platform.)
$(LI Modules for the execinfo.h C header have been added for FreeBSD, OS X,
and Linux (core.sys.freebsd.execinfo, core.sys.osx.execinfo, and
core.sys.linux.execinfo, respectively).)
$(LI Several core.stdc modules have been annotated with safety attributes.)
$(LI Most functions in core.bitop have been marked @safe pure nothrow.)
$(LI thread_stackBottom() and thread_stackTop() now require the current
thread to be attached to the runtime (with thread_attachThis()).)
$(LI A new atomicFence() instruction has been added to core.atomic.)
$(LI An experimental critical regions API has been added. See the functions
thread_enterCriticalRegion(), thread_exitCriticalRegion(), and
thread_inCriticalRegion() in core.thread. This API is not set in stone, so
the documentation is not yet processed by Ddoc and the interface may
change over time.)
$(LI The capacity() and reserve() functions have been marked pure nothrow.)
$(LI The thread_needLock() function has been removed. It was largely
considered useless since single core systems are very rare today (and it
didn't result in significant enough optimization anyway).)
$(LI The thread_scanAll() function now scans the calling thread's stack
and registers in addition to other threads'.)
$(LI All of core.sys.posix.pthread has been marked nothrow.)
$(LI A thread_setThis() function has been added to core.thread. This is a
low-level function primarily useful when side-stepping DRuntime's threading
infrastructure.)
$(LI Some core.stdc.stdio functions have been marked pure.)
$(LI Several core.memory functions have been marked pure and nothrow.)
$(LI core.stdc.stdarg now supports vector types.)
$(LI All core.sys.windows.windows functions are now nothrow. Some have been
marked pure as well.)
$(LI SYSTEM_INFO, GetSystemInfo(), and GetNativeSystemInfo() have been
added to core.sys.windows.windows.)
$(LI thread_attachThis() and thread_detachThis() are now more forgiving
about attaching already-attached threads and detaching already-detached
threads.)
$(LI Thread.yield() now uses SwitchToThread() on Windows.)
$(LI All core.atomic functions have been marked nothrow. Some have been
marked pure.)
$(LI Condition now has a mutex() property.)
$(LI RWMutex's reader() and writer() functions have been marked @property.)
$(LI 256-bit SIMD types have been added to core.simd.)
$(LI Exceptions will no longer trap on Windows if a debugger is attached.)
$(LI SetTimer() and KillTimer() have been added to core.sys.windows.windows.)
$(LI Fiber.reset() now has overloads that allow resetting the function.)
$(LI TypeInfo now has a new function rtInfo(). While this is now part of the
public API, the information it provides is completely internal to the runtime.)
)

$(RUNTIMEBUGSFIXED
$(LI Unlisted bug: An out of bounds error in the internal EH code has been fixed.)
$(LI Unlisted bug: Some infinite recursions in core.memory functions have been fixed.)
$(LI Unlisted bug: Fiber.reset()'s precondition has been fixed to allow State.HOLD.)
$(LI Unlisted bug: Some memory leaks on shutdown have been fixed.)
$(LI $(BUGZILLA 5206): stat_t is not the same as struct stat)
$(LI $(BUGZILLA 5582): Improvements to the DLL startup code)
$(LI $(BUGZILLA 5930): cas doesn't work when used in code compiled with -D)
$(LI $(BUGZILLA 6631): core.time module constructor runs AFTER main program's module constructor)
$(LI $(BUGZILLA 7704): RangeError when using key optainey by AA byKey() iteration)
$(LI $(BUGZILLA 7923): Please remove 'deprecated' from setAssertHandler())
$(LI $(BUGZILLA 8274): thread_attachThis only works for main thread)
)
$(COMMENT Pending changelog for 2.068.1.
)

$(VERSION 059, mmm dd, 2012, =================================================,
$(BUGSTITLE Library Changes,

$(LI $(RELATIVE_LINK2 coverage-profile-config, Functions to configure coverage, profile, and profile=gc reports were added.))

$(RUNTIMEBUGSFIXED
$(LI $(BUGZILLA 7606): core.time.TickDuration opCmp accepts only lvalues)
)
)

$(VERSION 057, mmm dd, 2011, =================================================,
$(BUGSTITLE Library Changes,

$(LI $(LNAME2 coverage-profile-config, Functions to configure coverage, profile, and profile=gc reports were added.)

$(RUNTIMEBUGSFIXED
$(LI $(BUGZILLA 6909): incorrect definition of the OVERLAPPED struct in core.sys.windows.windows ?)
$(P While they have been accessible through `extern(C)` linkage
for a while, the functions to configure coverage, profile, and
profile=gc reports where added to $(COREMODREF runtime,
core.runtime).
)
)

$(VERSION 055, mmm dd, 2011, =================================================,
$(BOOKTABLE,
$(TR $(TH Functions) $(TH Decscription))
$(TR $(TD $(CXREF runtime, dmd_coverSourcePath)) $(TD Set the directory which contains the source files.))
$(TR $(TD $(CXREF runtime, dmd_coverDestPath)) $(TD Set the directory where to write the -cov reports.))
$(TR $(TD $(CXREF runtime, dmd_coverSetMerge)) $(TD Set whether or not to merge results with existing -cov reports.))
$(TR $(TD $(CXREF runtime, trace_setlogfilename)) $(TD Set the output file for the -profile report.))
$(TR $(TD $(CXREF runtime, trace_setdeffilename)) $(TD Set the output file for the optimized -profile linker script.))
$(TR $(TD $(CXREF runtime, profilegc_setlogfilename)) $(TD Set the output file for the -profile=gc report.))
)

$(RUNTIMEBUGSFIXED
$(LI $(BUGZILLA 5967): Mangling of ArgClose for variadic function is swapped)
$(LI $(BUGZILLA 6493): Source code for the doc of core.time points to std.datetime.)
$(LI $(BUGZILLA 6466): core.demangle incorrect demangling of variables)
$(P Note that these functions are specific to dmd, and might not
be available on other compilers.
)
)

$(VERSION 054, mmm dd, 2011, =================================================,
)

$(WHATSNEW
$(LI Added core.sys.posix.netdb.)
$(LI For functions which have a version which takes a core.time.Duration
and another version which takes an integral value, the version which
takes an integral value is now scheduled for deprecation.)
)
Macros:
TITLE=Change Log

$(RUNTIMEBUGSFIXED
$(LI $(BUGZILLA 4323): std.demangle incorrectly handles template floating point numbers)
$(LI $(BUGZILLA 5272): Postblit not called on copying due to array append)
$(LI $(BUGZILLA 5956): Undocumented mangling of struct value)
$(LI $(BUGZILLA 6135): Thread/GC interaction bug on OS X)
)
)
BUGSTITLE = <div class="bugsfixed">$(H4 $1) $(OL $2 )</div>

$(VERSION 053, mmm dd, 2011, =================================================,
RELATIVE_LINK2=<a href="#$1">$+</a>
LNAME2=<a class="anchor" title="Permalink to this section" id="$1" href="#$1">$+</a>

$(WHATSNEW
$(LI Added some GC benchmark apps.)
$(LI Moved std.intrinsic to core.intrinsic.)
$(LI Implemented $(I exception chaining), as described in TDPL for POSIX.)
)
STDMODREF = <a href="phobos/std_$1.html">$2</a>
COREMODREF = <a href="phobos/core_$1.html">$2</a>
XREF = <a href="phobos/std_$1.html#$2">$2</a>
CXREF = <a href="phobos/core_$1.html#$2">$2</a>

$(RUNTIMEBUGSFIXED
$(LI $(BUGZILLA 5612): core.cpuid not implemented on 64)
$(LI $(BUGZILLA 1001): print stack trace (in debug mode) when program die)
$(LI $(BUGZILLA 5847): Threads started by core.thread should have same floating point state as main thread)
)
)
BOOKTABLE = <table><caption>$1</caption>$+</table>
5 changes: 4 additions & 1 deletion posix.mak
Expand Up @@ -92,6 +92,9 @@ $(DOCDIR)/core_stdc_%.html : src/core/stdc/%.d
$(DOCDIR)/core_sync_%.html : src/core/sync/%.d
$(DMD) $(DDOCFLAGS) -Df$@ project.ddoc $(DOCFMT) $<

changelog.html: changelog.dd
$(DMD) -Df$@ $<

######################## Header .di file generation ##############################

import: $(IMPORTS)
Expand Down Expand Up @@ -152,7 +155,7 @@ $(DRUNTIME): $(OBJS) $(SRCS)
UT_MODULES:=$(patsubst src/%.d,$(OBJDIR)/%,$(SRCS))
HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
endif

Expand Down
39 changes: 39 additions & 0 deletions src/core/runtime.d
Expand Up @@ -326,6 +326,8 @@ private:
*
* Params:
* path = The new path name.
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverSourcePath(string path);

Expand All @@ -334,6 +336,8 @@ extern (C) void dmd_coverSourcePath(string path);
*
* Params:
* path = The new path name.
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverDestPath(string path);

Expand All @@ -342,9 +346,44 @@ extern (C) void dmd_coverDestPath(string path);
*
* Params:
* flag = enable/disable coverage merge mode
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverSetMerge(bool flag);

/**
* Set the output file name for profile reports (-profile switch).
* An empty name will set the output to stdout.
*
* Params:
* name = file name
* Note:
* This is a dmd specific setting.
*/
extern (C) void trace_setlogfilename(string name);

/**
* Set the output file name for the optimized profile linker DEF file (-profile switch).
* An empty name will set the output to stdout.
*
* Params:
* name = file name
* Note:
* This is a dmd specific setting.
*/
extern (C) void trace_setdeffilename(string name);

/**
* Set the output file name for memory profile reports (-profile=gc switch).
* An empty name will set the output to stdout.
*
* Params:
* name = file name
* Note:
* This is a dmd specific setting.
*/
extern (C) void profilegc_setlogfilename(string name);

///////////////////////////////////////////////////////////////////////////////
// Overridable Callbacks
///////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 1 addition & 3 deletions src/rt/profilegc.d
Expand Up @@ -134,7 +134,7 @@ shared static ~this()
{
qsort(counts.ptr, counts.length, Result.sizeof, &Result.qsort_cmp);

FILE* fp = logfilename.length == 0 ? stdout : fopen(logfilename.ptr, "w");
FILE* fp = logfilename.length == 0 ? stdout : fopen((logfilename ~ '\0').ptr, "w");
if (fp)
{
fprintf(fp, "bytes allocated, type, function, file:line\n");
Expand All @@ -149,5 +149,3 @@ shared static ~this()
fprintf(stderr, "cannot write profilegc log file '%.*s'", logfilename.length, logfilename.ptr);
}
}


12 changes: 6 additions & 6 deletions src/rt/trace.d
Expand Up @@ -92,10 +92,9 @@ __gshared
// 0 success
// !=0 failure

int trace_setlogfilename(string name)
void trace_setlogfilename(string name)
{
trace_logfilename = name;
return 0;
}

////////////////////////////////////////
Expand All @@ -105,10 +104,9 @@ int trace_setlogfilename(string name)
// 0 success
// !=0 failure

int trace_setdeffilename(string name)
void trace_setdeffilename(string name)
{
trace_deffilename = name;
return 0;
}

////////////////////////////////////////
Expand Down Expand Up @@ -478,7 +476,8 @@ shared static ~this()
trace_merge(&groot);

// Report results
FILE* fplog = fopen(trace_logfilename.ptr, "w");
FILE* fplog = trace_logfilename.length == 0 ? stdout :
fopen((trace_logfilename ~ '\0').ptr, "w");
if (fplog)
{
auto nsymbols = trace_report(fplog, groot);
Expand All @@ -498,7 +497,8 @@ shared static ~this()
fprintf(stderr, "cannot write '%s'", trace_logfilename.ptr);

// Output function link order
FILE* fpdef = fopen(trace_deffilename.ptr,"w");
FILE* fpdef = trace_deffilename.length == 0 ? stdout :
fopen((trace_deffilename ~ '\0').ptr, "w");
if (fpdef)
{
fprintf(fpdef,"\nFUNCTIONS\n");
Expand Down
59 changes: 59 additions & 0 deletions test/profile/Makefile
@@ -0,0 +1,59 @@
# set from top makefile
OS:=
MODEL:=
DMD:=
DRUNTIME:=
DRUNTIMESO:=
QUIET:=
LINKDL:=

SRC:=src
ROOT:=./obj/$(OS)/$(MODEL)
TESTS:=$(addprefix $(ROOT)/,$(addsuffix .done,profile profilegc both))

DIFF:=diff
GREP:=grep

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
CFLAGS:=$(MODEL_FLAG) -Wall
DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIME) -defaultlib= -debuglib=

.PHONY: all clean
all: $(TESTS)

$(ROOT)/profile.done: DFLAGS+=-profile
$(ROOT)/profile.done: $(ROOT)/%.done: $(ROOT)/%
@echo Testing $*
@rm -f $(ROOT)/mytrace.log $(ROOT)/mytrace.def
$(QUIET)$(ROOT)/$* $(ROOT)/mytrace.log $(ROOT)/mytrace.def
$(QUIET)$(GREP) -q '1 .*_Dmain' $(ROOT)/mytrace.log
$(QUIET)$(GREP) -q '1000 .*uint profile.foo(uint)' $(ROOT)/mytrace.log
$(QUIET)$(DIFF) mytrace.def.exp $(ROOT)/mytrace.def
@touch $@

$(ROOT)/profilegc.done: DFLAGS+=-profile=gc
$(ROOT)/profilegc.done: $(ROOT)/%.done: $(ROOT)/%
@echo Testing $*
@rm -f $(ROOT)/myprofilegc.log
$(QUIET)$(ROOT)/$* $(ROOT)/myprofilegc.log
$(QUIET)$(DIFF) myprofilegc.log.exp $(ROOT)/myprofilegc.log
@touch $@

$(ROOT)/both.done: DFLAGS+=-profile -profile=gc
$(ROOT)/both.done: $(ROOT)/%.done: $(ROOT)/%
@echo Testing $*
@rm -f $(ROOT)/both.log $(ROOT)/both.def $(ROOT)/bothgc.log
$(QUIET)$(ROOT)/$* $(ROOT)/both.log $(ROOT)/both.def $(ROOT)/bothgc.log
$(QUIET)$(GREP) -q '1 .*_Dmain' $(ROOT)/mytrace.log
$(QUIET)$(GREP) -q '1000 .*both.Num\* both.foo(uint)' $(ROOT)/both.log
$(QUIET)$(DIFF) both.def.exp $(ROOT)/both.def
$(QUIET)$(DIFF) bothgc.log.exp $(ROOT)/bothgc.log
@touch $@

$(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$(ROOT)/$* $<

clean:
rm -rf obj *.log *.def
5 changes: 5 additions & 0 deletions test/profile/both.def.exp
@@ -0,0 +1,5 @@

FUNCTIONS
_Dmain
_D4both3fooFkZPS4both3Num
_D4both3Num6__ctorMFNckZS4both3Num
2 changes: 2 additions & 0 deletions test/profile/bothgc.log.exp
@@ -0,0 +1,2 @@
bytes allocated, type, function, file:line
4000 both.Num both.foo src/both.d:15
2 changes: 2 additions & 0 deletions test/profile/myprofilegc.log.exp
@@ -0,0 +1,2 @@
bytes allocated, type, function, file:line
4 uint D main src/profilegc.d:6
4 changes: 4 additions & 0 deletions test/profile/mytrace.def.exp
@@ -0,0 +1,4 @@

FUNCTIONS
_Dmain
_D7profile3fooFkZk

0 comments on commit ba9ea9e

Please sign in to comment.