Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1274)

Side by Side Diff: base/location.h

Issue 9702014: [UMA] Use proper C++ objects to serialize tracked_objects across process boundaries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/location.cc » ('j') | base/profiler/tracked_time.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_LOCATION_H_ 5 #ifndef BASE_LOCATION_H_
6 #define BASE_LOCATION_H_ 6 #define BASE_LOCATION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 12
13 namespace base {
14 class DictionaryValue;
15 }
16
13 namespace tracked_objects { 17 namespace tracked_objects {
14 18
15 // Location provides basic info where of an object was constructed, or was 19 // Location provides basic info where of an object was constructed, or was
16 // significantly brought to life. 20 // significantly brought to life.
17 class BASE_EXPORT Location { 21 class BASE_EXPORT Location {
18 public: 22 public:
19 // Constructor should be called with a long-lived char*, such as __FILE__. 23 // Constructor should be called with a long-lived char*, such as __FILE__.
20 // It assumes the provided value will persist as a global constant, and it 24 // It assumes the provided value will persist as a global constant, and it
21 // will not make a copy of it. 25 // will not make a copy of it.
22 Location(const char* function_name, 26 Location(const char* function_name,
(...skipping 28 matching lines...) Expand all
51 // Translate the some of the state in this instance into a human readable 55 // Translate the some of the state in this instance into a human readable
52 // string with HTML characters in the function names escaped, and append that 56 // string with HTML characters in the function names escaped, and append that
53 // string to |output|. Inclusion of the file_name_ and function_name_ are 57 // string to |output|. Inclusion of the file_name_ and function_name_ are
54 // optional, and controlled by the boolean arguments. 58 // optional, and controlled by the boolean arguments.
55 void Write(bool display_filename, bool display_function_name, 59 void Write(bool display_filename, bool display_function_name,
56 std::string* output) const; 60 std::string* output) const;
57 61
58 // Write function_name_ in HTML with '<' and '>' properly encoded. 62 // Write function_name_ in HTML with '<' and '>' properly encoded.
59 void WriteFunctionName(std::string* output) const; 63 void WriteFunctionName(std::string* output) const;
60 64
61 // Construct a Value* representation. The caller assumes ownership of the
62 // memory in the returned instance.
63 base::DictionaryValue* ToValue() const;
64
65 private: 65 private:
66 const char* function_name_; 66 const char* function_name_;
67 const char* file_name_; 67 const char* file_name_;
68 int line_number_; 68 int line_number_;
69 const void* program_counter_; 69 const void* program_counter_;
70 }; 70 };
71 71
72 // Serialized representation of the Location class that can safely be passed
73 // across process boundaries.
74 struct BASE_EXPORT SerializedLocation {
75 // The default constructor is exposed to support the IPC serialization macros.
76 SerializedLocation();
77 SerializedLocation(const tracked_objects::Location& location);
78 ~SerializedLocation();
79
80 // Writes the serialized data into the passed |dictionary|.
81 void ToValue(base::DictionaryValue* dictionary) const;
82
83 std::string file_name;
84 std::string function_name;
85 int line_number;
86 };
87
72 BASE_EXPORT const void* GetProgramCounter(); 88 BASE_EXPORT const void* GetProgramCounter();
73 89
74 // Define a macro to record the current source location. 90 // Define a macro to record the current source location.
75 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) 91 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__)
76 92
77 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \ 93 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \
78 ::tracked_objects::Location(function_name, \ 94 ::tracked_objects::Location(function_name, \
79 __FILE__, \ 95 __FILE__, \
80 __LINE__, \ 96 __LINE__, \
81 ::tracked_objects::GetProgramCounter()) 97 ::tracked_objects::GetProgramCounter())
82 98
83 } // namespace tracked_objects 99 } // namespace tracked_objects
84 100
85 #endif // BASE_LOCATION_H_ 101 #endif // BASE_LOCATION_H_
OLDNEW
« no previous file with comments | « no previous file | base/location.cc » ('j') | base/profiler/tracked_time.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698