1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares structures and parsing routines for Memory Profiler runtime
16 : // parameters.
17 :
18 : #ifndef SYZYGY_AGENT_MEMPROF_PARAMETERS_H_
19 : #define SYZYGY_AGENT_MEMPROF_PARAMETERS_H_
20 :
21 : #include "base/basictypes.h"
22 : #include "base/strings/string_piece.h"
23 : #include "syzygy/common/assertions.h"
24 :
25 m : namespace agent {
26 m : namespace memprof {
27 :
28 : // Describes how the module tracks stack traces.
29 m : enum StackTraceTracking {
30 : // Stack traces will be ignored.
31 m : kTrackingNone,
32 : // Stack traces will be tracked, and IDs emitted along with
33 : // DetailedFunctionCall records.
34 m : kTrackingTrack,
35 : // Stack traces will be both tracked and emitted as StackTrace records.
36 m : kTrackingEmit,
37 :
38 : // Must be last.
39 m : kStackTraceTrackingMax,
40 m : };
41 :
42 : // A structure housing runtime paramters for the memory profiler agent.
43 m : struct Parameters {
44 : // Controls the level of detail stored in |stack_trace_id|.
45 m : StackTraceTracking stack_trace_tracking;
46 : // If this is enabled then timestamps are strictly serialized and
47 : // synchronized across all threads.
48 m : bool serialize_timestamps;
49 : // If this is enabled then block contents will be hashed when freed, and
50 : // the hash value stored as an additional parameter to the heap free
51 : // function.
52 m : bool hash_contents_at_free;
53 m : };
54 :
55 : // The environment variable that is used for extracting parameters.
56 m : extern const char kParametersEnvVar[];
57 :
58 : // An array mapping StackTraceTracking values to strings.
59 m : extern const char* kStackTraceTrackingValues[];
60 :
61 : // Default parameter values.
62 m : extern StackTraceTracking kDefaultStackTraceTracking;
63 m : extern bool kDefaultSerializeTimestamps;
64 m : extern bool kDefaultHashContentsAtFree;
65 :
66 : // Parameter names for parsing.
67 m : extern const char kParamStackTraceTracking[];
68 m : extern const char kParamSerializeTimestamps[];
69 m : extern const char kParamHashContentsAtFree[];
70 :
71 : // Initializes a Parameters struct with default values.
72 : // @param parameters The Parameters struct to be initialized.
73 m : void SetDefaultParameters(Parameters* parameters);
74 :
75 : // Parses parameters from a string and updates the provided structure.
76 : // @param param_string the string of parameters to be parsed.
77 : // @param parameters The Parameters struct to be updated.
78 : // @returns true on success, false otherwise. Logs verbosely on failure.
79 m : bool ParseParameters(const base::StringPiece& param_string,
80 m : Parameters* parameters);
81 :
82 : // Parses parameters from the environment and updates the provided structure.
83 : // @param parameters The Parameters struct to be updated.
84 : // @returns true on success, false otherwise. Logs verbosely on failure.
85 m : bool ParseParametersFromEnv(Parameters* parameters);
86 :
87 m : } // namespace memprof
88 m : } // namespace agent
89 :
90 : #endif // SYZYGY_AGENT_MEMPROF_PARAMETERS_H_
|