Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ftime-trace implementation. #3797

Merged
merged 8 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ set(DRV_SRC
driver/dcomputecodegenerator.cpp
driver/exe_path.cpp
driver/targetmachine.cpp
driver/timetrace.cpp
driver/toobj.cpp
driver/tool.cpp
driver/archiver.cpp
Expand Down
3 changes: 3 additions & 0 deletions dmd/root/rmem.d
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ enum CHUNK_SIZE = (256 * 4096 - 64);

__gshared size_t heapleft = 0;
__gshared void* heapp;
version (IN_LLVM) __gshared size_t heaptotal = 0; // Total amount of memory allocated using malloc

extern (D) void* allocmemoryNoFree(size_t m_size) nothrow @nogc
{
Expand All @@ -175,11 +176,13 @@ extern (D) void* allocmemoryNoFree(size_t m_size) nothrow @nogc

if (m_size > CHUNK_SIZE)
{
version (IN_LLVM) heaptotal += m_size;
return Mem.check(malloc(m_size));
}

heapleft = CHUNK_SIZE;
heapp = Mem.check(malloc(CHUNK_SIZE));
version (IN_LLVM) heaptotal += CHUNK_SIZE;
goto L1;
}

Expand Down
2 changes: 1 addition & 1 deletion driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ cl::opt<bool> fTimeTrace(
cl::desc("Turn on time profiler. Generates JSON file "
"based on the output filename (also see --ftime-trace-file)."));
cl::opt<unsigned> fTimeTraceGranularity(
"ftime-trace-granularity", cl::ZeroOrMore,
"ftime-trace-granularity", cl::ZeroOrMore, cl::init(500),
cl::desc(
"Minimum time granularity (in microseconds) traced by time profiler"));
cl::opt<std::string>
Expand Down
21 changes: 16 additions & 5 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,9 @@ int cppmain() {
fatal();
}

initializeTimeTracer();
if (opts::fTimeTrace) {
initializeTimeTrace(opts::fTimeTraceGranularity, 0, opts::allArguments[0]);
}

// Set up the TargetMachine.
const auto arch = getArchStr();
Expand Down Expand Up @@ -1120,8 +1122,9 @@ int cppmain() {
if (!tempObjectsDir.empty())
llvm::sys::fs::remove(tempObjectsDir);

writeTimeTraceProfile();
deinitializeTimeTracer();
std::string fTimeTraceFile = opts::fTimeTraceFile;
writeTimeTraceProfile(fTimeTraceFile.empty() ? "" : fTimeTraceFile.c_str());
deinitializeTimeTrace();

llvm::llvm_shutdown();

Expand Down Expand Up @@ -1162,7 +1165,11 @@ void codegenModules(Modules &modules) {
const auto atCompute = hasComputeAttr(m);
if (atCompute == DComputeCompileFor::hostOnly ||
atCompute == DComputeCompileFor::hostAndDevice) {
TimeTraceScope timeScope(("Codegen module " + llvm::SmallString<20>(m->toChars())).str());
TimeTraceScope timeScope(
("Codegen module " + llvm::SmallString<20>(m->toChars()))
.str()
.c_str(),
m->loc);
#if LDC_MLIR_ENABLED
if (global.params.output_mlir == OUTPUTFLAGset)
cg.emitMLIR(m);
Expand Down Expand Up @@ -1190,7 +1197,11 @@ void codegenModules(Modules &modules) {
if (!computeModules.empty()) {
TimeTraceScope timeScope("Codegen DCompute device modules");
for (auto &mod : computeModules) {
TimeTraceScope timeScope(("Codegen DCompute device module " + llvm::SmallString<20>(mod->toChars())).str());
TimeTraceScope timeScope(("Codegen DCompute device module " +
llvm::SmallString<20>(mod->toChars()))
.str()
.c_str(),
mod->loc);
dccg.emit(mod);
}
}
Expand Down
67 changes: 0 additions & 67 deletions driver/timetrace.cpp

This file was deleted.

Loading