Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_CALLSTACK_H
     18 #define ANDROID_CALLSTACK_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <utils/String8.h>
     24 
     25 // ---------------------------------------------------------------------------
     26 
     27 namespace android {
     28 
     29 class CallStack
     30 {
     31 public:
     32     enum {
     33         MAX_DEPTH = 31
     34     };
     35 
     36     CallStack();
     37     CallStack(const CallStack& rhs);
     38     ~CallStack();
     39 
     40     CallStack& operator = (const CallStack& rhs);
     41 
     42     bool operator == (const CallStack& rhs) const;
     43     bool operator != (const CallStack& rhs) const;
     44     bool operator < (const CallStack& rhs) const;
     45     bool operator >= (const CallStack& rhs) const;
     46     bool operator > (const CallStack& rhs) const;
     47     bool operator <= (const CallStack& rhs) const;
     48 
     49     const void* operator [] (int index) const;
     50 
     51     void clear();
     52 
     53     void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH);
     54 
     55     // Dump a stack trace to the log
     56     void dump(const char* prefix = 0) const;
     57 
     58     // Return a string (possibly very long) containing the complete stack trace
     59     String8 toString(const char* prefix = 0) const;
     60 
     61     size_t size() const { return mCount; }
     62 
     63 private:
     64     // Internal helper function
     65     String8 toStringSingleLevel(const char* prefix, int32_t level) const;
     66 
     67     size_t      mCount;
     68     const void* mStack[MAX_DEPTH];
     69 };
     70 
     71 }; // namespace android
     72 
     73 
     74 // ---------------------------------------------------------------------------
     75 
     76 #endif // ANDROID_CALLSTACK_H
     77