Closed Bug 827523 Opened 12 years ago Closed 12 years ago

DMD: add some options that are useful when adding new memory reporters

Categories

(Core :: DMD, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla21

People

(Reporter: n.nethercote, Assigned: n.nethercote)

Details

Attachments

(3 files, 1 obsolete file)

When adding new memory reporters, it's useful to see all the records, not just the top 1000, so you can see exactly which blocks are being reported. But to prevent the output being overly long, it's also useful to reduce the size of the stack traces. This bug is about adding options for both of these things.
This removes valloc() from the test, because Windows doesn't support it.
Attachment #698982 - Flags: review?(justin.lebar+bug)
This swaps the diff order in test mode so the expected output is first, which is more intuitive.
Attachment #698983 - Flags: review?(justin.lebar+bug)
This patch: - Adds new --max-frames and --max-records options. - Bundles all the options in a new |Options| class, which makes things neater. - Fixes the indentation on the usage message.
Attachment #698987 - Flags: review?(justin.lebar+bug)
Component: General → DMD
Attachment #698982 - Flags: review?(justin.lebar+bug) → review+
Attachment #698983 - Flags: review?(justin.lebar+bug) → review+
> //--------------------------------------------------------------------------- >+// Options >+//--------------------------------------------------------------------------- >+ >+struct Options >+{ >+ template <typename T> >+ struct NumOption >+ { >+ const T mDefault; >+ const T mMax; >+ T mActual; >+ NumOption(T aDefault, T aMax) >+ : mDefault(aDefault), mMax(aMax), mActual(aDefault) >+ {} >+ }; >+ >+ enum Mode { >+ Normal, // run normally >+ Test, // do some basic correctness tests >+ Stress // do some performance stress tests >+ }; >+ >+ NumOption<size_t> mSampleBelowSize; >+ NumOption<uint32_t> mMaxFrames; >+ NumOption<uint32_t> mMaxRecords; >+ Mode mMode; >+ >+ Options(); >+}; I like the idea of having an Options object, but this API makes it significantly more verbose to access an option. How about if we had something like struct Options { enum Mode { [...] }; size_t sampleBelowSize; uint32_t maxFrames; uint32_t maxRecords; Mode mode; Options(); // sets everything to defaults void ParseOptions(int argc, const char** argv) { [...] } }; Options gOptions; // note, not a pointer I agree this isn't as nice wrt having the options' [max, default, actual] all in one object. But the consumer's API is nicer, and having ParseOptions be part of Options is better OOP. Making gOptions not be a pointer is a premature optimization for speed; the compiler can statically address the members of a gOptions stored in the data section. It also saves you one character ("." versus "->"). :) What do you think?
> I agree this isn't as nice wrt having the options' [max, default, actual] all > in one object. But the consumer's API is nicer, and having ParseOptions be > part of Options is better OOP. The mMax and mDefault fields are only used for parsing and the usage message. I'll try to encapsulate those operations inside the class to avoid exposing them. > Making gOptions not be a pointer is a premature optimization for speed; the > compiler can statically address the members of a gOptions stored in the data > section. It also saves you one character ("." versus "->"). :) That's not safe. The comment at the top of Init() says: // WARNING: this function runs *very* early -- before all static initializers // have run. For this reason, non-scalar globals such as gStateLock and // gStackTraceTable are allocated dynamically (so we can guarantee their // construction in this function) rather than statically.
New OOPier version.
Attachment #698987 - Attachment is obsolete: true
Attachment #698987 - Flags: review?(justin.lebar+bug)
Attachment #699470 - Flags: review?(justin.lebar+bug)
> That's not safe. Okay, but we don't have to rely on any static initializers -- we can make the constructor be a nop and rely on the .DATA section being 0.
Comment on attachment 699470 [details] [diff] [review] (part 3) - DMD: Add --max-frames and --max-records options. >@@ -272,20 +265,73 @@ static const size_t kBufLen = 64; > //--------------------------------------------------------------------------- >+// Options (I) >+//--------------------------------------------------------------------------- Nit: Could you say "Part I" or something? >-static bool >-OptionLong(const char* aArg, const char* aOptionName, long aMin, long aMax, >- long* aN) >+bool >+Options::Long(const char* aArg, const char* aOptionName, long aMin, long aMax, >+ long* aN) Nit: ExtractLong or something?
Attachment #699470 - Flags: review?(justin.lebar+bug) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: