Finding File source

D

Dav Coleman

Hi,

I've been trying to locate the source for File.open and I'm having no luck.

I looked under /usr/local/lib/ruby/1.8/ and found no File.rb or even IO.rb.
I did a find /usr/local/lib/ruby -name "*.rb" -exec grep "class File"
{} \; -print and it only turns up in a pertty print and ftools source.

Are the core classes only defined in compiled binary perhaps?

If so, I have another question. Using RoR I'm running into a problem
due to too many open files. I want to find the File.open source (or
Io_Open maybe) and add in some sort of debugging so I can log every
file being opened to help debug the issue. Is there a way I can do
this without going to the actual source?

Thanks for any advice.
 
D

Detlef Reichl

Hi,

I've been trying to locate the source for File.open and I'm having no luck.

I looked under /usr/local/lib/ruby/1.8/ and found no File.rb or even IO.rb.
I did a find /usr/local/lib/ruby -name "*.rb" -exec grep "class File"
{} \; -print and it only turns up in a pertty print and ftools source.

Are the core classes only defined in compiled binary perhaps?
Mostly, yes.

If so, I have another question. Using RoR I'm running into a problem
due to too many open files. I want to find the File.open source (or
Io_Open maybe) and add in some sort of debugging so I can log every
file being opened to help debug the issue. Is there a way I can do
this without going to the actual source?

On unixoid systems lsof will show you all open file descriptors.

Cheers
detlef
 
D

daz

Dav said:
Hi,

I've been trying to locate the source for File.open and I'm having no luck.
[...]
Are the core classes only defined in compiled binary perhaps?

Yes.

If so, I have another question. Using RoR I'm running into a problem
due to too many open files. I want to find the File.open source (or
Io_Open maybe) and add in some sort of debugging so I can log every
file being opened to help debug the issue. Is there a way I can do
this without going to the actual source?

Thanks for any advice.


Try something like this at the top of your prog:

#-----------------------------------------------
class File
class << self
alias :real_open :eek:pen
def open(*args, &blk)
p [:File_open] + args # <-----<<
real_open(*args, &blk)
end
end
end

module Kernel
alias :real_open :eek:pen
def open(*args, &blk)
p [:Knl_open] + args # <-----<<
real_open(*args, &blk)
end
end

#-----------------------------------------------
# TEST ...

fname = File.exist?('NUL') ? 'NUL' : '/dev/null'

File.open(fname) {}
open(fname) {}
#-----------------------------------------------


daz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top