How do I make LÖVE interact with luaprofiler?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

How do I make LÖVE interact with luaprofiler?

Post by kikito »

Some parts of my code are way too slow, but I'm not certain of where the trouble is. I want to try to use luaprofiler in order to find them out.

This is what I've done so far:
  • Downloaded Luaprofiler
  • Compiled it using the linux makefile (I had to change config.linux so it pointed to the appropiate "include" folder. I already had lua 5.1 installed) since I use Ubuntu
  • This produced a bunch of *.o files. I understand that the important one is the one called "bin/profiler.so"
  • Copied profiler.o to my project's folder (inside ./lib/profiler.so)
  • Required profiler with require "lib.profiler"
And then I got this error:

Code: Select all

Error: error loading module 'lib.profiler' from file './lib/profiler.so':
	./lib/profiler.so: undefined symbol: luaopen_lib_profiler
stack traceback:
	[C]: ?
	[C]: in function 'require'
	src/game/states/Play.lua:3: in main chunk
Has anyone managed to make this work? Am I missing some obvious step?
Last edited by kikito on Tue Jul 10, 2012 7:32 am, edited 1 time in total.
When I write def I mean function.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How do I make LÖVE interact with luaprofiler?

Post by Boolsheet »

The .o files are object files. They are intermediate files that should be passed on to the linker to produce the final library (with the extension .so).

Weird that you didn't get any errors while building. The makefile uses an old include path to the Lua headers. Ubuntu 12.04 has them in '/usr/include/lua5.1'. Open the config.linux file and replace the path of LUA_INCLUDE with this new path. (Oops, my mind didn't parse that you already did this) Then you have to build it again. If you don't want to rename the Makefile you can also specify it to make with the -f option: make -f Makefile.linux. ;)

Now it should create a folder named bin and in it a profiler.so. This is the actual binary. The makefile also has an install option (sudo make install), but if the path '/usr/local/lib/lua/5.1' does not exist, like it didn't for me, it will fail. You can copy it there by hand or to any other place where the default Lua package.path is pointing.

Now you can do 'local myProfiler = require("profiler")' in Lua. Or in LÖVE:

Code: Select all

profiler = require("profiler")
profiler.start("YourProfile.prof")

function love.quit()
   profiler.stop()
end
Use the summary.lua script in 'src/analyzer' to get a simple overview of what went on. Execute it like 'lua summary.lua YourProfile.prof'.

Beware, the file gets big very fast. ;)

Edit: Some time ago I hacked up a summary.lua that is a bit more verbose. It's not of good code quality, but it should work. Edit2: Actually, it looks like I just changed the formatting.
Usage: lua summary2.lua -v YourProfile.prof
Attachments
summary2.lua
Modified summary.lua
(4.42 KiB) Downloaded 112 times
Shallow indentations.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by kikito »

Hi bolsheet,

Thanks for answering. I'm not sure you paid me enough attention though :)
Weird that you didn't get any errors while building... Open the config.linux file and replace the path of LUA_INCLUDE with this new path
I did get an error. That is why I said:
Compiled it using the linux makefile (I had to change config.linux so it pointed to the appropiate "include" folder. I already had lua 5.1 installed) since I use Ubuntu
The thing is, I have managed to build a profiler.so file. I have put it on my project's folder. but when I try to require it, I get the error mentioned on my first post (the error happens on the require 'lib.profiler' line). I don't know how to solve that error.
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by bartbes »

Well, you can't require a compiled lib like that, you'd need to require "profiler", and then it'd work.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by kikito »

bartbes wrote:Well, you can't require a compiled lib like that, you'd need to require "profiler", and then it'd work.
Sorry, I don't understand. The exact line throwing the error looks like this:

Code: Select all

local profiler = require 'lib.profiler'
"lib" is an existing folder in the project. profiler.so is inside that folder.

What should I change?
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by bartbes »

Move it out of lib ;).

EDIT: I'll add this:
The name of this C function is the string "luaopen_" concatenated with a copy of the module name where each dot is replaced by an underscore. Moreover, if the module name has a hyphen, its prefix up to (and including) the first hyphen is removed. For instance, if the module name is a.v1-b.c, the function name will be luaopen_b_c.
Since luaprofiler has a function luaopen_profiler, it has to be opened with require("profiler").
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by vrld »

You have to move profiler.so out of the lib folder to the base folder (due to a idiocy of the Lua c-module loader that looks for a function called luaopen_lib_profiler instead of luaopen_profiler).

Alternatively, you can install luarocks and then install luaprofiler using luarocks. To use it, you just have to do a

Code: Select all

require 'luarocks.require'
before

Code: Select all

require 'profiler'
If you don't want to do either, you can add the following function to lua50_profiler.c:

Code: Select all

int luaopen_lib_profiler(lua_State *L) {
  return luaopen_profiler(L);
}
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by kikito »

OMG.

It works T__T

I feel so stupid now. Thanks a lot guys :D
When I write def I mean function.
Balrog CS
Prole
Posts: 1
Joined: Tue Jul 10, 2012 5:09 pm

Re: How do I make LÖVE interact with luaprofiler?

Post by Balrog CS »

Hello guys, first post from a newbie so I apologize if this is a trivial issue, but I also am having trouble getting a profiler to work with LÖVE. I think I have tried three of them by now, among one of them being luaprofiler, and for all of them I end up getting this error during runtime (for the most recent profiler once the profiler is about to end).

"Attempt to index global 'debug' (a boolean value)"

These errors are always caused by a call from debug.setHook() or debug.getInfo(). Somehow it thinks 'debug' is a boolean? Does this mean it has been overwritten somewhere?

I have looked online and I haven't found a solution to this, nor have I even found anyone with the same problem. It's probably something really stupid, but I have no idea at this point, any ideas? Is there some library I need or something?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How do I make LÖVE interact with luaprofiler?

Post by kikito »

@Balrog: That probably means that you have set the "debug" variable to something in some file. debug is a table in Lua, and it is usueful. Try looking for "debug" in your code. If you are using it for anything, change the name to something else, like doDebug.

@rest: Bolsheet's summary file makes luaprofiler's output so much more useful! I recommend it to everyone. :D
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 3 guests