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/strings/string_piece.h"
22 : #include "syzygy/common/assertions.h"
23 :
24 m : namespace agent {
25 m : namespace memprof {
26 :
27 : // Describes how the module tracks stack traces.
28 m : enum StackTraceTracking {
29 : // Stack traces will be ignored.
30 m : kTrackingNone,
31 : // Stack traces will be tracked, and IDs emitted along with
32 : // DetailedFunctionCall records.
33 m : kTrackingTrack,
34 : // Stack traces will be both tracked and emitted as StackTrace records.
35 m : kTrackingEmit,
36 :
37 : // Must be last.
38 m : kStackTraceTrackingMax,
39 m : };
40 :
41 : // A structure housing runtime paramters for the memory profiler agent.
42 m : struct Parameters {
43 : // Controls the level of detail stored in |stack_trace_id|.
44 m : StackTraceTracking stack_trace_tracking;
45 : // If this is enabled then timestamps are strictly serialized and
46 : // synchronized across all threads.
47 m : bool serialize_timestamps;
48 : // If this is enabled then block contents will be hashed when freed, and
49 : // the hash value stored as an additional parameter to the heap free
50 : // function.
51 m : bool hash_contents_at_free;
52 m : };
53 :
54 : // The environment variable that is used for extracting parameters.
55 m : extern const char kParametersEnvVar[];
56 :
57 : // An array mapping StackTraceTracking values to strings.
58 m : extern const char* kStackTraceTrackingValues[];
59 :
60 : // Default parameter values.
61 m : extern StackTraceTracking kDefaultStackTraceTracking;
62 m : extern bool kDefaultSerializeTimestamps;
63 m : extern bool kDefaultHashContentsAtFree;
64 :
65 : // Parameter names for parsing.
66 m : extern const char kParamStackTraceTracking[];
67 m : extern const char kParamSerializeTimestamps[];
68 m : extern const char kParamHashContentsAtFree[];
69 :
70 : // Initializes a Parameters struct with default values.
71 : // @param parameters The Parameters struct to be initialized.
72 m : void SetDefaultParameters(Parameters* parameters);
73 :
74 : // Parses parameters from a string and updates the provided structure.
75 : // @param param_string the string of parameters to be parsed.
76 : // @param parameters The Parameters struct to be updated.
77 : // @returns true on success, false otherwise. Logs verbosely on failure.
78 m : bool ParseParameters(const base::StringPiece& param_string,
79 m : Parameters* parameters);
80 :
81 : // Parses parameters from the environment and updates the provided structure.
82 : // @param parameters The Parameters struct to be updated.
83 : // @returns true on success, false otherwise. Logs verbosely on failure.
84 m : bool ParseParametersFromEnv(Parameters* parameters);
85 :
86 m : } // namespace memprof
87 m : } // namespace agent
88 :
89 : #endif // SYZYGY_AGENT_MEMPROF_PARAMETERS_H_
|