Home | History | Annotate | Download | only in uploader
      1 /*
      2  * Copyright (C) 2015 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 METRICSD_UPLOADER_CRASH_COUNTERS_H_
     18 #define METRICSD_UPLOADER_CRASH_COUNTERS_H_
     19 
     20 #include <atomic>
     21 
     22 // This class is used to keep track of the crash counters.
     23 // An instance of it will be used by both the binder thread (to increment the
     24 // counters) and the uploader thread (to gather and reset the counters).
     25 // As such, the internal counters are atomic uints to allow concurrent access.
     26 class CrashCounters {
     27  public:
     28   CrashCounters();
     29 
     30   void IncrementKernelCrashCount();
     31   unsigned int GetAndResetKernelCrashCount();
     32 
     33   void IncrementUserCrashCount();
     34   unsigned int GetAndResetUserCrashCount();
     35 
     36   void IncrementUncleanShutdownCount();
     37   unsigned int GetAndResetUncleanShutdownCount();
     38 
     39  private:
     40   std::atomic_uint kernel_crashes_;
     41   std::atomic_uint unclean_shutdowns_;
     42   std::atomic_uint user_crashes_;
     43 };
     44 
     45 #endif  // METRICSD_UPLOADER_CRASH_COUNTERS_H_
     46