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

Side by Side Diff: src/d8.h

Issue 13050: Live counters in d8 (Closed)
Patch Set: Created 12 years 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
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 24 matching lines...) Expand all
35 35
36 #include "v8.h" 36 #include "v8.h"
37 37
38 38
39 namespace v8 { 39 namespace v8 {
40 40
41 41
42 namespace i = v8::internal; 42 namespace i = v8::internal;
43 43
44 44
45 // A single counter in a counter collection.
45 class Counter { 46 class Counter {
46 public: 47 public:
47 explicit Counter(const char* name) 48 static const int kMaxNameSize = 64;
48 : name_(name), value_(0) { } 49 int32_t* Bind(const char* name);
49 int* GetValuePtr() { return &value_; } 50 int32_t* ptr() { return &counter_; }
50 const char* name() { return name_; } 51 int32_t value() { return counter_; }
51 int value() { return value_; }
52 private: 52 private:
53 const char* name_; 53 int32_t counter_;
54 int value_; 54 uint8_t name_[kMaxNameSize];
55 }; 55 };
56 56
57 57
58 // A set of counters and associated information. An instance of this
59 // class is stored directly in the memory-mapped counters file if
60 // the --map-counters options is used
61 class CounterCollection {
62 public:
63 CounterCollection();
64 Counter* GetNextCounter();
65 private:
66 static const unsigned kMaxCounters = 256;
67 uint32_t magic_number_;
68 uint32_t max_counters_;
69 uint32_t max_name_size_;
70 uint32_t counters_in_use_;
71 Counter counters_[kMaxCounters];
72 };
73
74
58 class Shell: public i::AllStatic { 75 class Shell: public i::AllStatic {
59 public: 76 public:
60 static bool ExecuteString(Handle<String> source, 77 static bool ExecuteString(Handle<String> source,
61 Handle<Value> name, 78 Handle<Value> name,
62 bool print_result, 79 bool print_result,
63 bool report_exceptions); 80 bool report_exceptions);
64 static void ReportException(TryCatch* try_catch); 81 static void ReportException(TryCatch* try_catch);
65 static void Initialize(); 82 static void Initialize();
66 static void OnExit(); 83 static void OnExit();
67 static int* LookupCounter(const char* name); 84 static int* LookupCounter(const char* name);
85 static void MapCounters(const char* name);
68 static Handle<String> ReadFile(const char* name); 86 static Handle<String> ReadFile(const char* name);
69 static void RunShell(); 87 static void RunShell();
70 static int Main(int argc, char* argv[]); 88 static int Main(int argc, char* argv[]);
71 static Handle<Array> GetCompletions(Handle<String> text, 89 static Handle<Array> GetCompletions(Handle<String> text,
72 Handle<String> full); 90 Handle<String> full);
73 91
74 static Handle<Value> Print(const Arguments& args); 92 static Handle<Value> Print(const Arguments& args);
75 static Handle<Value> Quit(const Arguments& args); 93 static Handle<Value> Quit(const Arguments& args);
76 static Handle<Value> Version(const Arguments& args); 94 static Handle<Value> Version(const Arguments& args);
77 static Handle<Value> Load(const Arguments& args); 95 static Handle<Value> Load(const Arguments& args);
78 96
79 static const char* kHistoryFileName; 97 static const char* kHistoryFileName;
80 static const char* kPrompt; 98 static const char* kPrompt;
81 private: 99 private:
82 static Persistent<Context> utility_context_; 100 static Persistent<Context> utility_context_;
83 static Persistent<Context> evaluation_context_; 101 static Persistent<Context> evaluation_context_;
84 typedef std::map<const char*, Counter*> CounterMap; 102 typedef std::map<const char*, Counter*> CounterMap;
85 static CounterMap counter_map_; 103 static CounterMap counter_map_;
104 // We statically allocate a set of local counters to be used if we
105 // don't want to store the stats in a memory-mapped file
106 static CounterCollection local_counters_;
107 static CounterCollection* counters_;
108 static i::OS::MemoryMappedFile* counters_file_;
86 }; 109 };
87 110
88 111
89 class LineEditor { 112 class LineEditor {
90 public: 113 public:
91 enum Type { DUMB = 0, READLINE = 1 }; 114 enum Type { DUMB = 0, READLINE = 1 };
92 LineEditor(Type type, const char* name); 115 LineEditor(Type type, const char* name);
93 virtual ~LineEditor() { } 116 virtual ~LineEditor() { }
94 117
95 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; 118 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0;
96 virtual bool Open() { return true; } 119 virtual bool Open() { return true; }
97 virtual bool Close() { return true; } 120 virtual bool Close() { return true; }
98 virtual void AddHistory(const char* str) { } 121 virtual void AddHistory(const char* str) { }
99 122
100 const char* name() { return name_; } 123 const char* name() { return name_; }
101 static LineEditor* Get(); 124 static LineEditor* Get();
102 private: 125 private:
103 Type type_; 126 Type type_;
104 const char* name_; 127 const char* name_;
105 LineEditor* next_; 128 LineEditor* next_;
106 static LineEditor* first_; 129 static LineEditor* first_;
107 }; 130 };
108 131
109 132
110 } // namespace v8 133 } // namespace v8
111 134
112 135
113 #endif // V8_D8_H_ 136 #endif // V8_D8_H_
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698