Closed Bug 845804 Opened 11 years ago Closed 11 years ago

Refactor duplicated code in nsMemoryInfoDumper and nsCycleCollector.cpp

Categories

(Toolkit :: about:memory, defect)

All
Android
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla22

People

(Reporter: kats, Assigned: kats)

Details

Attachments

(1 file, 1 obsolete file)

The code in the OpenTempFile function in nsMemoryInfoDumper is pretty much duplicated in nsCycleCollectorLogger::CreateTempFile in nsCycleCollector.cpp and should be refactored.
Attached patch Patch (obsolete) — Splinter Review
This is what I imagine you meant in bug 845342 comment 1, but it seems wrong to have this random OpenTempFile floating around in no namespace. Is there a better place to move it to?
Assignee: nobody → bugmail.mozilla
Attachment #718966 - Flags: feedback?(n.nethercote)
Comment on attachment 718966 [details] [diff] [review]
Patch

Review of attachment 718966 [details] [diff] [review]:
-----------------------------------------------------------------

Definitely heading in the right direction, but shouldn't nsMemoryInfoDumper.cpp call OpenTempFile() somewhere?

jlebar might have an opinion about the best place for OpenTempFile.  It feels like it belongs in some lower-level header that can be imported by both nsMemoryInfoDumper.cpp and nsCycleCollector.cpp.
Attachment #718966 - Flags: feedback?(n.nethercote) → feedback+
nsMemoryInfoDumper already calls OpenTempFile; I didn't modify the signature of the function so the existing calls to it don't show up in the patch. Or am I misunderstanding your question?
Comment on attachment 718966 [details] [diff] [review]
Patch

:jlebar, any thoughts on where I should relocate OpenTempFile to so that it can be cleanly reused across nsCycleCollector and nsMemoryInfoDumper?
Attachment #718966 - Flags: feedback?(justin.lebar+bug)
Maybe OpenTempFile could be a static method on nsMemoryInfoDumper?  I'd like that better than a global function, since that lacks any context as to why you're opening a temp file.
Attachment #718966 - Flags: feedback?(justin.lebar+bug)
> nsMemoryInfoDumper already calls OpenTempFile; I didn't modify the signature
> of the function so the existing calls to it don't show up in the patch.

Right!  Carry on :)
Attached patch Patch (v2)Splinter Review
Made it a static method on nsMemoryInfoDumper
Attachment #718966 - Attachment is obsolete: true
Attachment #719603 - Flags: review?(n.nethercote)
Comment on attachment 719603 [details] [diff] [review]
Patch (v2)

Review of attachment 719603 [details] [diff] [review]:
-----------------------------------------------------------------

r=me with the comment below addressed.

::: xpcom/base/nsCycleCollector.cpp
@@ +1412,4 @@
>              NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
>                                    getter_AddRefs(logFile));
>          }
> +        nsresult rv = nsMemoryInfoDumper::OpenTempFile(filename,

Don't you need to check |logFile| before calling OpenTempFile()?
Attachment #719603 - Flags: review?(n.nethercote) → review+
(In reply to Nicholas Nethercote [:njn] from comment #8)
> 
> Don't you need to check |logFile| before calling OpenTempFile()?

No, because OpenTempFile does the check internally. Note that we want to execute the tail end of OpenTempFile regardless of whether logFile is set or not at the call site; it's just that it if it's not set we want to do the additional work of finding the temp dir. It is a little confusing though, I can add some documentation to that effect.
Sorry for the false alarm here! :-0
No problem :)

RyanVM re-landed this as https://hg.mozilla.org/integration/mozilla-inbound/rev/8392e41895df once it was determined to be free of blame for the xpcshell failures.
https://hg.mozilla.org/mozilla-central/rev/8392e41895df
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla22
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: