Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic macOS support #480

Merged
merged 135 commits into from
May 7, 2018
Merged

Basic macOS support #480

merged 135 commits into from
May 7, 2018

Conversation

npyl
Copy link
Collaborator

@npyl npyl commented Apr 15, 2018

Hi everyone,
This is my work for getting conky to run on macOS and load the entire default config.

Preview

conky running on my mac

At the moment everything that is needed for the default conky config to be shown, is supported. (There are other things working too: e.g. if_mounted, if_existing etc)

CHANGES

  • In ConkyPlatformChecks.cmake, Conky.cmake and src/CMakeLists.txt introduce support for Darwin
  • Introduce the files darwin.cc, darwin.h and darwin_sip.h
  • In ConkyPlatformChecks.cmake force cmake to search for statfs64 in sys/mount.h instead of sys/statfs.h as it doesn't exist in the latter.
  • In .gitignore add .DS_Store which are spotlight-generated files that offer directory-related attributes; unnecessary for conky development on macOS.
  • In luamm.cc I encountered the error: No member named '__cxa_exception_type' in ‘std::exception_ptr’ and couldn’t find a solution so I disabled the code for macOS
  • In semaphore.hh I had to introduce a variation of semaphore class because macOS does not support named-unix semaphores (although available) . Also, I didn't want to bloat the code with too much preprocessor-code
  • In core.cc enable the conky-variables running_processes, threads , running_threads for macOS
  • Introduce previous_total_cpu_time as member variable in
  • In top.h I introduced the member variable previous_total_cpu_time in an attempt to optimise to the finest get_top_info()and specifically for getting %CPU usage foreach process. I have implemented a slightly different approach than the one used in linux.cc:
    My approach is based on the concept that total-CPU-time-delta should be process-specific instead of iteration-specific as implemented in linux.cc.
    For the sake of keeping this PR compacked I will add a link to the issue in conky-for-macOS repo: link
  • Introduce a new conky-variable: sip_status. This variable is Only available for macOS and offers information about the security measure 'System Integrity Protection' or SIP
  • In core.cc introduce sip_status
  • In extras/vim/syntax/conkyrc.vim, extras/nano/conky.nanorc and doc/variables.xml add sip_status variable and provide documentation for it in the latter
  • Introduce HAVE_CLOCK_GETTIME cmakedefine to provide backwards compatibility with versions of macOS that don't provide clock_gettime()

TESTED WITH

  • Apple's Instruments - For finding memory leaks
  • Apple’s top - For memory stats
  • Activity Monitor - For CPU usage

MY QUESTIONS

  1. I noticed in almost all source-file's License headers a line saying the identation used. Though, for development I was using XCode and the identation is different in darwin.cc, darwin.h and darwin_sip.h. Is this a necessary requirement for merging?
  2. I have included code from apple’s top utility which is APSL-licensed in order to implement memory-stats. The problem is, that the algorithm apple uses, is the only CORRECT, and is fairly undocumented. AFAIK, there is no other way to calculate memory statistics than using apple-code. Does this cause a problem, keeping in mind that I am using small portions of their software and copying the only available way of finding memory stats?

I apologise for giving you a pull request 130-commits-long but lots of work had to be done to bring conky to a usable state first. :)

npyl added 30 commits August 27, 2017 19:01
…IN_C_FULL so remove -D_POSIX_C_SOURCE=200809L). What is more, -D_LARGEFILE64_SOURCE is used by default so not needed on macOS
…caused it to crash immediately upon initialisation
…n't cloned the repo and thus it showed 3166 commits behind
…nd not in 100% or 200% as it did before! Yeah
On macOS there can be used MANY swapfiles ( NOT swap partitions,,, the installation disk is the partition for storing swap memory data )
Thus conky code must be updated for Darwin to support multi-swapfile usage stats.

For now, we default to showing stats for swapfile0
…orage so removed the swapmode( int swapfd, unsigned long * retvail, unsigned long * retfree )
when sem initialisation fails just like in sem() for linux…

darwin.cc:  partially implemented update_cpu_usage() and
update_total_processes()
( Now it finds the correct number of tasks )

the changes in cmake file don’t change the functionality… It is only
comments.

In upcoming updates lua support may be enabled and the comments are
related to lua support.
…le ( we use hw.logicalcpumax instead of hw.ncpus ) --> The new implementation of get_cpu_count() finds the the max value of logical cores the mac could use on a boot.

update_total_processes() was patched to allow initialising only ONCE when conky runs the machHost and processorSet ( this could probably be implemented in a better way I guess though... )
compile ( This way we are compatible to GPLv3, i think )

Include GPLv3 header in darwin.cc, darwin.h and darwin_soundcard.h

Add more beautiful and explanatory comments to ease the work of other
contributors… ( Mostly on things that don’t work! )
…lementation but still it doesn't work as expected, plus, there are more memory related problems that will be fixed in newer release!

NOTE: It will be really good to see how functions are implemented on linux.cc for more complete implementation
…... ( only keeps mach stuff )

Needs some more work though to print accurate percentage! :)
npyl added 9 commits February 26, 2018 14:26
Revert to original conky readme
Move all macOS related information to the Wiki: https://github.com/Conky-for-macOS/conky-for-macOS/wiki
For now, I have only tested up / down bytes count on en0, and it works.

This is for #14
- Fix License headers in darwin* files
- Remove ConkyX entry from .gitignore which slipped into from the "forConkyX" branch which was used for another project ... ConkyX.
- Cleanup top.h  (I will request the changes in a pull request finally)
@brndnmtthws
Copy link
Owner

Wow, this is really cool. It's going to take some time to review this, but I'll get back to you on it.

@npyl
Copy link
Collaborator Author

npyl commented Apr 23, 2018

Thats awesome thanks. If you need to build this i have wriiten a simple guide here: link

Apart from installing the required libraries it is pretty much normal conky compilation!

@brndnmtthws
Copy link
Owner

@npyl can you address the build error?

At this point I think I'll just merge this, and go in and clean stuff up later. I'd rather get this merged and get a release out so we can find bugs.

I want to add some tools like clang-format into the build system so we can standardize on formatting and include some static analysis.

@npyl
Copy link
Collaborator Author

npyl commented Apr 26, 2018

@brndnmtthws Yep, i will check it out

EDIT: I also think I have messed up a bit the documentation of sip_status..
You may want to wait a bit for me to check it out before you merge!!!

@npyl
Copy link
Collaborator Author

npyl commented Apr 26, 2018

Hey btw, I should also tell you that I am really stressed with school right now, so after i finish it (approx 2 months) i will be able to dedicate alot time. Until then I am not sure how much i will be able to dedicate thanks for the understanding

@brndnmtthws
Copy link
Owner

@npyl not to worry. Conky has been around for more than 12 years, and I think it'll still be around in another 12 :)

Improve checks for headers in ConkyPlatformChecks.cmake to amend the problem;
I mistakenly thought that statfs64 wasn't available in sys/statfs.h in macOS thus I tried to add platform specific code.  Though, I add the checks in the wrong place and also messed up linux-specific code by replacing checks_include sys/statfs with check_symbol_exists statfs64
@npyl
Copy link
Collaborator Author

npyl commented May 5, 2018

Hi!! I found some time and solved the problem. Thank you for your patience! :)

I have also almost finished documenting of sip_status

UPDATE: Hmm... Ok the problem for linux is fixed, but there is a problem for the mac now, let me see it again!
UPDATE2: Seems it is ok now! (for both OS). I am only worried if the patches are in the right place and if i should move them to a different more proper location!

@brndnmtthws brndnmtthws merged commit b20d83b into brndnmtthws:master May 7, 2018
@brndnmtthws
Copy link
Owner

@npyl as a follow-up to this, could you take a stab at adding a macOS Travis CI build? That would be super valuable!

@npyl
Copy link
Collaborator Author

npyl commented May 11, 2018

@brndnmtthws Yeah! I will do it as soon as I can! thats cool!

@brndnmtthws
Copy link
Owner

@npyl also take a look at #486. I'm trying to get the build process into better shape.

npyl added a commit to Conky-for-macOS/conky-for-macOS that referenced this pull request Jul 2, 2018
This commit fixes documentation of a macOS specific variable (sip_status) as promised in brndnmtthws#480.

Also, fix some identation problems in darwin.cc
brndnmtthws pushed a commit that referenced this pull request Jul 4, 2018
This commit fixes documentation of a macOS specific variable (sip_status) as promised in #480.

Also, fix some identation problems in darwin.cc
brndnmtthws added a commit that referenced this pull request Jul 4, 2018
* Documentation fixes for macOS

This commit fixes documentation of a macOS specific variable (sip_status) as promised in #480.

Also, fix some identation problems in darwin.cc

* Amend #18 by polling less often! This will help lower CPU usage, too!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants