MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / shutdown

Method shutdown

source/game/scripting/StarLuaRoot.cpp:49–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void LuaRoot::shutdown() {
50 clearScriptCache();
51
52 if (!m_luaEngine)
53 return;
54
55 auto profile = m_luaEngine->getProfile();
56 if (!profile.empty()) {
57 profile.sort([](auto const& a, auto const& b) {
58 return a.totalTime > b.totalTime;
59 });
60
61 std::function<Json (LuaProfileEntry const&)> jsonFromProfileEntry = [&](LuaProfileEntry const& entry) -> Json {
62 JsonObject profile;
63 profile.set("function", entry.name.value("<function>"));
64 profile.set("scope", entry.nameScope.value("?"));
65 profile.set("source", strf("{}:{}", entry.source, entry.sourceLine));
66 profile.set("self", entry.selfTime);
67 profile.set("total", entry.totalTime);
68 List<LuaProfileEntry> calls;
69 for (auto p : entry.calls)
70 calls.append(*p.second);
71 profile.set("calls", calls.sorted([](auto const& a, auto const& b) { return a.totalTime > b.totalTime; }).transformed(jsonFromProfileEntry));
72 return profile;
73 };
74
75 String profileSummary = Json(profile.transformed(jsonFromProfileEntry)).repr(1);
76
77 if (!File::isDirectory(m_storageDirectory)) {
78 Logger::info("Creating lua storage directory");
79 File::makeDirectory(m_storageDirectory);
80 }
81
82 String filename = strf("{}.luaprofile", Time::printCurrentDateAndTime("<year>-<month>-<day>-<hours>-<minutes>-<seconds>-<millis>"));
83 String path = File::relativeTo(m_storageDirectory, filename);
84 Logger::info("Writing lua profile {}", filename);
85 File::writeFile(profileSummary, path);
86 }
87
88 m_luaEngine.reset();
89}
90
91LuaContext LuaRoot::createContext(String const& script) {
92 return createContext(StringList{script});

Callers 3

receivePacketsMethod · 0.45
writeDataMethod · 0.45
readDataMethod · 0.45

Calls 12

strfFunction · 0.85
JsonClass · 0.85
getProfileMethod · 0.80
emptyMethod · 0.45
sortMethod · 0.45
setMethod · 0.45
valueMethod · 0.45
appendMethod · 0.45
transformedMethod · 0.45
sortedMethod · 0.45
reprMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected